1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2013 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. */
23 #include "gdb_string.h"
29 #include "exceptions.h"
31 /*#include "terminal.h" */
34 #include "gdb-stabs.h"
35 #include "gdbthread.h"
37 #include "remote-notif.h"
40 #include "gdb_assert.h"
43 #include "cli/cli-decode.h"
44 #include "cli/cli-setshow.h"
45 #include "target-descriptions.h"
47 #include "filestuff.h"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
64 #include "xml-support.h"
66 #include "memory-map.h"
68 #include "tracepoint.h"
74 /* Temp hacks for tracepoint encoding migration. */
75 static char *target_buf
;
76 static long target_buf_size
;
78 /* The size to align memory write packets, when practical. The protocol
79 does not guarantee any alignment, and gdb will generate short
80 writes and unaligned writes, but even as a best-effort attempt this
81 can improve bulk transfers. For instance, if a write is misaligned
82 relative to the target's data bus, the stub may need to make an extra
83 round trip fetching data from the target. This doesn't make a
84 huge difference, but it's easy to do, so we try to be helpful.
86 The alignment chosen is arbitrary; usually data bus width is
87 important here, not the possibly larger cache line size. */
88 enum { REMOTE_ALIGN_WRITES
= 16 };
90 /* Prototypes for local functions. */
91 static void async_cleanup_sigint_signal_handler (void *dummy
);
92 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
93 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
94 int forever
, int *is_notif
);
96 static void async_handle_remote_sigint (int);
97 static void async_handle_remote_sigint_twice (int);
99 static void remote_files_info (struct target_ops
*ignore
);
101 static void remote_prepare_to_store (struct regcache
*regcache
);
103 static void remote_open (char *name
, int from_tty
);
105 static void extended_remote_open (char *name
, int from_tty
);
107 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
109 static void remote_close (void);
111 static void remote_mourn (struct target_ops
*ops
);
113 static void extended_remote_restart (void);
115 static void extended_remote_mourn (struct target_ops
*);
117 static void remote_mourn_1 (struct target_ops
*);
119 static void remote_send (char **buf
, long *sizeof_buf_p
);
121 static int readchar (int timeout
);
123 static void remote_serial_write (const char *str
, int len
);
125 static void remote_kill (struct target_ops
*ops
);
127 static int tohex (int nib
);
129 static int remote_can_async_p (void);
131 static int remote_is_async_p (void);
133 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
134 void *context
), void *context
);
136 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
138 static void sync_remote_interrupt_twice (int signo
);
140 static void interrupt_query (void);
142 static void set_general_thread (struct ptid ptid
);
143 static void set_continue_thread (struct ptid ptid
);
145 static void get_offsets (void);
147 static void skip_frame (void);
149 static long read_frame (char **buf_p
, long *sizeof_buf
);
151 static int hexnumlen (ULONGEST num
);
153 static void init_remote_ops (void);
155 static void init_extended_remote_ops (void);
157 static void remote_stop (ptid_t
);
159 static int ishex (int ch
, int *val
);
161 static int stubhex (int ch
);
163 static int hexnumstr (char *, ULONGEST
);
165 static int hexnumnstr (char *, ULONGEST
, int);
167 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
169 static void print_packet (char *);
171 static void compare_sections_command (char *, int);
173 static void packet_command (char *, int);
175 static int stub_unpack_int (char *buff
, int fieldlength
);
177 static ptid_t
remote_current_thread (ptid_t oldptid
);
179 static void remote_find_new_threads (void);
181 static int fromhex (int a
);
183 static int putpkt_binary (char *buf
, int cnt
);
185 static void check_binary_download (CORE_ADDR addr
);
187 struct packet_config
;
189 static void show_packet_config_cmd (struct packet_config
*config
);
191 static void update_packet_config (struct packet_config
*config
);
193 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
194 struct cmd_list_element
*c
);
196 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
198 struct cmd_list_element
*c
,
201 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
202 static ptid_t
read_ptid (char *buf
, char **obuf
);
204 static void remote_set_permissions (void);
207 static int remote_get_trace_status (struct trace_status
*ts
);
209 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
211 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
213 static void remote_query_supported (void);
215 static void remote_check_symbols (void);
217 void _initialize_remote (void);
220 static void stop_reply_xfree (struct stop_reply
*);
221 static void remote_parse_stop_reply (char *, struct stop_reply
*);
222 static void push_stop_reply (struct stop_reply
*);
223 static void discard_pending_stop_replies (struct inferior
*);
224 static int peek_stop_reply (ptid_t ptid
);
226 static void remote_async_inferior_event_handler (gdb_client_data
);
228 static void remote_terminal_ours (void);
230 static int remote_read_description_p (struct target_ops
*target
);
232 static void remote_console_output (char *msg
);
234 static int remote_supports_cond_breakpoints (void);
236 static int remote_can_run_breakpoint_commands (void);
240 static struct cmd_list_element
*remote_cmdlist
;
242 /* For "set remote" and "show remote". */
244 static struct cmd_list_element
*remote_set_cmdlist
;
245 static struct cmd_list_element
*remote_show_cmdlist
;
247 /* Stub vCont actions support.
249 Each field is a boolean flag indicating whether the stub reports
250 support for the corresponding action. */
252 struct vCont_action_support
261 /* Controls whether GDB is willing to use range stepping. */
263 static int use_range_stepping
= 1;
265 /* Description of the remote protocol state for the currently
266 connected target. This is per-target state, and independent of the
267 selected architecture. */
271 /* A buffer to use for incoming packets, and its current size. The
272 buffer is grown dynamically for larger incoming packets.
273 Outgoing packets may also be constructed in this buffer.
274 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
275 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
280 /* True if we're going through initial connection setup (finding out
281 about the remote side's threads, relocating symbols, etc.). */
284 /* If we negotiated packet size explicitly (and thus can bypass
285 heuristics for the largest packet size that will not overflow
286 a buffer in the stub), this will be set to that packet size.
287 Otherwise zero, meaning to use the guessed size. */
288 long explicit_packet_size
;
290 /* remote_wait is normally called when the target is running and
291 waits for a stop reply packet. But sometimes we need to call it
292 when the target is already stopped. We can send a "?" packet
293 and have remote_wait read the response. Or, if we already have
294 the response, we can stash it in BUF and tell remote_wait to
295 skip calling getpkt. This flag is set when BUF contains a
296 stop reply packet and the target is not waiting. */
297 int cached_wait_status
;
299 /* True, if in no ack mode. That is, neither GDB nor the stub will
300 expect acks from each other. The connection is assumed to be
304 /* True if we're connected in extended remote mode. */
307 /* True if the stub reported support for multi-process
309 int multi_process_aware
;
311 /* True if we resumed the target and we're waiting for the target to
312 stop. In the mean time, we can't start another command/query.
313 The remote server wouldn't be ready to process it, so we'd
314 timeout waiting for a reply that would never come and eventually
315 we'd close the connection. This can happen in asynchronous mode
316 because we allow GDB commands while the target is running. */
317 int waiting_for_stop_reply
;
319 /* True if the stub reports support for non-stop mode. */
322 /* The status of the stub support for the various vCont actions. */
323 struct vCont_action_support supports_vCont
;
325 /* True if the stub reports support for conditional tracepoints. */
326 int cond_tracepoints
;
328 /* True if the stub reports support for target-side breakpoint
330 int cond_breakpoints
;
332 /* True if the stub reports support for target-side breakpoint
334 int breakpoint_commands
;
336 /* True if the stub reports support for fast tracepoints. */
337 int fast_tracepoints
;
339 /* True if the stub reports support for static tracepoints. */
340 int static_tracepoints
;
342 /* True if the stub reports support for installing tracepoint while
344 int install_in_trace
;
346 /* True if the stub can continue running a trace while GDB is
348 int disconnected_tracing
;
350 /* True if the stub reports support for enabling and disabling
351 tracepoints while a trace experiment is running. */
352 int enable_disable_tracepoints
;
354 /* True if the stub can collect strings using tracenz bytecode. */
357 /* True if the stub supports qXfer:libraries-svr4:read with a
359 int augmented_libraries_svr4_read
;
361 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
362 responded to that. */
365 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
366 remote_open knows that we don't have a file open when the program
368 struct serial
*remote_desc
;
370 /* These are the threads which we last sent to the remote system. The
371 TID member will be -1 for all or -2 for not sent yet. */
372 ptid_t general_thread
;
373 ptid_t continue_thread
;
375 /* This is the traceframe which we last selected on the remote system.
376 It will be -1 if no traceframe is selected. */
377 int remote_traceframe_number
;
379 char *last_pass_packet
;
381 /* The last QProgramSignals packet sent to the target. We bypass
382 sending a new program signals list down to the target if the new
383 packet is exactly the same as the last we sent. IOW, we only let
384 the target know about program signals list changes. */
385 char *last_program_signals_packet
;
388 /* Private data that we'll store in (struct thread_info)->private. */
389 struct private_thread_info
396 free_private_thread_info (struct private_thread_info
*info
)
402 /* Returns true if the multi-process extensions are in effect. */
404 remote_multi_process_p (struct remote_state
*rs
)
406 return rs
->multi_process_aware
;
409 /* This data could be associated with a target, but we do not always
410 have access to the current target when we need it, so for now it is
411 static. This will be fine for as long as only one target is in use
413 static struct remote_state
*remote_state
;
415 static struct remote_state
*
416 get_remote_state_raw (void)
421 /* Allocate a new struct remote_state with xmalloc, initialize it, and
424 static struct remote_state
*
425 new_remote_state (void)
427 struct remote_state
*result
= XCNEW (struct remote_state
);
429 /* The default buffer size is unimportant; it will be expanded
430 whenever a larger buffer is needed. */
431 result
->buf_size
= 400;
432 result
->buf
= xmalloc (result
->buf_size
);
433 result
->remote_traceframe_number
= -1;
438 /* Description of the remote protocol for a given architecture. */
442 long offset
; /* Offset into G packet. */
443 long regnum
; /* GDB's internal register number. */
444 LONGEST pnum
; /* Remote protocol register number. */
445 int in_g_packet
; /* Always part of G packet. */
446 /* long size in bytes; == register_size (target_gdbarch (), regnum);
448 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
452 struct remote_arch_state
454 /* Description of the remote protocol registers. */
455 long sizeof_g_packet
;
457 /* Description of the remote protocol registers indexed by REGNUM
458 (making an array gdbarch_num_regs in size). */
459 struct packet_reg
*regs
;
461 /* This is the size (in chars) of the first response to the ``g''
462 packet. It is used as a heuristic when determining the maximum
463 size of memory-read and memory-write packets. A target will
464 typically only reserve a buffer large enough to hold the ``g''
465 packet. The size does not include packet overhead (headers and
467 long actual_register_packet_size
;
469 /* This is the maximum size (in chars) of a non read/write packet.
470 It is also used as a cap on the size of read/write packets. */
471 long remote_packet_size
;
474 long sizeof_pkt
= 2000;
476 /* Utility: generate error from an incoming stub packet. */
478 trace_error (char *buf
)
481 return; /* not an error msg */
484 case '1': /* malformed packet error */
485 if (*++buf
== '0') /* general case: */
486 error (_("remote.c: error in outgoing packet."));
488 error (_("remote.c: error in outgoing packet at field #%ld."),
489 strtol (buf
, NULL
, 16));
491 error (_("Target returns error code '%s'."), buf
);
495 /* Utility: wait for reply from stub, while accepting "O" packets. */
497 remote_get_noisy_reply (char **buf_p
,
500 do /* Loop on reply from remote stub. */
504 QUIT
; /* Allow user to bail out with ^C. */
505 getpkt (buf_p
, sizeof_buf
, 0);
509 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
512 CORE_ADDR from
, to
, org_to
;
514 int adjusted_size
= 0;
515 volatile struct gdb_exception ex
;
517 p
= buf
+ strlen ("qRelocInsn:");
518 pp
= unpack_varlen_hex (p
, &ul
);
520 error (_("invalid qRelocInsn packet: %s"), buf
);
524 unpack_varlen_hex (p
, &ul
);
529 TRY_CATCH (ex
, RETURN_MASK_ALL
)
531 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
535 adjusted_size
= to
- org_to
;
537 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
540 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
542 /* Propagate memory errors silently back to the target.
543 The stub may have limited the range of addresses we
544 can write to, for example. */
549 /* Something unexpectedly bad happened. Be verbose so
550 we can tell what, and propagate the error back to the
551 stub, so it doesn't get stuck waiting for a
553 exception_fprintf (gdb_stderr
, ex
,
554 _("warning: relocating instruction: "));
558 else if (buf
[0] == 'O' && buf
[1] != 'K')
559 remote_console_output (buf
+ 1); /* 'O' message from stub */
561 return buf
; /* Here's the actual reply. */
566 /* Handle for retreving the remote protocol data from gdbarch. */
567 static struct gdbarch_data
*remote_gdbarch_data_handle
;
569 static struct remote_arch_state
*
570 get_remote_arch_state (void)
572 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
575 /* Fetch the global remote target state. */
577 static struct remote_state
*
578 get_remote_state (void)
580 /* Make sure that the remote architecture state has been
581 initialized, because doing so might reallocate rs->buf. Any
582 function which calls getpkt also needs to be mindful of changes
583 to rs->buf, but this call limits the number of places which run
585 get_remote_arch_state ();
587 return get_remote_state_raw ();
591 compare_pnums (const void *lhs_
, const void *rhs_
)
593 const struct packet_reg
* const *lhs
= lhs_
;
594 const struct packet_reg
* const *rhs
= rhs_
;
596 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
598 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
605 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
607 int regnum
, num_remote_regs
, offset
;
608 struct packet_reg
**remote_regs
;
610 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
612 struct packet_reg
*r
= ®s
[regnum
];
614 if (register_size (gdbarch
, regnum
) == 0)
615 /* Do not try to fetch zero-sized (placeholder) registers. */
618 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
623 /* Define the g/G packet format as the contents of each register
624 with a remote protocol number, in order of ascending protocol
627 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
628 * sizeof (struct packet_reg
*));
629 for (num_remote_regs
= 0, regnum
= 0;
630 regnum
< gdbarch_num_regs (gdbarch
);
632 if (regs
[regnum
].pnum
!= -1)
633 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
635 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
638 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
640 remote_regs
[regnum
]->in_g_packet
= 1;
641 remote_regs
[regnum
]->offset
= offset
;
642 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
648 /* Given the architecture described by GDBARCH, return the remote
649 protocol register's number and the register's offset in the g/G
650 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
651 If the target does not have a mapping for REGNUM, return false,
652 otherwise, return true. */
655 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
656 int *pnum
, int *poffset
)
659 struct packet_reg
*regs
;
660 struct cleanup
*old_chain
;
662 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
664 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
665 old_chain
= make_cleanup (xfree
, regs
);
667 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
669 *pnum
= regs
[regnum
].pnum
;
670 *poffset
= regs
[regnum
].offset
;
672 do_cleanups (old_chain
);
678 init_remote_state (struct gdbarch
*gdbarch
)
680 struct remote_state
*rs
= get_remote_state_raw ();
681 struct remote_arch_state
*rsa
;
683 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
685 /* Use the architecture to build a regnum<->pnum table, which will be
686 1:1 unless a feature set specifies otherwise. */
687 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
688 gdbarch_num_regs (gdbarch
),
691 /* Record the maximum possible size of the g packet - it may turn out
693 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
695 /* Default maximum number of characters in a packet body. Many
696 remote stubs have a hardwired buffer size of 400 bytes
697 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
698 as the maximum packet-size to ensure that the packet and an extra
699 NUL character can always fit in the buffer. This stops GDB
700 trashing stubs that try to squeeze an extra NUL into what is
701 already a full buffer (As of 1999-12-04 that was most stubs). */
702 rsa
->remote_packet_size
= 400 - 1;
704 /* This one is filled in when a ``g'' packet is received. */
705 rsa
->actual_register_packet_size
= 0;
707 /* Should rsa->sizeof_g_packet needs more space than the
708 default, adjust the size accordingly. Remember that each byte is
709 encoded as two characters. 32 is the overhead for the packet
710 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
711 (``$NN:G...#NN'') is a better guess, the below has been padded a
713 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
714 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
716 /* Make sure that the packet buffer is plenty big enough for
717 this architecture. */
718 if (rs
->buf_size
< rsa
->remote_packet_size
)
720 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
721 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
727 /* Return the current allowed size of a remote packet. This is
728 inferred from the current architecture, and should be used to
729 limit the length of outgoing packets. */
731 get_remote_packet_size (void)
733 struct remote_state
*rs
= get_remote_state ();
734 struct remote_arch_state
*rsa
= get_remote_arch_state ();
736 if (rs
->explicit_packet_size
)
737 return rs
->explicit_packet_size
;
739 return rsa
->remote_packet_size
;
742 static struct packet_reg
*
743 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
745 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
749 struct packet_reg
*r
= &rsa
->regs
[regnum
];
751 gdb_assert (r
->regnum
== regnum
);
756 static struct packet_reg
*
757 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
761 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
763 struct packet_reg
*r
= &rsa
->regs
[i
];
771 /* FIXME: graces/2002-08-08: These variables should eventually be
772 bound to an instance of the target object (as in gdbarch-tdep()),
773 when such a thing exists. */
775 /* This is set to the data address of the access causing the target
776 to stop for a watchpoint. */
777 static CORE_ADDR remote_watch_data_address
;
779 /* This is non-zero if target stopped for a watchpoint. */
780 static int remote_stopped_by_watchpoint_p
;
782 static struct target_ops remote_ops
;
784 static struct target_ops extended_remote_ops
;
786 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
787 ``forever'' still use the normal timeout mechanism. This is
788 currently used by the ASYNC code to guarentee that target reads
789 during the initial connect always time-out. Once getpkt has been
790 modified to return a timeout indication and, in turn
791 remote_wait()/wait_for_inferior() have gained a timeout parameter
793 static int wait_forever_enabled_p
= 1;
795 /* Allow the user to specify what sequence to send to the remote
796 when he requests a program interruption: Although ^C is usually
797 what remote systems expect (this is the default, here), it is
798 sometimes preferable to send a break. On other systems such
799 as the Linux kernel, a break followed by g, which is Magic SysRq g
800 is required in order to interrupt the execution. */
801 const char interrupt_sequence_control_c
[] = "Ctrl-C";
802 const char interrupt_sequence_break
[] = "BREAK";
803 const char interrupt_sequence_break_g
[] = "BREAK-g";
804 static const char *const interrupt_sequence_modes
[] =
806 interrupt_sequence_control_c
,
807 interrupt_sequence_break
,
808 interrupt_sequence_break_g
,
811 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
814 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
815 struct cmd_list_element
*c
,
818 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
819 fprintf_filtered (file
,
820 _("Send the ASCII ETX character (Ctrl-c) "
821 "to the remote target to interrupt the "
822 "execution of the program.\n"));
823 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
824 fprintf_filtered (file
,
825 _("send a break signal to the remote target "
826 "to interrupt the execution of the program.\n"));
827 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
828 fprintf_filtered (file
,
829 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
830 "the remote target to interrupt the execution "
831 "of Linux kernel.\n"));
833 internal_error (__FILE__
, __LINE__
,
834 _("Invalid value for interrupt_sequence_mode: %s."),
835 interrupt_sequence_mode
);
838 /* This boolean variable specifies whether interrupt_sequence is sent
839 to the remote target when gdb connects to it.
840 This is mostly needed when you debug the Linux kernel: The Linux kernel
841 expects BREAK g which is Magic SysRq g for connecting gdb. */
842 static int interrupt_on_connect
= 0;
844 /* This variable is used to implement the "set/show remotebreak" commands.
845 Since these commands are now deprecated in favor of "set/show remote
846 interrupt-sequence", it no longer has any effect on the code. */
847 static int remote_break
;
850 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
853 interrupt_sequence_mode
= interrupt_sequence_break
;
855 interrupt_sequence_mode
= interrupt_sequence_control_c
;
859 show_remotebreak (struct ui_file
*file
, int from_tty
,
860 struct cmd_list_element
*c
,
865 /* This variable sets the number of bits in an address that are to be
866 sent in a memory ("M" or "m") packet. Normally, after stripping
867 leading zeros, the entire address would be sent. This variable
868 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
869 initial implementation of remote.c restricted the address sent in
870 memory packets to ``host::sizeof long'' bytes - (typically 32
871 bits). Consequently, for 64 bit targets, the upper 32 bits of an
872 address was never sent. Since fixing this bug may cause a break in
873 some remote targets this variable is principly provided to
874 facilitate backward compatibility. */
876 static unsigned int remote_address_size
;
878 /* Temporary to track who currently owns the terminal. See
879 remote_terminal_* for more details. */
881 static int remote_async_terminal_ours_p
;
883 /* The executable file to use for "run" on the remote side. */
885 static char *remote_exec_file
= "";
888 /* User configurable variables for the number of characters in a
889 memory read/write packet. MIN (rsa->remote_packet_size,
890 rsa->sizeof_g_packet) is the default. Some targets need smaller
891 values (fifo overruns, et.al.) and some users need larger values
892 (speed up transfers). The variables ``preferred_*'' (the user
893 request), ``current_*'' (what was actually set) and ``forced_*''
894 (Positive - a soft limit, negative - a hard limit). */
896 struct memory_packet_config
903 /* Compute the current size of a read/write packet. Since this makes
904 use of ``actual_register_packet_size'' the computation is dynamic. */
907 get_memory_packet_size (struct memory_packet_config
*config
)
909 struct remote_state
*rs
= get_remote_state ();
910 struct remote_arch_state
*rsa
= get_remote_arch_state ();
912 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
913 law?) that some hosts don't cope very well with large alloca()
914 calls. Eventually the alloca() code will be replaced by calls to
915 xmalloc() and make_cleanups() allowing this restriction to either
916 be lifted or removed. */
917 #ifndef MAX_REMOTE_PACKET_SIZE
918 #define MAX_REMOTE_PACKET_SIZE 16384
920 /* NOTE: 20 ensures we can write at least one byte. */
921 #ifndef MIN_REMOTE_PACKET_SIZE
922 #define MIN_REMOTE_PACKET_SIZE 20
927 if (config
->size
<= 0)
928 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
930 what_they_get
= config
->size
;
934 what_they_get
= get_remote_packet_size ();
935 /* Limit the packet to the size specified by the user. */
937 && what_they_get
> config
->size
)
938 what_they_get
= config
->size
;
940 /* Limit it to the size of the targets ``g'' response unless we have
941 permission from the stub to use a larger packet size. */
942 if (rs
->explicit_packet_size
== 0
943 && rsa
->actual_register_packet_size
> 0
944 && what_they_get
> rsa
->actual_register_packet_size
)
945 what_they_get
= rsa
->actual_register_packet_size
;
947 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
948 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
949 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
950 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
952 /* Make sure there is room in the global buffer for this packet
953 (including its trailing NUL byte). */
954 if (rs
->buf_size
< what_they_get
+ 1)
956 rs
->buf_size
= 2 * what_they_get
;
957 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
960 return what_they_get
;
963 /* Update the size of a read/write packet. If they user wants
964 something really big then do a sanity check. */
967 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
969 int fixed_p
= config
->fixed_p
;
970 long size
= config
->size
;
973 error (_("Argument required (integer, `fixed' or `limited')."));
974 else if (strcmp (args
, "hard") == 0
975 || strcmp (args
, "fixed") == 0)
977 else if (strcmp (args
, "soft") == 0
978 || strcmp (args
, "limit") == 0)
984 size
= strtoul (args
, &end
, 0);
986 error (_("Invalid %s (bad syntax)."), config
->name
);
988 /* Instead of explicitly capping the size of a packet to
989 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
990 instead allowed to set the size to something arbitrarily
992 if (size
> MAX_REMOTE_PACKET_SIZE
)
993 error (_("Invalid %s (too large)."), config
->name
);
997 if (fixed_p
&& !config
->fixed_p
)
999 if (! query (_("The target may not be able to correctly handle a %s\n"
1000 "of %ld bytes. Change the packet size? "),
1001 config
->name
, size
))
1002 error (_("Packet size not changed."));
1004 /* Update the config. */
1005 config
->fixed_p
= fixed_p
;
1006 config
->size
= size
;
1010 show_memory_packet_size (struct memory_packet_config
*config
)
1012 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1013 if (config
->fixed_p
)
1014 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1015 get_memory_packet_size (config
));
1017 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1018 get_memory_packet_size (config
));
1021 static struct memory_packet_config memory_write_packet_config
=
1023 "memory-write-packet-size",
1027 set_memory_write_packet_size (char *args
, int from_tty
)
1029 set_memory_packet_size (args
, &memory_write_packet_config
);
1033 show_memory_write_packet_size (char *args
, int from_tty
)
1035 show_memory_packet_size (&memory_write_packet_config
);
1039 get_memory_write_packet_size (void)
1041 return get_memory_packet_size (&memory_write_packet_config
);
1044 static struct memory_packet_config memory_read_packet_config
=
1046 "memory-read-packet-size",
1050 set_memory_read_packet_size (char *args
, int from_tty
)
1052 set_memory_packet_size (args
, &memory_read_packet_config
);
1056 show_memory_read_packet_size (char *args
, int from_tty
)
1058 show_memory_packet_size (&memory_read_packet_config
);
1062 get_memory_read_packet_size (void)
1064 long size
= get_memory_packet_size (&memory_read_packet_config
);
1066 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1067 extra buffer size argument before the memory read size can be
1068 increased beyond this. */
1069 if (size
> get_remote_packet_size ())
1070 size
= get_remote_packet_size ();
1075 /* Generic configuration support for packets the stub optionally
1076 supports. Allows the user to specify the use of the packet as well
1077 as allowing GDB to auto-detect support in the remote stub. */
1081 PACKET_SUPPORT_UNKNOWN
= 0,
1086 struct packet_config
1090 enum auto_boolean detect
;
1091 enum packet_support support
;
1094 /* Analyze a packet's return value and update the packet config
1105 update_packet_config (struct packet_config
*config
)
1107 switch (config
->detect
)
1109 case AUTO_BOOLEAN_TRUE
:
1110 config
->support
= PACKET_ENABLE
;
1112 case AUTO_BOOLEAN_FALSE
:
1113 config
->support
= PACKET_DISABLE
;
1115 case AUTO_BOOLEAN_AUTO
:
1116 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1122 show_packet_config_cmd (struct packet_config
*config
)
1124 char *support
= "internal-error";
1126 switch (config
->support
)
1129 support
= "enabled";
1131 case PACKET_DISABLE
:
1132 support
= "disabled";
1134 case PACKET_SUPPORT_UNKNOWN
:
1135 support
= "unknown";
1138 switch (config
->detect
)
1140 case AUTO_BOOLEAN_AUTO
:
1141 printf_filtered (_("Support for the `%s' packet "
1142 "is auto-detected, currently %s.\n"),
1143 config
->name
, support
);
1145 case AUTO_BOOLEAN_TRUE
:
1146 case AUTO_BOOLEAN_FALSE
:
1147 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1148 config
->name
, support
);
1154 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1155 const char *title
, int legacy
)
1161 config
->name
= name
;
1162 config
->title
= title
;
1163 config
->detect
= AUTO_BOOLEAN_AUTO
;
1164 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1165 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1167 show_doc
= xstrprintf ("Show current use of remote "
1168 "protocol `%s' (%s) packet",
1170 /* set/show TITLE-packet {auto,on,off} */
1171 cmd_name
= xstrprintf ("%s-packet", title
);
1172 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1173 &config
->detect
, set_doc
,
1174 show_doc
, NULL
, /* help_doc */
1175 set_remote_protocol_packet_cmd
,
1176 show_remote_protocol_packet_cmd
,
1177 &remote_set_cmdlist
, &remote_show_cmdlist
);
1178 /* The command code copies the documentation strings. */
1181 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1186 legacy_name
= xstrprintf ("%s-packet", name
);
1187 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1188 &remote_set_cmdlist
);
1189 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1190 &remote_show_cmdlist
);
1194 static enum packet_result
1195 packet_check_result (const char *buf
)
1199 /* The stub recognized the packet request. Check that the
1200 operation succeeded. */
1202 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1204 /* "Enn" - definitly an error. */
1205 return PACKET_ERROR
;
1207 /* Always treat "E." as an error. This will be used for
1208 more verbose error messages, such as E.memtypes. */
1209 if (buf
[0] == 'E' && buf
[1] == '.')
1210 return PACKET_ERROR
;
1212 /* The packet may or may not be OK. Just assume it is. */
1216 /* The stub does not support the packet. */
1217 return PACKET_UNKNOWN
;
1220 static enum packet_result
1221 packet_ok (const char *buf
, struct packet_config
*config
)
1223 enum packet_result result
;
1225 result
= packet_check_result (buf
);
1230 /* The stub recognized the packet request. */
1231 switch (config
->support
)
1233 case PACKET_SUPPORT_UNKNOWN
:
1235 fprintf_unfiltered (gdb_stdlog
,
1236 "Packet %s (%s) is supported\n",
1237 config
->name
, config
->title
);
1238 config
->support
= PACKET_ENABLE
;
1240 case PACKET_DISABLE
:
1241 internal_error (__FILE__
, __LINE__
,
1242 _("packet_ok: attempt to use a disabled packet"));
1248 case PACKET_UNKNOWN
:
1249 /* The stub does not support the packet. */
1250 switch (config
->support
)
1253 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1254 /* If the stub previously indicated that the packet was
1255 supported then there is a protocol error.. */
1256 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1257 config
->name
, config
->title
);
1259 /* The user set it wrong. */
1260 error (_("Enabled packet %s (%s) not recognized by stub"),
1261 config
->name
, config
->title
);
1263 case PACKET_SUPPORT_UNKNOWN
:
1265 fprintf_unfiltered (gdb_stdlog
,
1266 "Packet %s (%s) is NOT supported\n",
1267 config
->name
, config
->title
);
1268 config
->support
= PACKET_DISABLE
;
1270 case PACKET_DISABLE
:
1292 PACKET_vFile_pwrite
,
1294 PACKET_vFile_unlink
,
1295 PACKET_vFile_readlink
,
1297 PACKET_qXfer_features
,
1298 PACKET_qXfer_libraries
,
1299 PACKET_qXfer_libraries_svr4
,
1300 PACKET_qXfer_memory_map
,
1301 PACKET_qXfer_spu_read
,
1302 PACKET_qXfer_spu_write
,
1303 PACKET_qXfer_osdata
,
1304 PACKET_qXfer_threads
,
1305 PACKET_qXfer_statictrace_read
,
1306 PACKET_qXfer_traceframe_info
,
1312 PACKET_QPassSignals
,
1313 PACKET_QProgramSignals
,
1314 PACKET_qSearch_memory
,
1317 PACKET_QStartNoAckMode
,
1319 PACKET_qXfer_siginfo_read
,
1320 PACKET_qXfer_siginfo_write
,
1322 PACKET_ConditionalTracepoints
,
1323 PACKET_ConditionalBreakpoints
,
1324 PACKET_BreakpointCommands
,
1325 PACKET_FastTracepoints
,
1326 PACKET_StaticTracepoints
,
1327 PACKET_InstallInTrace
,
1330 PACKET_TracepointSource
,
1333 PACKET_QDisableRandomization
,
1335 PACKET_QTBuffer_size
,
1338 PACKET_qXfer_btrace
,
1342 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1345 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1346 struct cmd_list_element
*c
)
1348 struct packet_config
*packet
;
1350 for (packet
= remote_protocol_packets
;
1351 packet
< &remote_protocol_packets
[PACKET_MAX
];
1354 if (&packet
->detect
== c
->var
)
1356 update_packet_config (packet
);
1360 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1365 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1366 struct cmd_list_element
*c
,
1369 struct packet_config
*packet
;
1371 for (packet
= remote_protocol_packets
;
1372 packet
< &remote_protocol_packets
[PACKET_MAX
];
1375 if (&packet
->detect
== c
->var
)
1377 show_packet_config_cmd (packet
);
1381 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1385 /* Should we try one of the 'Z' requests? */
1389 Z_PACKET_SOFTWARE_BP
,
1390 Z_PACKET_HARDWARE_BP
,
1397 /* For compatibility with older distributions. Provide a ``set remote
1398 Z-packet ...'' command that updates all the Z packet types. */
1400 static enum auto_boolean remote_Z_packet_detect
;
1403 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1404 struct cmd_list_element
*c
)
1408 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1410 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1411 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1416 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1417 struct cmd_list_element
*c
,
1422 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1424 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1428 /* Should we try the 'ThreadInfo' query packet?
1430 This variable (NOT available to the user: auto-detect only!)
1431 determines whether GDB will use the new, simpler "ThreadInfo"
1432 query or the older, more complex syntax for thread queries.
1433 This is an auto-detect variable (set to true at each connect,
1434 and set to false when the target fails to recognize it). */
1436 static int use_threadinfo_query
;
1437 static int use_threadextra_query
;
1439 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1440 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1441 static struct async_signal_handler
*async_sigint_remote_token
;
1444 /* Asynchronous signal handle registered as event loop source for
1445 when we have pending events ready to be passed to the core. */
1447 static struct async_event_handler
*remote_async_inferior_event_token
;
1451 static ptid_t magic_null_ptid
;
1452 static ptid_t not_sent_ptid
;
1453 static ptid_t any_thread_ptid
;
1455 /* Find out if the stub attached to PID (and hence GDB should offer to
1456 detach instead of killing it when bailing out). */
1459 remote_query_attached (int pid
)
1461 struct remote_state
*rs
= get_remote_state ();
1462 size_t size
= get_remote_packet_size ();
1464 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1467 if (remote_multi_process_p (rs
))
1468 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1470 xsnprintf (rs
->buf
, size
, "qAttached");
1473 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1475 switch (packet_ok (rs
->buf
,
1476 &remote_protocol_packets
[PACKET_qAttached
]))
1479 if (strcmp (rs
->buf
, "1") == 0)
1483 warning (_("Remote failure reply: %s"), rs
->buf
);
1485 case PACKET_UNKNOWN
:
1492 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1493 has been invented by GDB, instead of reported by the target. Since
1494 we can be connected to a remote system before before knowing about
1495 any inferior, mark the target with execution when we find the first
1496 inferior. If ATTACHED is 1, then we had just attached to this
1497 inferior. If it is 0, then we just created this inferior. If it
1498 is -1, then try querying the remote stub to find out if it had
1499 attached to the inferior or not. */
1501 static struct inferior
*
1502 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1504 struct inferior
*inf
;
1506 /* Check whether this process we're learning about is to be
1507 considered attached, or if is to be considered to have been
1508 spawned by the stub. */
1510 attached
= remote_query_attached (pid
);
1512 if (gdbarch_has_global_solist (target_gdbarch ()))
1514 /* If the target shares code across all inferiors, then every
1515 attach adds a new inferior. */
1516 inf
= add_inferior (pid
);
1518 /* ... and every inferior is bound to the same program space.
1519 However, each inferior may still have its own address
1521 inf
->aspace
= maybe_new_address_space ();
1522 inf
->pspace
= current_program_space
;
1526 /* In the traditional debugging scenario, there's a 1-1 match
1527 between program/address spaces. We simply bind the inferior
1528 to the program space's address space. */
1529 inf
= current_inferior ();
1530 inferior_appeared (inf
, pid
);
1533 inf
->attach_flag
= attached
;
1534 inf
->fake_pid_p
= fake_pid_p
;
1539 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1540 according to RUNNING. */
1543 remote_add_thread (ptid_t ptid
, int running
)
1547 set_executing (ptid
, running
);
1548 set_running (ptid
, running
);
1551 /* Come here when we learn about a thread id from the remote target.
1552 It may be the first time we hear about such thread, so take the
1553 opportunity to add it to GDB's thread list. In case this is the
1554 first time we're noticing its corresponding inferior, add it to
1555 GDB's inferior list as well. */
1558 remote_notice_new_inferior (ptid_t currthread
, int running
)
1560 /* If this is a new thread, add it to GDB's thread list.
1561 If we leave it up to WFI to do this, bad things will happen. */
1563 if (in_thread_list (currthread
) && is_exited (currthread
))
1565 /* We're seeing an event on a thread id we knew had exited.
1566 This has to be a new thread reusing the old id. Add it. */
1567 remote_add_thread (currthread
, running
);
1571 if (!in_thread_list (currthread
))
1573 struct inferior
*inf
= NULL
;
1574 int pid
= ptid_get_pid (currthread
);
1576 if (ptid_is_pid (inferior_ptid
)
1577 && pid
== ptid_get_pid (inferior_ptid
))
1579 /* inferior_ptid has no thread member yet. This can happen
1580 with the vAttach -> remote_wait,"TAAthread:" path if the
1581 stub doesn't support qC. This is the first stop reported
1582 after an attach, so this is the main thread. Update the
1583 ptid in the thread list. */
1584 if (in_thread_list (pid_to_ptid (pid
)))
1585 thread_change_ptid (inferior_ptid
, currthread
);
1588 remote_add_thread (currthread
, running
);
1589 inferior_ptid
= currthread
;
1594 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1596 /* inferior_ptid is not set yet. This can happen with the
1597 vRun -> remote_wait,"TAAthread:" path if the stub
1598 doesn't support qC. This is the first stop reported
1599 after an attach, so this is the main thread. Update the
1600 ptid in the thread list. */
1601 thread_change_ptid (inferior_ptid
, currthread
);
1605 /* When connecting to a target remote, or to a target
1606 extended-remote which already was debugging an inferior, we
1607 may not know about it yet. Add it before adding its child
1608 thread, so notifications are emitted in a sensible order. */
1609 if (!in_inferior_list (ptid_get_pid (currthread
)))
1611 struct remote_state
*rs
= get_remote_state ();
1612 int fake_pid_p
= !remote_multi_process_p (rs
);
1614 inf
= remote_add_inferior (fake_pid_p
,
1615 ptid_get_pid (currthread
), -1);
1618 /* This is really a new thread. Add it. */
1619 remote_add_thread (currthread
, running
);
1621 /* If we found a new inferior, let the common code do whatever
1622 it needs to with it (e.g., read shared libraries, insert
1625 notice_new_inferior (currthread
, running
, 0);
1629 /* Return the private thread data, creating it if necessary. */
1631 static struct private_thread_info
*
1632 demand_private_info (ptid_t ptid
)
1634 struct thread_info
*info
= find_thread_ptid (ptid
);
1640 info
->private = xmalloc (sizeof (*(info
->private)));
1641 info
->private_dtor
= free_private_thread_info
;
1642 info
->private->core
= -1;
1643 info
->private->extra
= 0;
1646 return info
->private;
1649 /* Call this function as a result of
1650 1) A halt indication (T packet) containing a thread id
1651 2) A direct query of currthread
1652 3) Successful execution of set thread */
1655 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1657 rs
->general_thread
= currthread
;
1660 /* If 'QPassSignals' is supported, tell the remote stub what signals
1661 it can simply pass through to the inferior without reporting. */
1664 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1666 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1668 char *pass_packet
, *p
;
1670 struct remote_state
*rs
= get_remote_state ();
1672 gdb_assert (numsigs
< 256);
1673 for (i
= 0; i
< numsigs
; i
++)
1675 if (pass_signals
[i
])
1678 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1679 strcpy (pass_packet
, "QPassSignals:");
1680 p
= pass_packet
+ strlen (pass_packet
);
1681 for (i
= 0; i
< numsigs
; i
++)
1683 if (pass_signals
[i
])
1686 *p
++ = tohex (i
>> 4);
1687 *p
++ = tohex (i
& 15);
1696 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1698 char *buf
= rs
->buf
;
1700 putpkt (pass_packet
);
1701 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1702 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1703 if (rs
->last_pass_packet
)
1704 xfree (rs
->last_pass_packet
);
1705 rs
->last_pass_packet
= pass_packet
;
1708 xfree (pass_packet
);
1712 /* If 'QProgramSignals' is supported, tell the remote stub what
1713 signals it should pass through to the inferior when detaching. */
1716 remote_program_signals (int numsigs
, unsigned char *signals
)
1718 if (remote_protocol_packets
[PACKET_QProgramSignals
].support
!= PACKET_DISABLE
)
1722 struct remote_state
*rs
= get_remote_state ();
1724 gdb_assert (numsigs
< 256);
1725 for (i
= 0; i
< numsigs
; i
++)
1730 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1731 strcpy (packet
, "QProgramSignals:");
1732 p
= packet
+ strlen (packet
);
1733 for (i
= 0; i
< numsigs
; i
++)
1735 if (signal_pass_state (i
))
1738 *p
++ = tohex (i
>> 4);
1739 *p
++ = tohex (i
& 15);
1748 if (!rs
->last_program_signals_packet
1749 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1751 char *buf
= rs
->buf
;
1754 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1755 packet_ok (buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1756 xfree (rs
->last_program_signals_packet
);
1757 rs
->last_program_signals_packet
= packet
;
1764 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1765 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1766 thread. If GEN is set, set the general thread, if not, then set
1767 the step/continue thread. */
1769 set_thread (struct ptid ptid
, int gen
)
1771 struct remote_state
*rs
= get_remote_state ();
1772 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1773 char *buf
= rs
->buf
;
1774 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1776 if (ptid_equal (state
, ptid
))
1780 *buf
++ = gen
? 'g' : 'c';
1781 if (ptid_equal (ptid
, magic_null_ptid
))
1782 xsnprintf (buf
, endbuf
- buf
, "0");
1783 else if (ptid_equal (ptid
, any_thread_ptid
))
1784 xsnprintf (buf
, endbuf
- buf
, "0");
1785 else if (ptid_equal (ptid
, minus_one_ptid
))
1786 xsnprintf (buf
, endbuf
- buf
, "-1");
1788 write_ptid (buf
, endbuf
, ptid
);
1790 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1792 rs
->general_thread
= ptid
;
1794 rs
->continue_thread
= ptid
;
1798 set_general_thread (struct ptid ptid
)
1800 set_thread (ptid
, 1);
1804 set_continue_thread (struct ptid ptid
)
1806 set_thread (ptid
, 0);
1809 /* Change the remote current process. Which thread within the process
1810 ends up selected isn't important, as long as it is the same process
1811 as what INFERIOR_PTID points to.
1813 This comes from that fact that there is no explicit notion of
1814 "selected process" in the protocol. The selected process for
1815 general operations is the process the selected general thread
1819 set_general_process (void)
1821 struct remote_state
*rs
= get_remote_state ();
1823 /* If the remote can't handle multiple processes, don't bother. */
1824 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1827 /* We only need to change the remote current thread if it's pointing
1828 at some other process. */
1829 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1830 set_general_thread (inferior_ptid
);
1834 /* Return nonzero if the thread PTID is still alive on the remote
1838 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1840 struct remote_state
*rs
= get_remote_state ();
1843 if (ptid_equal (ptid
, magic_null_ptid
))
1844 /* The main thread is always alive. */
1847 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1848 /* The main thread is always alive. This can happen after a
1849 vAttach, if the remote side doesn't support
1854 endp
= rs
->buf
+ get_remote_packet_size ();
1857 write_ptid (p
, endp
, ptid
);
1860 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1861 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1864 /* About these extended threadlist and threadinfo packets. They are
1865 variable length packets but, the fields within them are often fixed
1866 length. They are redundent enough to send over UDP as is the
1867 remote protocol in general. There is a matching unit test module
1870 #define OPAQUETHREADBYTES 8
1872 /* a 64 bit opaque identifier */
1873 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1875 /* WARNING: This threadref data structure comes from the remote O.S.,
1876 libstub protocol encoding, and remote.c. It is not particularly
1879 /* Right now, the internal structure is int. We want it to be bigger.
1880 Plan to fix this. */
1882 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1884 /* gdb_ext_thread_info is an internal GDB data structure which is
1885 equivalent to the reply of the remote threadinfo packet. */
1887 struct gdb_ext_thread_info
1889 threadref threadid
; /* External form of thread reference. */
1890 int active
; /* Has state interesting to GDB?
1892 char display
[256]; /* Brief state display, name,
1893 blocked/suspended. */
1894 char shortname
[32]; /* To be used to name threads. */
1895 char more_display
[256]; /* Long info, statistics, queue depth,
1899 /* The volume of remote transfers can be limited by submitting
1900 a mask containing bits specifying the desired information.
1901 Use a union of these values as the 'selection' parameter to
1902 get_thread_info. FIXME: Make these TAG names more thread specific. */
1904 #define TAG_THREADID 1
1905 #define TAG_EXISTS 2
1906 #define TAG_DISPLAY 4
1907 #define TAG_THREADNAME 8
1908 #define TAG_MOREDISPLAY 16
1910 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1912 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1914 static char *unpack_nibble (char *buf
, int *val
);
1916 static char *pack_nibble (char *buf
, int nibble
);
1918 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1920 static char *unpack_byte (char *buf
, int *value
);
1922 static char *pack_int (char *buf
, int value
);
1924 static char *unpack_int (char *buf
, int *value
);
1926 static char *unpack_string (char *src
, char *dest
, int length
);
1928 static char *pack_threadid (char *pkt
, threadref
*id
);
1930 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1932 void int_to_threadref (threadref
*id
, int value
);
1934 static int threadref_to_int (threadref
*ref
);
1936 static void copy_threadref (threadref
*dest
, threadref
*src
);
1938 static int threadmatch (threadref
*dest
, threadref
*src
);
1940 static char *pack_threadinfo_request (char *pkt
, int mode
,
1943 static int remote_unpack_thread_info_response (char *pkt
,
1944 threadref
*expectedref
,
1945 struct gdb_ext_thread_info
1949 static int remote_get_threadinfo (threadref
*threadid
,
1950 int fieldset
, /*TAG mask */
1951 struct gdb_ext_thread_info
*info
);
1953 static char *pack_threadlist_request (char *pkt
, int startflag
,
1955 threadref
*nextthread
);
1957 static int parse_threadlist_response (char *pkt
,
1959 threadref
*original_echo
,
1960 threadref
*resultlist
,
1963 static int remote_get_threadlist (int startflag
,
1964 threadref
*nextthread
,
1968 threadref
*threadlist
);
1970 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1972 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1973 void *context
, int looplimit
);
1975 static int remote_newthread_step (threadref
*ref
, void *context
);
1978 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1979 buffer we're allowed to write to. Returns
1980 BUF+CHARACTERS_WRITTEN. */
1983 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1986 struct remote_state
*rs
= get_remote_state ();
1988 if (remote_multi_process_p (rs
))
1990 pid
= ptid_get_pid (ptid
);
1992 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1994 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1996 tid
= ptid_get_tid (ptid
);
1998 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2000 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2005 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2006 passed the last parsed char. Returns null_ptid on error. */
2009 read_ptid (char *buf
, char **obuf
)
2013 ULONGEST pid
= 0, tid
= 0;
2017 /* Multi-process ptid. */
2018 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2020 error (_("invalid remote ptid: %s"), p
);
2023 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2026 return ptid_build (pid
, 0, tid
);
2029 /* No multi-process. Just a tid. */
2030 pp
= unpack_varlen_hex (p
, &tid
);
2032 /* Since the stub is not sending a process id, then default to
2033 what's in inferior_ptid, unless it's null at this point. If so,
2034 then since there's no way to know the pid of the reported
2035 threads, use the magic number. */
2036 if (ptid_equal (inferior_ptid
, null_ptid
))
2037 pid
= ptid_get_pid (magic_null_ptid
);
2039 pid
= ptid_get_pid (inferior_ptid
);
2043 return ptid_build (pid
, 0, tid
);
2046 /* Encode 64 bits in 16 chars of hex. */
2048 static const char hexchars
[] = "0123456789abcdef";
2051 ishex (int ch
, int *val
)
2053 if ((ch
>= 'a') && (ch
<= 'f'))
2055 *val
= ch
- 'a' + 10;
2058 if ((ch
>= 'A') && (ch
<= 'F'))
2060 *val
= ch
- 'A' + 10;
2063 if ((ch
>= '0') && (ch
<= '9'))
2074 if (ch
>= 'a' && ch
<= 'f')
2075 return ch
- 'a' + 10;
2076 if (ch
>= '0' && ch
<= '9')
2078 if (ch
>= 'A' && ch
<= 'F')
2079 return ch
- 'A' + 10;
2084 stub_unpack_int (char *buff
, int fieldlength
)
2091 nibble
= stubhex (*buff
++);
2095 retval
= retval
<< 4;
2101 unpack_varlen_hex (char *buff
, /* packet to parse */
2105 ULONGEST retval
= 0;
2107 while (ishex (*buff
, &nibble
))
2110 retval
= retval
<< 4;
2111 retval
|= nibble
& 0x0f;
2118 unpack_nibble (char *buf
, int *val
)
2120 *val
= fromhex (*buf
++);
2125 pack_nibble (char *buf
, int nibble
)
2127 *buf
++ = hexchars
[(nibble
& 0x0f)];
2132 pack_hex_byte (char *pkt
, int byte
)
2134 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2135 *pkt
++ = hexchars
[(byte
& 0xf)];
2140 unpack_byte (char *buf
, int *value
)
2142 *value
= stub_unpack_int (buf
, 2);
2147 pack_int (char *buf
, int value
)
2149 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2150 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2151 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2152 buf
= pack_hex_byte (buf
, (value
& 0xff));
2157 unpack_int (char *buf
, int *value
)
2159 *value
= stub_unpack_int (buf
, 8);
2163 #if 0 /* Currently unused, uncomment when needed. */
2164 static char *pack_string (char *pkt
, char *string
);
2167 pack_string (char *pkt
, char *string
)
2172 len
= strlen (string
);
2174 len
= 200; /* Bigger than most GDB packets, junk??? */
2175 pkt
= pack_hex_byte (pkt
, len
);
2179 if ((ch
== '\0') || (ch
== '#'))
2180 ch
= '*'; /* Protect encapsulation. */
2185 #endif /* 0 (unused) */
2188 unpack_string (char *src
, char *dest
, int length
)
2197 pack_threadid (char *pkt
, threadref
*id
)
2200 unsigned char *altid
;
2202 altid
= (unsigned char *) id
;
2203 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2205 pkt
= pack_hex_byte (pkt
, *altid
++);
2211 unpack_threadid (char *inbuf
, threadref
*id
)
2214 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2217 altref
= (char *) id
;
2219 while (inbuf
< limit
)
2221 x
= stubhex (*inbuf
++);
2222 y
= stubhex (*inbuf
++);
2223 *altref
++ = (x
<< 4) | y
;
2228 /* Externally, threadrefs are 64 bits but internally, they are still
2229 ints. This is due to a mismatch of specifications. We would like
2230 to use 64bit thread references internally. This is an adapter
2234 int_to_threadref (threadref
*id
, int value
)
2236 unsigned char *scan
;
2238 scan
= (unsigned char *) id
;
2244 *scan
++ = (value
>> 24) & 0xff;
2245 *scan
++ = (value
>> 16) & 0xff;
2246 *scan
++ = (value
>> 8) & 0xff;
2247 *scan
++ = (value
& 0xff);
2251 threadref_to_int (threadref
*ref
)
2254 unsigned char *scan
;
2260 value
= (value
<< 8) | ((*scan
++) & 0xff);
2265 copy_threadref (threadref
*dest
, threadref
*src
)
2268 unsigned char *csrc
, *cdest
;
2270 csrc
= (unsigned char *) src
;
2271 cdest
= (unsigned char *) dest
;
2278 threadmatch (threadref
*dest
, threadref
*src
)
2280 /* Things are broken right now, so just assume we got a match. */
2282 unsigned char *srcp
, *destp
;
2284 srcp
= (char *) src
;
2285 destp
= (char *) dest
;
2289 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2296 threadid:1, # always request threadid
2303 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2306 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2308 *pkt
++ = 'q'; /* Info Query */
2309 *pkt
++ = 'P'; /* process or thread info */
2310 pkt
= pack_int (pkt
, mode
); /* mode */
2311 pkt
= pack_threadid (pkt
, id
); /* threadid */
2312 *pkt
= '\0'; /* terminate */
2316 /* These values tag the fields in a thread info response packet. */
2317 /* Tagging the fields allows us to request specific fields and to
2318 add more fields as time goes by. */
2320 #define TAG_THREADID 1 /* Echo the thread identifier. */
2321 #define TAG_EXISTS 2 /* Is this process defined enough to
2322 fetch registers and its stack? */
2323 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2324 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2325 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2329 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2330 struct gdb_ext_thread_info
*info
)
2332 struct remote_state
*rs
= get_remote_state ();
2336 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2339 /* info->threadid = 0; FIXME: implement zero_threadref. */
2341 info
->display
[0] = '\0';
2342 info
->shortname
[0] = '\0';
2343 info
->more_display
[0] = '\0';
2345 /* Assume the characters indicating the packet type have been
2347 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2348 pkt
= unpack_threadid (pkt
, &ref
);
2351 warning (_("Incomplete response to threadinfo request."));
2352 if (!threadmatch (&ref
, expectedref
))
2353 { /* This is an answer to a different request. */
2354 warning (_("ERROR RMT Thread info mismatch."));
2357 copy_threadref (&info
->threadid
, &ref
);
2359 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2361 /* Packets are terminated with nulls. */
2362 while ((pkt
< limit
) && mask
&& *pkt
)
2364 pkt
= unpack_int (pkt
, &tag
); /* tag */
2365 pkt
= unpack_byte (pkt
, &length
); /* length */
2366 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2368 warning (_("ERROR RMT: threadinfo tag mismatch."));
2372 if (tag
== TAG_THREADID
)
2376 warning (_("ERROR RMT: length of threadid is not 16."));
2380 pkt
= unpack_threadid (pkt
, &ref
);
2381 mask
= mask
& ~TAG_THREADID
;
2384 if (tag
== TAG_EXISTS
)
2386 info
->active
= stub_unpack_int (pkt
, length
);
2388 mask
= mask
& ~(TAG_EXISTS
);
2391 warning (_("ERROR RMT: 'exists' length too long."));
2397 if (tag
== TAG_THREADNAME
)
2399 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2400 mask
= mask
& ~TAG_THREADNAME
;
2403 if (tag
== TAG_DISPLAY
)
2405 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2406 mask
= mask
& ~TAG_DISPLAY
;
2409 if (tag
== TAG_MOREDISPLAY
)
2411 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2412 mask
= mask
& ~TAG_MOREDISPLAY
;
2415 warning (_("ERROR RMT: unknown thread info tag."));
2416 break; /* Not a tag we know about. */
2422 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2423 struct gdb_ext_thread_info
*info
)
2425 struct remote_state
*rs
= get_remote_state ();
2428 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2430 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2432 if (rs
->buf
[0] == '\0')
2435 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2440 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2443 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2444 threadref
*nextthread
)
2446 *pkt
++ = 'q'; /* info query packet */
2447 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2448 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2449 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2450 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2455 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2458 parse_threadlist_response (char *pkt
, int result_limit
,
2459 threadref
*original_echo
, threadref
*resultlist
,
2462 struct remote_state
*rs
= get_remote_state ();
2464 int count
, resultcount
, done
;
2467 /* Assume the 'q' and 'M chars have been stripped. */
2468 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2469 /* done parse past here */
2470 pkt
= unpack_byte (pkt
, &count
); /* count field */
2471 pkt
= unpack_nibble (pkt
, &done
);
2472 /* The first threadid is the argument threadid. */
2473 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2474 while ((count
-- > 0) && (pkt
< limit
))
2476 pkt
= unpack_threadid (pkt
, resultlist
++);
2477 if (resultcount
++ >= result_limit
)
2486 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2487 int *done
, int *result_count
, threadref
*threadlist
)
2489 struct remote_state
*rs
= get_remote_state ();
2490 static threadref echo_nextthread
;
2493 /* Trancate result limit to be smaller than the packet size. */
2494 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2495 >= get_remote_packet_size ())
2496 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2498 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2500 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2502 if (*rs
->buf
== '\0')
2506 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2509 if (!threadmatch (&echo_nextthread
, nextthread
))
2511 /* FIXME: This is a good reason to drop the packet. */
2512 /* Possably, there is a duplicate response. */
2514 retransmit immediatly - race conditions
2515 retransmit after timeout - yes
2517 wait for packet, then exit
2519 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2520 return 0; /* I choose simply exiting. */
2522 if (*result_count
<= 0)
2526 warning (_("RMT ERROR : failed to get remote thread list."));
2529 return result
; /* break; */
2531 if (*result_count
> result_limit
)
2534 warning (_("RMT ERROR: threadlist response longer than requested."));
2540 /* This is the interface between remote and threads, remotes upper
2543 /* remote_find_new_threads retrieves the thread list and for each
2544 thread in the list, looks up the thread in GDB's internal list,
2545 adding the thread if it does not already exist. This involves
2546 getting partial thread lists from the remote target so, polling the
2547 quit_flag is required. */
2550 /* About this many threadisds fit in a packet. */
2552 #define MAXTHREADLISTRESULTS 32
2555 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2558 int done
, i
, result_count
;
2562 static threadref nextthread
;
2563 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2568 if (loopcount
++ > looplimit
)
2571 warning (_("Remote fetch threadlist -infinite loop-."));
2574 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2575 &done
, &result_count
, resultthreadlist
))
2580 /* Clear for later iterations. */
2582 /* Setup to resume next batch of thread references, set nextthread. */
2583 if (result_count
>= 1)
2584 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2586 while (result_count
--)
2587 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2594 remote_newthread_step (threadref
*ref
, void *context
)
2596 int pid
= ptid_get_pid (inferior_ptid
);
2597 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2599 if (!in_thread_list (ptid
))
2601 return 1; /* continue iterator */
2604 #define CRAZY_MAX_THREADS 1000
2607 remote_current_thread (ptid_t oldpid
)
2609 struct remote_state
*rs
= get_remote_state ();
2612 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2613 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2614 return read_ptid (&rs
->buf
[2], NULL
);
2619 /* Find new threads for info threads command.
2620 * Original version, using John Metzler's thread protocol.
2624 remote_find_new_threads (void)
2626 remote_threadlist_iterator (remote_newthread_step
, 0,
2630 #if defined(HAVE_LIBEXPAT)
2632 typedef struct thread_item
2638 DEF_VEC_O(thread_item_t
);
2640 struct threads_parsing_context
2642 VEC (thread_item_t
) *items
;
2646 start_thread (struct gdb_xml_parser
*parser
,
2647 const struct gdb_xml_element
*element
,
2648 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2650 struct threads_parsing_context
*data
= user_data
;
2652 struct thread_item item
;
2654 struct gdb_xml_value
*attr
;
2656 id
= xml_find_attribute (attributes
, "id")->value
;
2657 item
.ptid
= read_ptid (id
, NULL
);
2659 attr
= xml_find_attribute (attributes
, "core");
2661 item
.core
= *(ULONGEST
*) attr
->value
;
2667 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2671 end_thread (struct gdb_xml_parser
*parser
,
2672 const struct gdb_xml_element
*element
,
2673 void *user_data
, const char *body_text
)
2675 struct threads_parsing_context
*data
= user_data
;
2677 if (body_text
&& *body_text
)
2678 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2681 const struct gdb_xml_attribute thread_attributes
[] = {
2682 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2683 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2684 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2687 const struct gdb_xml_element thread_children
[] = {
2688 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2691 const struct gdb_xml_element threads_children
[] = {
2692 { "thread", thread_attributes
, thread_children
,
2693 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2694 start_thread
, end_thread
},
2695 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2698 const struct gdb_xml_element threads_elements
[] = {
2699 { "threads", NULL
, threads_children
,
2700 GDB_XML_EF_NONE
, NULL
, NULL
},
2701 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2704 /* Discard the contents of the constructed thread info context. */
2707 clear_threads_parsing_context (void *p
)
2709 struct threads_parsing_context
*context
= p
;
2711 struct thread_item
*item
;
2713 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2714 xfree (item
->extra
);
2716 VEC_free (thread_item_t
, context
->items
);
2722 * Find all threads for info threads command.
2723 * Uses new thread protocol contributed by Cisco.
2724 * Falls back and attempts to use the older method (above)
2725 * if the target doesn't respond to the new method.
2729 remote_threads_info (struct target_ops
*ops
)
2731 struct remote_state
*rs
= get_remote_state ();
2735 if (rs
->remote_desc
== 0) /* paranoia */
2736 error (_("Command can only be used when connected to the remote target."));
2738 #if defined(HAVE_LIBEXPAT)
2739 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2741 char *xml
= target_read_stralloc (¤t_target
,
2742 TARGET_OBJECT_THREADS
, NULL
);
2744 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2748 struct threads_parsing_context context
;
2750 context
.items
= NULL
;
2751 make_cleanup (clear_threads_parsing_context
, &context
);
2753 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2754 threads_elements
, xml
, &context
) == 0)
2757 struct thread_item
*item
;
2760 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2763 if (!ptid_equal (item
->ptid
, null_ptid
))
2765 struct private_thread_info
*info
;
2766 /* In non-stop mode, we assume new found threads
2767 are running until proven otherwise with a
2768 stop reply. In all-stop, we can only get
2769 here if all threads are stopped. */
2770 int running
= non_stop
? 1 : 0;
2772 remote_notice_new_inferior (item
->ptid
, running
);
2774 info
= demand_private_info (item
->ptid
);
2775 info
->core
= item
->core
;
2776 info
->extra
= item
->extra
;
2783 do_cleanups (back_to
);
2788 if (use_threadinfo_query
)
2790 putpkt ("qfThreadInfo");
2791 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2793 if (bufp
[0] != '\0') /* q packet recognized */
2795 struct cleanup
*old_chain
;
2798 /* remote_notice_new_inferior (in the loop below) may make
2799 new RSP calls, which clobber rs->buf. Work with a
2801 bufp
= saved_reply
= xstrdup (rs
->buf
);
2802 old_chain
= make_cleanup (free_current_contents
, &saved_reply
);
2804 while (*bufp
++ == 'm') /* reply contains one or more TID */
2808 new_thread
= read_ptid (bufp
, &bufp
);
2809 if (!ptid_equal (new_thread
, null_ptid
))
2811 /* In non-stop mode, we assume new found threads
2812 are running until proven otherwise with a
2813 stop reply. In all-stop, we can only get
2814 here if all threads are stopped. */
2815 int running
= non_stop
? 1 : 0;
2817 remote_notice_new_inferior (new_thread
, running
);
2820 while (*bufp
++ == ','); /* comma-separated list */
2821 free_current_contents (&saved_reply
);
2822 putpkt ("qsThreadInfo");
2823 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2824 bufp
= saved_reply
= xstrdup (rs
->buf
);
2826 do_cleanups (old_chain
);
2831 /* Only qfThreadInfo is supported in non-stop mode. */
2835 /* Else fall back to old method based on jmetzler protocol. */
2836 use_threadinfo_query
= 0;
2837 remote_find_new_threads ();
2842 * Collect a descriptive string about the given thread.
2843 * The target may say anything it wants to about the thread
2844 * (typically info about its blocked / runnable state, name, etc.).
2845 * This string will appear in the info threads display.
2847 * Optional: targets are not required to implement this function.
2851 remote_threads_extra_info (struct thread_info
*tp
)
2853 struct remote_state
*rs
= get_remote_state ();
2857 struct gdb_ext_thread_info threadinfo
;
2858 static char display_buf
[100]; /* arbitrary... */
2859 int n
= 0; /* position in display_buf */
2861 if (rs
->remote_desc
== 0) /* paranoia */
2862 internal_error (__FILE__
, __LINE__
,
2863 _("remote_threads_extra_info"));
2865 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2866 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2867 /* This is the main thread which was added by GDB. The remote
2868 server doesn't know about it. */
2871 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2873 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2875 if (info
&& info
->private)
2876 return info
->private->extra
;
2881 if (use_threadextra_query
)
2884 char *endb
= rs
->buf
+ get_remote_packet_size ();
2886 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2888 write_ptid (b
, endb
, tp
->ptid
);
2891 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2892 if (rs
->buf
[0] != 0)
2894 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2895 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2896 display_buf
[result
] = '\0';
2901 /* If the above query fails, fall back to the old method. */
2902 use_threadextra_query
= 0;
2903 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2904 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2905 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2906 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2907 if (threadinfo
.active
)
2909 if (*threadinfo
.shortname
)
2910 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2911 " Name: %s,", threadinfo
.shortname
);
2912 if (*threadinfo
.display
)
2913 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2914 " State: %s,", threadinfo
.display
);
2915 if (*threadinfo
.more_display
)
2916 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2917 " Priority: %s", threadinfo
.more_display
);
2921 /* For purely cosmetic reasons, clear up trailing commas. */
2922 if (',' == display_buf
[n
-1])
2923 display_buf
[n
-1] = ' ';
2932 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2933 struct static_tracepoint_marker
*marker
)
2935 struct remote_state
*rs
= get_remote_state ();
2938 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2940 p
+= hexnumstr (p
, addr
);
2942 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2946 error (_("Remote failure reply: %s"), p
);
2950 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2957 static VEC(static_tracepoint_marker_p
) *
2958 remote_static_tracepoint_markers_by_strid (const char *strid
)
2960 struct remote_state
*rs
= get_remote_state ();
2961 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2962 struct static_tracepoint_marker
*marker
= NULL
;
2963 struct cleanup
*old_chain
;
2966 /* Ask for a first packet of static tracepoint marker
2969 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2972 error (_("Remote failure reply: %s"), p
);
2974 old_chain
= make_cleanup (free_current_marker
, &marker
);
2979 marker
= XCNEW (struct static_tracepoint_marker
);
2983 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2985 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2987 VEC_safe_push (static_tracepoint_marker_p
,
2993 release_static_tracepoint_marker (marker
);
2994 memset (marker
, 0, sizeof (*marker
));
2997 while (*p
++ == ','); /* comma-separated list */
2998 /* Ask for another packet of static tracepoint definition. */
3000 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3004 do_cleanups (old_chain
);
3009 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3012 remote_get_ada_task_ptid (long lwp
, long thread
)
3014 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
3018 /* Restart the remote side; this is an extended protocol operation. */
3021 extended_remote_restart (void)
3023 struct remote_state
*rs
= get_remote_state ();
3025 /* Send the restart command; for reasons I don't understand the
3026 remote side really expects a number after the "R". */
3027 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3030 remote_fileio_reset ();
3033 /* Clean up connection to a remote debugger. */
3038 struct remote_state
*rs
= get_remote_state ();
3040 if (rs
->remote_desc
== NULL
)
3041 return; /* already closed */
3043 /* Make sure we leave stdin registered in the event loop, and we
3044 don't leave the async SIGINT signal handler installed. */
3045 remote_terminal_ours ();
3047 serial_close (rs
->remote_desc
);
3048 rs
->remote_desc
= NULL
;
3050 /* We don't have a connection to the remote stub anymore. Get rid
3051 of all the inferiors and their threads we were controlling.
3052 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3053 will be unable to find the thread corresponding to (pid, 0, 0). */
3054 inferior_ptid
= null_ptid
;
3055 discard_all_inferiors ();
3057 /* Stop replies may from inferiors which are still unknown to GDB.
3058 We are closing the remote target, so we should discard
3059 everything, including the stop replies from GDB-unknown
3061 discard_pending_stop_replies (NULL
);
3063 if (remote_async_inferior_event_token
)
3064 delete_async_event_handler (&remote_async_inferior_event_token
);
3066 remote_notif_unregister_async_event_handler ();
3068 trace_reset_local_state ();
3071 /* Query the remote side for the text, data and bss offsets. */
3076 struct remote_state
*rs
= get_remote_state ();
3079 int lose
, num_segments
= 0, do_sections
, do_segments
;
3080 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3081 struct section_offsets
*offs
;
3082 struct symfile_segment_data
*data
;
3084 if (symfile_objfile
== NULL
)
3087 putpkt ("qOffsets");
3088 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3091 if (buf
[0] == '\000')
3092 return; /* Return silently. Stub doesn't support
3096 warning (_("Remote failure reply: %s"), buf
);
3100 /* Pick up each field in turn. This used to be done with scanf, but
3101 scanf will make trouble if CORE_ADDR size doesn't match
3102 conversion directives correctly. The following code will work
3103 with any size of CORE_ADDR. */
3104 text_addr
= data_addr
= bss_addr
= 0;
3108 if (strncmp (ptr
, "Text=", 5) == 0)
3111 /* Don't use strtol, could lose on big values. */
3112 while (*ptr
&& *ptr
!= ';')
3113 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3115 if (strncmp (ptr
, ";Data=", 6) == 0)
3118 while (*ptr
&& *ptr
!= ';')
3119 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3124 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3127 while (*ptr
&& *ptr
!= ';')
3128 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3130 if (bss_addr
!= data_addr
)
3131 warning (_("Target reported unsupported offsets: %s"), buf
);
3136 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3139 /* Don't use strtol, could lose on big values. */
3140 while (*ptr
&& *ptr
!= ';')
3141 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3144 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3147 while (*ptr
&& *ptr
!= ';')
3148 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3156 error (_("Malformed response to offset query, %s"), buf
);
3157 else if (*ptr
!= '\0')
3158 warning (_("Target reported unsupported offsets: %s"), buf
);
3160 offs
= ((struct section_offsets
*)
3161 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3162 memcpy (offs
, symfile_objfile
->section_offsets
,
3163 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3165 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3166 do_segments
= (data
!= NULL
);
3167 do_sections
= num_segments
== 0;
3169 if (num_segments
> 0)
3171 segments
[0] = text_addr
;
3172 segments
[1] = data_addr
;
3174 /* If we have two segments, we can still try to relocate everything
3175 by assuming that the .text and .data offsets apply to the whole
3176 text and data segments. Convert the offsets given in the packet
3177 to base addresses for symfile_map_offsets_to_segments. */
3178 else if (data
&& data
->num_segments
== 2)
3180 segments
[0] = data
->segment_bases
[0] + text_addr
;
3181 segments
[1] = data
->segment_bases
[1] + data_addr
;
3184 /* If the object file has only one segment, assume that it is text
3185 rather than data; main programs with no writable data are rare,
3186 but programs with no code are useless. Of course the code might
3187 have ended up in the data segment... to detect that we would need
3188 the permissions here. */
3189 else if (data
&& data
->num_segments
== 1)
3191 segments
[0] = data
->segment_bases
[0] + text_addr
;
3194 /* There's no way to relocate by segment. */
3200 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3201 offs
, num_segments
, segments
);
3203 if (ret
== 0 && !do_sections
)
3204 error (_("Can not handle qOffsets TextSeg "
3205 "response with this symbol file"));
3212 free_symfile_segment_data (data
);
3216 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3218 /* This is a temporary kludge to force data and bss to use the
3219 same offsets because that's what nlmconv does now. The real
3220 solution requires changes to the stub and remote.c that I
3221 don't have time to do right now. */
3223 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3224 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3227 objfile_relocate (symfile_objfile
, offs
);
3230 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3231 threads we know are stopped already. This is used during the
3232 initial remote connection in non-stop mode --- threads that are
3233 reported as already being stopped are left stopped. */
3236 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3238 /* If we have a stop reply for this thread, it must be stopped. */
3239 if (peek_stop_reply (thread
->ptid
))
3240 set_stop_requested (thread
->ptid
, 1);
3245 /* Send interrupt_sequence to remote target. */
3247 send_interrupt_sequence (void)
3249 struct remote_state
*rs
= get_remote_state ();
3251 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3252 remote_serial_write ("\x03", 1);
3253 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3254 serial_send_break (rs
->remote_desc
);
3255 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3257 serial_send_break (rs
->remote_desc
);
3258 remote_serial_write ("g", 1);
3261 internal_error (__FILE__
, __LINE__
,
3262 _("Invalid value for interrupt_sequence_mode: %s."),
3263 interrupt_sequence_mode
);
3267 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3268 and extract the PTID. Returns NULL_PTID if not found. */
3271 stop_reply_extract_thread (char *stop_reply
)
3273 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3277 /* Txx r:val ; r:val (...) */
3280 /* Look for "register" named "thread". */
3285 p1
= strchr (p
, ':');
3289 if (strncmp (p
, "thread", p1
- p
) == 0)
3290 return read_ptid (++p1
, &p
);
3292 p1
= strchr (p
, ';');
3304 /* Query the remote target for which is the current thread/process,
3305 add it to our tables, and update INFERIOR_PTID. The caller is
3306 responsible for setting the state such that the remote end is ready
3307 to return the current thread.
3309 This function is called after handling the '?' or 'vRun' packets,
3310 whose response is a stop reply from which we can also try
3311 extracting the thread. If the target doesn't support the explicit
3312 qC query, we infer the current thread from that stop reply, passed
3313 in in WAIT_STATUS, which may be NULL. */
3316 add_current_inferior_and_thread (char *wait_status
)
3318 struct remote_state
*rs
= get_remote_state ();
3320 ptid_t ptid
= null_ptid
;
3322 inferior_ptid
= null_ptid
;
3324 /* Now, if we have thread information, update inferior_ptid. First
3325 if we have a stop reply handy, maybe it's a T stop reply with a
3326 "thread" register we can extract the current thread from. If
3327 not, ask the remote which is the current thread, with qC. The
3328 former method avoids a roundtrip. Note we don't use
3329 remote_parse_stop_reply as that makes use of the target
3330 architecture, which we haven't yet fully determined at this
3332 if (wait_status
!= NULL
)
3333 ptid
= stop_reply_extract_thread (wait_status
);
3334 if (ptid_equal (ptid
, null_ptid
))
3335 ptid
= remote_current_thread (inferior_ptid
);
3337 if (!ptid_equal (ptid
, null_ptid
))
3339 if (!remote_multi_process_p (rs
))
3342 inferior_ptid
= ptid
;
3346 /* Without this, some commands which require an active target
3347 (such as kill) won't work. This variable serves (at least)
3348 double duty as both the pid of the target process (if it has
3349 such), and as a flag indicating that a target is active. */
3350 inferior_ptid
= magic_null_ptid
;
3354 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3356 /* Add the main thread. */
3357 add_thread_silent (inferior_ptid
);
3361 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3363 struct remote_state
*rs
= get_remote_state ();
3364 struct packet_config
*noack_config
;
3365 char *wait_status
= NULL
;
3367 immediate_quit
++; /* Allow user to interrupt it. */
3370 if (interrupt_on_connect
)
3371 send_interrupt_sequence ();
3373 /* Ack any packet which the remote side has already sent. */
3374 serial_write (rs
->remote_desc
, "+", 1);
3376 /* Signal other parts that we're going through the initial setup,
3377 and so things may not be stable yet. */
3378 rs
->starting_up
= 1;
3380 /* The first packet we send to the target is the optional "supported
3381 packets" request. If the target can answer this, it will tell us
3382 which later probes to skip. */
3383 remote_query_supported ();
3385 /* If the stub wants to get a QAllow, compose one and send it. */
3386 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3387 remote_set_permissions ();
3389 /* Next, we possibly activate noack mode.
3391 If the QStartNoAckMode packet configuration is set to AUTO,
3392 enable noack mode if the stub reported a wish for it with
3395 If set to TRUE, then enable noack mode even if the stub didn't
3396 report it in qSupported. If the stub doesn't reply OK, the
3397 session ends with an error.
3399 If FALSE, then don't activate noack mode, regardless of what the
3400 stub claimed should be the default with qSupported. */
3402 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3404 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3405 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3406 && noack_config
->support
== PACKET_ENABLE
))
3408 putpkt ("QStartNoAckMode");
3409 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3410 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3416 /* Tell the remote that we are using the extended protocol. */
3418 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3421 /* Let the target know which signals it is allowed to pass down to
3423 update_signals_program_target ();
3425 /* Next, if the target can specify a description, read it. We do
3426 this before anything involving memory or registers. */
3427 target_find_description ();
3429 /* Next, now that we know something about the target, update the
3430 address spaces in the program spaces. */
3431 update_address_spaces ();
3433 /* On OSs where the list of libraries is global to all
3434 processes, we fetch them early. */
3435 if (gdbarch_has_global_solist (target_gdbarch ()))
3436 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3440 if (!rs
->non_stop_aware
)
3441 error (_("Non-stop mode requested, but remote "
3442 "does not support non-stop"));
3444 putpkt ("QNonStop:1");
3445 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3447 if (strcmp (rs
->buf
, "OK") != 0)
3448 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3450 /* Find about threads and processes the stub is already
3451 controlling. We default to adding them in the running state.
3452 The '?' query below will then tell us about which threads are
3454 remote_threads_info (target
);
3456 else if (rs
->non_stop_aware
)
3458 /* Don't assume that the stub can operate in all-stop mode.
3459 Request it explicitly. */
3460 putpkt ("QNonStop:0");
3461 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3463 if (strcmp (rs
->buf
, "OK") != 0)
3464 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3467 /* Upload TSVs regardless of whether the target is running or not. The
3468 remote stub, such as GDBserver, may have some predefined or builtin
3469 TSVs, even if the target is not running. */
3470 if (remote_get_trace_status (current_trace_status ()) != -1)
3472 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3474 remote_upload_trace_state_variables (&uploaded_tsvs
);
3475 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3478 /* Check whether the target is running now. */
3480 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3486 struct inferior
*inf
;
3488 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3491 error (_("The target is not running (try extended-remote?)"));
3493 /* We're connected, but not running. Drop out before we
3494 call start_remote. */
3495 rs
->starting_up
= 0;
3500 /* Save the reply for later. */
3501 wait_status
= alloca (strlen (rs
->buf
) + 1);
3502 strcpy (wait_status
, rs
->buf
);
3505 /* Let the stub know that we want it to return the thread. */
3506 set_continue_thread (minus_one_ptid
);
3508 add_current_inferior_and_thread (wait_status
);
3510 /* init_wait_for_inferior should be called before get_offsets in order
3511 to manage `inserted' flag in bp loc in a correct state.
3512 breakpoint_init_inferior, called from init_wait_for_inferior, set
3513 `inserted' flag to 0, while before breakpoint_re_set, called from
3514 start_remote, set `inserted' flag to 1. In the initialization of
3515 inferior, breakpoint_init_inferior should be called first, and then
3516 breakpoint_re_set can be called. If this order is broken, state of
3517 `inserted' flag is wrong, and cause some problems on breakpoint
3519 init_wait_for_inferior ();
3521 get_offsets (); /* Get text, data & bss offsets. */
3523 /* If we could not find a description using qXfer, and we know
3524 how to do it some other way, try again. This is not
3525 supported for non-stop; it could be, but it is tricky if
3526 there are no stopped threads when we connect. */
3527 if (remote_read_description_p (target
)
3528 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3530 target_clear_description ();
3531 target_find_description ();
3534 /* Use the previously fetched status. */
3535 gdb_assert (wait_status
!= NULL
);
3536 strcpy (rs
->buf
, wait_status
);
3537 rs
->cached_wait_status
= 1;
3540 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3544 /* Clear WFI global state. Do this before finding about new
3545 threads and inferiors, and setting the current inferior.
3546 Otherwise we would clear the proceed status of the current
3547 inferior when we want its stop_soon state to be preserved
3548 (see notice_new_inferior). */
3549 init_wait_for_inferior ();
3551 /* In non-stop, we will either get an "OK", meaning that there
3552 are no stopped threads at this time; or, a regular stop
3553 reply. In the latter case, there may be more than one thread
3554 stopped --- we pull them all out using the vStopped
3556 if (strcmp (rs
->buf
, "OK") != 0)
3558 struct notif_client
*notif
= ¬if_client_stop
;
3560 /* remote_notif_get_pending_replies acks this one, and gets
3562 notif_client_stop
.pending_event
3563 = remote_notif_parse (notif
, rs
->buf
);
3564 remote_notif_get_pending_events (notif
);
3566 /* Make sure that threads that were stopped remain
3568 iterate_over_threads (set_stop_requested_callback
, NULL
);
3571 if (target_can_async_p ())
3572 target_async (inferior_event_handler
, 0);
3574 if (thread_count () == 0)
3577 error (_("The target is not running (try extended-remote?)"));
3579 /* We're connected, but not running. Drop out before we
3580 call start_remote. */
3581 rs
->starting_up
= 0;
3585 /* Let the stub know that we want it to return the thread. */
3587 /* Force the stub to choose a thread. */
3588 set_general_thread (null_ptid
);
3591 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3592 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3593 error (_("remote didn't report the current thread in non-stop mode"));
3595 get_offsets (); /* Get text, data & bss offsets. */
3597 /* In non-stop mode, any cached wait status will be stored in
3598 the stop reply queue. */
3599 gdb_assert (wait_status
== NULL
);
3601 /* Report all signals during attach/startup. */
3602 remote_pass_signals (0, NULL
);
3605 /* If we connected to a live target, do some additional setup. */
3606 if (target_has_execution
)
3608 if (exec_bfd
) /* No use without an exec file. */
3609 remote_check_symbols ();
3612 /* Possibly the target has been engaged in a trace run started
3613 previously; find out where things are at. */
3614 if (remote_get_trace_status (current_trace_status ()) != -1)
3616 struct uploaded_tp
*uploaded_tps
= NULL
;
3618 if (current_trace_status ()->running
)
3619 printf_filtered (_("Trace is already running on the target.\n"));
3621 remote_upload_tracepoints (&uploaded_tps
);
3623 merge_uploaded_tracepoints (&uploaded_tps
);
3626 /* The thread and inferior lists are now synchronized with the
3627 target, our symbols have been relocated, and we're merged the
3628 target's tracepoints with ours. We're done with basic start
3630 rs
->starting_up
= 0;
3632 /* If breakpoints are global, insert them now. */
3633 if (gdbarch_has_global_breakpoints (target_gdbarch ())
3634 && breakpoints_always_inserted_mode ())
3635 insert_breakpoints ();
3638 /* Open a connection to a remote debugger.
3639 NAME is the filename used for communication. */
3642 remote_open (char *name
, int from_tty
)
3644 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3647 /* Open a connection to a remote debugger using the extended
3648 remote gdb protocol. NAME is the filename used for communication. */
3651 extended_remote_open (char *name
, int from_tty
)
3653 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3656 /* Generic code for opening a connection to a remote target. */
3659 init_all_packet_configs (void)
3663 for (i
= 0; i
< PACKET_MAX
; i
++)
3664 update_packet_config (&remote_protocol_packets
[i
]);
3667 /* Symbol look-up. */
3670 remote_check_symbols (void)
3672 struct remote_state
*rs
= get_remote_state ();
3673 char *msg
, *reply
, *tmp
;
3674 struct minimal_symbol
*sym
;
3677 /* The remote side has no concept of inferiors that aren't running
3678 yet, it only knows about running processes. If we're connected
3679 but our current inferior is not running, we should not invite the
3680 remote target to request symbol lookups related to its
3681 (unrelated) current process. */
3682 if (!target_has_execution
)
3685 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3688 /* Make sure the remote is pointing at the right process. Note
3689 there's no way to select "no process". */
3690 set_general_process ();
3692 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3693 because we need both at the same time. */
3694 msg
= alloca (get_remote_packet_size ());
3696 /* Invite target to request symbol lookups. */
3698 putpkt ("qSymbol::");
3699 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3700 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3703 while (strncmp (reply
, "qSymbol:", 8) == 0)
3706 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3708 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3710 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3713 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3714 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3716 /* If this is a function address, return the start of code
3717 instead of any data function descriptor. */
3718 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3722 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3723 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3727 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3732 static struct serial
*
3733 remote_serial_open (char *name
)
3735 static int udp_warning
= 0;
3737 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3738 of in ser-tcp.c, because it is the remote protocol assuming that the
3739 serial connection is reliable and not the serial connection promising
3741 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3743 warning (_("The remote protocol may be unreliable over UDP.\n"
3744 "Some events may be lost, rendering further debugging "
3749 return serial_open (name
);
3752 /* Inform the target of our permission settings. The permission flags
3753 work without this, but if the target knows the settings, it can do
3754 a couple things. First, it can add its own check, to catch cases
3755 that somehow manage to get by the permissions checks in target
3756 methods. Second, if the target is wired to disallow particular
3757 settings (for instance, a system in the field that is not set up to
3758 be able to stop at a breakpoint), it can object to any unavailable
3762 remote_set_permissions (void)
3764 struct remote_state
*rs
= get_remote_state ();
3766 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3767 "WriteReg:%x;WriteMem:%x;"
3768 "InsertBreak:%x;InsertTrace:%x;"
3769 "InsertFastTrace:%x;Stop:%x",
3770 may_write_registers
, may_write_memory
,
3771 may_insert_breakpoints
, may_insert_tracepoints
,
3772 may_insert_fast_tracepoints
, may_stop
);
3774 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3776 /* If the target didn't like the packet, warn the user. Do not try
3777 to undo the user's settings, that would just be maddening. */
3778 if (strcmp (rs
->buf
, "OK") != 0)
3779 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3782 /* This type describes each known response to the qSupported
3784 struct protocol_feature
3786 /* The name of this protocol feature. */
3789 /* The default for this protocol feature. */
3790 enum packet_support default_support
;
3792 /* The function to call when this feature is reported, or after
3793 qSupported processing if the feature is not supported.
3794 The first argument points to this structure. The second
3795 argument indicates whether the packet requested support be
3796 enabled, disabled, or probed (or the default, if this function
3797 is being called at the end of processing and this feature was
3798 not reported). The third argument may be NULL; if not NULL, it
3799 is a NUL-terminated string taken from the packet following
3800 this feature's name and an equals sign. */
3801 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3804 /* The corresponding packet for this feature. Only used if
3805 FUNC is remote_supported_packet. */
3810 remote_supported_packet (const struct protocol_feature
*feature
,
3811 enum packet_support support
,
3812 const char *argument
)
3816 warning (_("Remote qSupported response supplied an unexpected value for"
3817 " \"%s\"."), feature
->name
);
3821 if (remote_protocol_packets
[feature
->packet
].support
3822 == PACKET_SUPPORT_UNKNOWN
)
3823 remote_protocol_packets
[feature
->packet
].support
= support
;
3827 remote_packet_size (const struct protocol_feature
*feature
,
3828 enum packet_support support
, const char *value
)
3830 struct remote_state
*rs
= get_remote_state ();
3835 if (support
!= PACKET_ENABLE
)
3838 if (value
== NULL
|| *value
== '\0')
3840 warning (_("Remote target reported \"%s\" without a size."),
3846 packet_size
= strtol (value
, &value_end
, 16);
3847 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3849 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3850 feature
->name
, value
);
3854 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3856 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3857 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3858 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3861 /* Record the new maximum packet size. */
3862 rs
->explicit_packet_size
= packet_size
;
3866 remote_multi_process_feature (const struct protocol_feature
*feature
,
3867 enum packet_support support
, const char *value
)
3869 struct remote_state
*rs
= get_remote_state ();
3871 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3875 remote_non_stop_feature (const struct protocol_feature
*feature
,
3876 enum packet_support support
, const char *value
)
3878 struct remote_state
*rs
= get_remote_state ();
3880 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3884 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3885 enum packet_support support
,
3888 struct remote_state
*rs
= get_remote_state ();
3890 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3894 remote_cond_breakpoint_feature (const struct protocol_feature
*feature
,
3895 enum packet_support support
,
3898 struct remote_state
*rs
= get_remote_state ();
3900 rs
->cond_breakpoints
= (support
== PACKET_ENABLE
);
3904 remote_breakpoint_commands_feature (const struct protocol_feature
*feature
,
3905 enum packet_support support
,
3908 struct remote_state
*rs
= get_remote_state ();
3910 rs
->breakpoint_commands
= (support
== PACKET_ENABLE
);
3914 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3915 enum packet_support support
,
3918 struct remote_state
*rs
= get_remote_state ();
3920 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3924 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3925 enum packet_support support
,
3928 struct remote_state
*rs
= get_remote_state ();
3930 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3934 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3935 enum packet_support support
,
3938 struct remote_state
*rs
= get_remote_state ();
3940 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3944 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3945 enum packet_support support
,
3948 struct remote_state
*rs
= get_remote_state ();
3950 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3954 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3955 enum packet_support support
,
3958 struct remote_state
*rs
= get_remote_state ();
3960 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3964 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3965 enum packet_support support
,
3968 struct remote_state
*rs
= get_remote_state ();
3970 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3974 remote_augmented_libraries_svr4_read_feature
3975 (const struct protocol_feature
*feature
,
3976 enum packet_support support
, const char *value
)
3978 struct remote_state
*rs
= get_remote_state ();
3980 rs
->augmented_libraries_svr4_read
= (support
== PACKET_ENABLE
);
3983 static const struct protocol_feature remote_protocol_features
[] = {
3984 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3985 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3986 PACKET_qXfer_auxv
},
3987 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3988 PACKET_qXfer_features
},
3989 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3990 PACKET_qXfer_libraries
},
3991 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3992 PACKET_qXfer_libraries_svr4
},
3993 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
3994 remote_augmented_libraries_svr4_read_feature
, -1 },
3995 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3996 PACKET_qXfer_memory_map
},
3997 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3998 PACKET_qXfer_spu_read
},
3999 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4000 PACKET_qXfer_spu_write
},
4001 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4002 PACKET_qXfer_osdata
},
4003 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4004 PACKET_qXfer_threads
},
4005 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4006 PACKET_qXfer_traceframe_info
},
4007 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4008 PACKET_QPassSignals
},
4009 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4010 PACKET_QProgramSignals
},
4011 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4012 PACKET_QStartNoAckMode
},
4013 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
4014 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
4015 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4016 PACKET_qXfer_siginfo_read
},
4017 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4018 PACKET_qXfer_siginfo_write
},
4019 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
4020 PACKET_ConditionalTracepoints
},
4021 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_cond_breakpoint_feature
,
4022 PACKET_ConditionalBreakpoints
},
4023 { "BreakpointCommands", PACKET_DISABLE
, remote_breakpoint_commands_feature
,
4024 PACKET_BreakpointCommands
},
4025 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
4026 PACKET_FastTracepoints
},
4027 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
4028 PACKET_StaticTracepoints
},
4029 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
4030 PACKET_InstallInTrace
},
4031 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
4033 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4035 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4037 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4038 PACKET_TracepointSource
},
4039 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4041 { "EnableDisableTracepoints", PACKET_DISABLE
,
4042 remote_enable_disable_tracepoint_feature
, -1 },
4043 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4044 PACKET_qXfer_fdpic
},
4045 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4047 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4048 PACKET_QDisableRandomization
},
4049 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4050 { "QTBuffer:size", PACKET_DISABLE
,
4051 remote_supported_packet
, PACKET_QTBuffer_size
},
4052 { "tracenz", PACKET_DISABLE
,
4053 remote_string_tracing_feature
, -1 },
4054 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4055 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4056 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4057 PACKET_qXfer_btrace
}
4060 static char *remote_support_xml
;
4062 /* Register string appended to "xmlRegisters=" in qSupported query. */
4065 register_remote_support_xml (const char *xml
)
4067 #if defined(HAVE_LIBEXPAT)
4068 if (remote_support_xml
== NULL
)
4069 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4072 char *copy
= xstrdup (remote_support_xml
+ 13);
4073 char *p
= strtok (copy
, ",");
4077 if (strcmp (p
, xml
) == 0)
4084 while ((p
= strtok (NULL
, ",")) != NULL
);
4087 remote_support_xml
= reconcat (remote_support_xml
,
4088 remote_support_xml
, ",", xml
,
4095 remote_query_supported_append (char *msg
, const char *append
)
4098 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4100 return xstrdup (append
);
4104 remote_query_supported (void)
4106 struct remote_state
*rs
= get_remote_state ();
4109 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4111 /* The packet support flags are handled differently for this packet
4112 than for most others. We treat an error, a disabled packet, and
4113 an empty response identically: any features which must be reported
4114 to be used will be automatically disabled. An empty buffer
4115 accomplishes this, since that is also the representation for a list
4116 containing no features. */
4119 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
4122 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4124 q
= remote_query_supported_append (q
, "multiprocess+");
4126 if (remote_support_xml
)
4127 q
= remote_query_supported_append (q
, remote_support_xml
);
4129 q
= remote_query_supported_append (q
, "qRelocInsn+");
4131 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4134 do_cleanups (old_chain
);
4136 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4138 /* If an error occured, warn, but do not return - just reset the
4139 buffer to empty and go on to disable features. */
4140 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4143 warning (_("Remote failure reply: %s"), rs
->buf
);
4148 memset (seen
, 0, sizeof (seen
));
4153 enum packet_support is_supported
;
4154 char *p
, *end
, *name_end
, *value
;
4156 /* First separate out this item from the rest of the packet. If
4157 there's another item after this, we overwrite the separator
4158 (terminated strings are much easier to work with). */
4160 end
= strchr (p
, ';');
4163 end
= p
+ strlen (p
);
4173 warning (_("empty item in \"qSupported\" response"));
4178 name_end
= strchr (p
, '=');
4181 /* This is a name=value entry. */
4182 is_supported
= PACKET_ENABLE
;
4183 value
= name_end
+ 1;
4192 is_supported
= PACKET_ENABLE
;
4196 is_supported
= PACKET_DISABLE
;
4200 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4204 warning (_("unrecognized item \"%s\" "
4205 "in \"qSupported\" response"), p
);
4211 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4212 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4214 const struct protocol_feature
*feature
;
4217 feature
= &remote_protocol_features
[i
];
4218 feature
->func (feature
, is_supported
, value
);
4223 /* If we increased the packet size, make sure to increase the global
4224 buffer size also. We delay this until after parsing the entire
4225 qSupported packet, because this is the same buffer we were
4227 if (rs
->buf_size
< rs
->explicit_packet_size
)
4229 rs
->buf_size
= rs
->explicit_packet_size
;
4230 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4233 /* Handle the defaults for unmentioned features. */
4234 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4237 const struct protocol_feature
*feature
;
4239 feature
= &remote_protocol_features
[i
];
4240 feature
->func (feature
, feature
->default_support
, NULL
);
4244 /* Remove any of the remote.c targets from target stack. Upper targets depend
4245 on it so remove them first. */
4248 remote_unpush_target (void)
4250 pop_all_targets_above (process_stratum
- 1);
4254 remote_open_1 (char *name
, int from_tty
,
4255 struct target_ops
*target
, int extended_p
)
4257 struct remote_state
*rs
= get_remote_state ();
4260 error (_("To open a remote debug connection, you need to specify what\n"
4261 "serial device is attached to the remote system\n"
4262 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4264 /* See FIXME above. */
4265 if (!target_async_permitted
)
4266 wait_forever_enabled_p
= 1;
4268 /* If we're connected to a running target, target_preopen will kill it.
4269 Ask this question first, before target_preopen has a chance to kill
4271 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4274 && !query (_("Already connected to a remote target. Disconnect? ")))
4275 error (_("Still connected."));
4278 /* Here the possibly existing remote target gets unpushed. */
4279 target_preopen (from_tty
);
4281 /* Make sure we send the passed signals list the next time we resume. */
4282 xfree (rs
->last_pass_packet
);
4283 rs
->last_pass_packet
= NULL
;
4285 /* Make sure we send the program signals list the next time we
4287 xfree (rs
->last_program_signals_packet
);
4288 rs
->last_program_signals_packet
= NULL
;
4290 remote_fileio_reset ();
4291 reopen_exec_file ();
4294 rs
->remote_desc
= remote_serial_open (name
);
4295 if (!rs
->remote_desc
)
4296 perror_with_name (name
);
4298 if (baud_rate
!= -1)
4300 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4302 /* The requested speed could not be set. Error out to
4303 top level after closing remote_desc. Take care to
4304 set remote_desc to NULL to avoid closing remote_desc
4306 serial_close (rs
->remote_desc
);
4307 rs
->remote_desc
= NULL
;
4308 perror_with_name (name
);
4312 serial_raw (rs
->remote_desc
);
4314 /* If there is something sitting in the buffer we might take it as a
4315 response to a command, which would be bad. */
4316 serial_flush_input (rs
->remote_desc
);
4320 puts_filtered ("Remote debugging using ");
4321 puts_filtered (name
);
4322 puts_filtered ("\n");
4324 push_target (target
); /* Switch to using remote target now. */
4326 /* Register extra event sources in the event loop. */
4327 remote_async_inferior_event_token
4328 = create_async_event_handler (remote_async_inferior_event_handler
,
4330 remote_notif_register_async_event_handler ();
4332 /* Reset the target state; these things will be queried either by
4333 remote_query_supported or as they are needed. */
4334 init_all_packet_configs ();
4335 rs
->cached_wait_status
= 0;
4336 rs
->explicit_packet_size
= 0;
4338 rs
->multi_process_aware
= 0;
4339 rs
->extended
= extended_p
;
4340 rs
->non_stop_aware
= 0;
4341 rs
->waiting_for_stop_reply
= 0;
4342 rs
->ctrlc_pending_p
= 0;
4344 rs
->general_thread
= not_sent_ptid
;
4345 rs
->continue_thread
= not_sent_ptid
;
4346 rs
->remote_traceframe_number
= -1;
4348 /* Probe for ability to use "ThreadInfo" query, as required. */
4349 use_threadinfo_query
= 1;
4350 use_threadextra_query
= 1;
4352 if (target_async_permitted
)
4354 /* With this target we start out by owning the terminal. */
4355 remote_async_terminal_ours_p
= 1;
4357 /* FIXME: cagney/1999-09-23: During the initial connection it is
4358 assumed that the target is already ready and able to respond to
4359 requests. Unfortunately remote_start_remote() eventually calls
4360 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4361 around this. Eventually a mechanism that allows
4362 wait_for_inferior() to expect/get timeouts will be
4364 wait_forever_enabled_p
= 0;
4367 /* First delete any symbols previously loaded from shared libraries. */
4368 no_shared_libraries (NULL
, 0);
4371 init_thread_list ();
4373 /* Start the remote connection. If error() or QUIT, discard this
4374 target (we'd otherwise be in an inconsistent state) and then
4375 propogate the error on up the exception chain. This ensures that
4376 the caller doesn't stumble along blindly assuming that the
4377 function succeeded. The CLI doesn't have this problem but other
4378 UI's, such as MI do.
4380 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4381 this function should return an error indication letting the
4382 caller restore the previous state. Unfortunately the command
4383 ``target remote'' is directly wired to this function making that
4384 impossible. On a positive note, the CLI side of this problem has
4385 been fixed - the function set_cmd_context() makes it possible for
4386 all the ``target ....'' commands to share a common callback
4387 function. See cli-dump.c. */
4389 volatile struct gdb_exception ex
;
4391 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4393 remote_start_remote (from_tty
, target
, extended_p
);
4397 /* Pop the partially set up target - unless something else did
4398 already before throwing the exception. */
4399 if (rs
->remote_desc
!= NULL
)
4400 remote_unpush_target ();
4401 if (target_async_permitted
)
4402 wait_forever_enabled_p
= 1;
4403 throw_exception (ex
);
4407 if (target_async_permitted
)
4408 wait_forever_enabled_p
= 1;
4411 /* This takes a program previously attached to and detaches it. After
4412 this is done, GDB can be used to debug some other program. We
4413 better not have left any breakpoints in the target program or it'll
4414 die when it hits one. */
4417 remote_detach_1 (char *args
, int from_tty
, int extended
)
4419 int pid
= ptid_get_pid (inferior_ptid
);
4420 struct remote_state
*rs
= get_remote_state ();
4423 error (_("Argument given to \"detach\" when remotely debugging."));
4425 if (!target_has_execution
)
4426 error (_("No process to detach from."));
4430 char *exec_file
= get_exec_file (0);
4431 if (exec_file
== NULL
)
4433 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4434 target_pid_to_str (pid_to_ptid (pid
)));
4435 gdb_flush (gdb_stdout
);
4438 /* Tell the remote target to detach. */
4439 if (remote_multi_process_p (rs
))
4440 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4442 strcpy (rs
->buf
, "D");
4445 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4447 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4449 else if (rs
->buf
[0] == '\0')
4450 error (_("Remote doesn't know how to detach"));
4452 error (_("Can't detach process."));
4454 if (from_tty
&& !extended
)
4455 puts_filtered (_("Ending remote debugging.\n"));
4457 target_mourn_inferior ();
4461 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4463 remote_detach_1 (args
, from_tty
, 0);
4467 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4469 remote_detach_1 (args
, from_tty
, 1);
4472 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4475 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4478 error (_("Argument given to \"disconnect\" when remotely debugging."));
4480 /* Make sure we unpush even the extended remote targets; mourn
4481 won't do it. So call remote_mourn_1 directly instead of
4482 target_mourn_inferior. */
4483 remote_mourn_1 (target
);
4486 puts_filtered ("Ending remote debugging.\n");
4489 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4490 be chatty about it. */
4493 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4495 struct remote_state
*rs
= get_remote_state ();
4497 char *wait_status
= NULL
;
4499 pid
= parse_pid_to_attach (args
);
4501 /* Remote PID can be freely equal to getpid, do not check it here the same
4502 way as in other targets. */
4504 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4505 error (_("This target does not support attaching to a process"));
4509 char *exec_file
= get_exec_file (0);
4512 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4513 target_pid_to_str (pid_to_ptid (pid
)));
4515 printf_unfiltered (_("Attaching to %s\n"),
4516 target_pid_to_str (pid_to_ptid (pid
)));
4518 gdb_flush (gdb_stdout
);
4521 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4523 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4525 if (packet_ok (rs
->buf
,
4526 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4530 /* Save the reply for later. */
4531 wait_status
= alloca (strlen (rs
->buf
) + 1);
4532 strcpy (wait_status
, rs
->buf
);
4534 else if (strcmp (rs
->buf
, "OK") != 0)
4535 error (_("Attaching to %s failed with: %s"),
4536 target_pid_to_str (pid_to_ptid (pid
)),
4539 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4540 error (_("This target does not support attaching to a process"));
4542 error (_("Attaching to %s failed"),
4543 target_pid_to_str (pid_to_ptid (pid
)));
4545 set_current_inferior (remote_add_inferior (0, pid
, 1));
4547 inferior_ptid
= pid_to_ptid (pid
);
4551 struct thread_info
*thread
;
4553 /* Get list of threads. */
4554 remote_threads_info (target
);
4556 thread
= first_thread_of_process (pid
);
4558 inferior_ptid
= thread
->ptid
;
4560 inferior_ptid
= pid_to_ptid (pid
);
4562 /* Invalidate our notion of the remote current thread. */
4563 record_currthread (rs
, minus_one_ptid
);
4567 /* Now, if we have thread information, update inferior_ptid. */
4568 inferior_ptid
= remote_current_thread (inferior_ptid
);
4570 /* Add the main thread to the thread list. */
4571 add_thread_silent (inferior_ptid
);
4574 /* Next, if the target can specify a description, read it. We do
4575 this before anything involving memory or registers. */
4576 target_find_description ();
4580 /* Use the previously fetched status. */
4581 gdb_assert (wait_status
!= NULL
);
4583 if (target_can_async_p ())
4585 struct notif_event
*reply
4586 = remote_notif_parse (¬if_client_stop
, wait_status
);
4588 push_stop_reply ((struct stop_reply
*) reply
);
4590 target_async (inferior_event_handler
, 0);
4594 gdb_assert (wait_status
!= NULL
);
4595 strcpy (rs
->buf
, wait_status
);
4596 rs
->cached_wait_status
= 1;
4600 gdb_assert (wait_status
== NULL
);
4604 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4606 extended_remote_attach_1 (ops
, args
, from_tty
);
4609 /* Convert hex digit A to a number. */
4614 if (a
>= '0' && a
<= '9')
4616 else if (a
>= 'a' && a
<= 'f')
4617 return a
- 'a' + 10;
4618 else if (a
>= 'A' && a
<= 'F')
4619 return a
- 'A' + 10;
4621 error (_("Reply contains invalid hex digit %d"), a
);
4625 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4629 for (i
= 0; i
< count
; i
++)
4631 if (hex
[0] == 0 || hex
[1] == 0)
4633 /* Hex string is short, or of uneven length.
4634 Return the count that has been converted so far. */
4637 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4643 /* Convert number NIB to a hex digit. */
4651 return 'a' + nib
- 10;
4655 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4659 /* May use a length, or a nul-terminated string as input. */
4661 count
= strlen ((char *) bin
);
4663 for (i
= 0; i
< count
; i
++)
4665 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4666 *hex
++ = tohex (*bin
++ & 0xf);
4672 /* Check for the availability of vCont. This function should also check
4676 remote_vcont_probe (struct remote_state
*rs
)
4680 strcpy (rs
->buf
, "vCont?");
4682 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4685 /* Make sure that the features we assume are supported. */
4686 if (strncmp (buf
, "vCont", 5) == 0)
4689 int support_s
, support_S
, support_c
, support_C
;
4695 rs
->supports_vCont
.t
= 0;
4696 rs
->supports_vCont
.r
= 0;
4697 while (p
&& *p
== ';')
4700 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4702 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4704 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4706 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4708 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4709 rs
->supports_vCont
.t
= 1;
4710 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4711 rs
->supports_vCont
.r
= 1;
4713 p
= strchr (p
, ';');
4716 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4717 BUF will make packet_ok disable the packet. */
4718 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4722 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4725 /* Helper function for building "vCont" resumptions. Write a
4726 resumption to P. ENDP points to one-passed-the-end of the buffer
4727 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4728 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4729 resumed thread should be single-stepped and/or signalled. If PTID
4730 equals minus_one_ptid, then all threads are resumed; if PTID
4731 represents a process, then all threads of the process are resumed;
4732 the thread to be stepped and/or signalled is given in the global
4736 append_resumption (char *p
, char *endp
,
4737 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4739 struct remote_state
*rs
= get_remote_state ();
4741 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4742 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4744 /* GDB is willing to range step. */
4745 && use_range_stepping
4746 /* Target supports range stepping. */
4747 && rs
->supports_vCont
.r
4748 /* We don't currently support range stepping multiple
4749 threads with a wildcard (though the protocol allows it,
4750 so stubs shouldn't make an active effort to forbid
4752 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4754 struct thread_info
*tp
;
4756 if (ptid_equal (ptid
, minus_one_ptid
))
4758 /* If we don't know about the target thread's tid, then
4759 we're resuming magic_null_ptid (see caller). */
4760 tp
= find_thread_ptid (magic_null_ptid
);
4763 tp
= find_thread_ptid (ptid
);
4764 gdb_assert (tp
!= NULL
);
4766 if (tp
->control
.may_range_step
)
4768 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4770 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
4771 phex_nz (tp
->control
.step_range_start
,
4773 phex_nz (tp
->control
.step_range_end
,
4777 p
+= xsnprintf (p
, endp
- p
, ";s");
4780 p
+= xsnprintf (p
, endp
- p
, ";s");
4781 else if (siggnal
!= GDB_SIGNAL_0
)
4782 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4784 p
+= xsnprintf (p
, endp
- p
, ";c");
4786 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4790 /* All (-1) threads of process. */
4791 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4793 p
+= xsnprintf (p
, endp
- p
, ":");
4794 p
= write_ptid (p
, endp
, nptid
);
4796 else if (!ptid_equal (ptid
, minus_one_ptid
))
4798 p
+= xsnprintf (p
, endp
- p
, ":");
4799 p
= write_ptid (p
, endp
, ptid
);
4805 /* Append a vCont continue-with-signal action for threads that have a
4806 non-zero stop signal. */
4809 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4811 struct thread_info
*thread
;
4813 ALL_THREADS (thread
)
4814 if (ptid_match (thread
->ptid
, ptid
)
4815 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4816 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4817 && signal_pass_state (thread
->suspend
.stop_signal
))
4819 p
= append_resumption (p
, endp
, thread
->ptid
,
4820 0, thread
->suspend
.stop_signal
);
4821 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4827 /* Resume the remote inferior by using a "vCont" packet. The thread
4828 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4829 resumed thread should be single-stepped and/or signalled. If PTID
4830 equals minus_one_ptid, then all threads are resumed; the thread to
4831 be stepped and/or signalled is given in the global INFERIOR_PTID.
4832 This function returns non-zero iff it resumes the inferior.
4834 This function issues a strict subset of all possible vCont commands at the
4838 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4840 struct remote_state
*rs
= get_remote_state ();
4844 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4845 remote_vcont_probe (rs
);
4847 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4851 endp
= rs
->buf
+ get_remote_packet_size ();
4853 /* If we could generate a wider range of packets, we'd have to worry
4854 about overflowing BUF. Should there be a generic
4855 "multi-part-packet" packet? */
4857 p
+= xsnprintf (p
, endp
- p
, "vCont");
4859 if (ptid_equal (ptid
, magic_null_ptid
))
4861 /* MAGIC_NULL_PTID means that we don't have any active threads,
4862 so we don't have any TID numbers the inferior will
4863 understand. Make sure to only send forms that do not specify
4865 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4867 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4869 /* Resume all threads (of all processes, or of a single
4870 process), with preference for INFERIOR_PTID. This assumes
4871 inferior_ptid belongs to the set of all threads we are about
4873 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4875 /* Step inferior_ptid, with or without signal. */
4876 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4879 /* Also pass down any pending signaled resumption for other
4880 threads not the current. */
4881 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4883 /* And continue others without a signal. */
4884 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4888 /* Scheduler locking; resume only PTID. */
4889 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4892 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4897 /* In non-stop, the stub replies to vCont with "OK". The stop
4898 reply will be reported asynchronously by means of a `%Stop'
4900 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4901 if (strcmp (rs
->buf
, "OK") != 0)
4902 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4908 /* Tell the remote machine to resume. */
4910 static enum gdb_signal last_sent_signal
= GDB_SIGNAL_0
;
4912 static int last_sent_step
;
4915 remote_resume (struct target_ops
*ops
,
4916 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4918 struct remote_state
*rs
= get_remote_state ();
4921 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4922 (explained in remote-notif.c:handle_notification) so
4923 remote_notif_process is not called. We need find a place where
4924 it is safe to start a 'vNotif' sequence. It is good to do it
4925 before resuming inferior, because inferior was stopped and no RSP
4926 traffic at that moment. */
4928 remote_notif_process (¬if_client_stop
);
4930 last_sent_signal
= siggnal
;
4931 last_sent_step
= step
;
4933 /* The vCont packet doesn't need to specify threads via Hc. */
4934 /* No reverse support (yet) for vCont. */
4935 if (execution_direction
!= EXEC_REVERSE
)
4936 if (remote_vcont_resume (ptid
, step
, siggnal
))
4939 /* All other supported resume packets do use Hc, so set the continue
4941 if (ptid_equal (ptid
, minus_one_ptid
))
4942 set_continue_thread (any_thread_ptid
);
4944 set_continue_thread (ptid
);
4947 if (execution_direction
== EXEC_REVERSE
)
4949 /* We don't pass signals to the target in reverse exec mode. */
4950 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4951 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4955 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4956 error (_("Remote reverse-step not supported."));
4958 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4959 error (_("Remote reverse-continue not supported."));
4961 strcpy (buf
, step
? "bs" : "bc");
4963 else if (siggnal
!= GDB_SIGNAL_0
)
4965 buf
[0] = step
? 'S' : 'C';
4966 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4967 buf
[2] = tohex (((int) siggnal
) & 0xf);
4971 strcpy (buf
, step
? "s" : "c");
4976 /* We are about to start executing the inferior, let's register it
4977 with the event loop. NOTE: this is the one place where all the
4978 execution commands end up. We could alternatively do this in each
4979 of the execution commands in infcmd.c. */
4980 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4981 into infcmd.c in order to allow inferior function calls to work
4982 NOT asynchronously. */
4983 if (target_can_async_p ())
4984 target_async (inferior_event_handler
, 0);
4986 /* We've just told the target to resume. The remote server will
4987 wait for the inferior to stop, and then send a stop reply. In
4988 the mean time, we can't start another command/query ourselves
4989 because the stub wouldn't be ready to process it. This applies
4990 only to the base all-stop protocol, however. In non-stop (which
4991 only supports vCont), the stub replies with an "OK", and is
4992 immediate able to process further serial input. */
4994 rs
->waiting_for_stop_reply
= 1;
4998 /* Set up the signal handler for SIGINT, while the target is
4999 executing, ovewriting the 'regular' SIGINT signal handler. */
5001 async_initialize_sigint_signal_handler (void)
5003 signal (SIGINT
, async_handle_remote_sigint
);
5006 /* Signal handler for SIGINT, while the target is executing. */
5008 async_handle_remote_sigint (int sig
)
5010 signal (sig
, async_handle_remote_sigint_twice
);
5011 mark_async_signal_handler (async_sigint_remote_token
);
5014 /* Signal handler for SIGINT, installed after SIGINT has already been
5015 sent once. It will take effect the second time that the user sends
5018 async_handle_remote_sigint_twice (int sig
)
5020 signal (sig
, async_handle_remote_sigint
);
5021 mark_async_signal_handler (async_sigint_remote_twice_token
);
5024 /* Perform the real interruption of the target execution, in response
5027 async_remote_interrupt (gdb_client_data arg
)
5030 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5032 target_stop (inferior_ptid
);
5035 /* Perform interrupt, if the first attempt did not succeed. Just give
5036 up on the target alltogether. */
5038 async_remote_interrupt_twice (gdb_client_data arg
)
5041 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5046 /* Reinstall the usual SIGINT handlers, after the target has
5049 async_cleanup_sigint_signal_handler (void *dummy
)
5051 signal (SIGINT
, handle_sigint
);
5054 /* Send ^C to target to halt it. Target will respond, and send us a
5056 static void (*ofunc
) (int);
5058 /* The command line interface's stop routine. This function is installed
5059 as a signal handler for SIGINT. The first time a user requests a
5060 stop, we call remote_stop to send a break or ^C. If there is no
5061 response from the target (it didn't stop when the user requested it),
5062 we ask the user if he'd like to detach from the target. */
5064 sync_remote_interrupt (int signo
)
5066 /* If this doesn't work, try more severe steps. */
5067 signal (signo
, sync_remote_interrupt_twice
);
5069 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5072 /* The user typed ^C twice. */
5075 sync_remote_interrupt_twice (int signo
)
5077 signal (signo
, ofunc
);
5078 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5079 signal (signo
, sync_remote_interrupt
);
5082 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5083 thread, all threads of a remote process, or all threads of all
5087 remote_stop_ns (ptid_t ptid
)
5089 struct remote_state
*rs
= get_remote_state ();
5091 char *endp
= rs
->buf
+ get_remote_packet_size ();
5093 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
5094 remote_vcont_probe (rs
);
5096 if (!rs
->supports_vCont
.t
)
5097 error (_("Remote server does not support stopping threads"));
5099 if (ptid_equal (ptid
, minus_one_ptid
)
5100 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5101 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5106 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5108 if (ptid_is_pid (ptid
))
5109 /* All (-1) threads of process. */
5110 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
5113 /* Small optimization: if we already have a stop reply for
5114 this thread, no use in telling the stub we want this
5116 if (peek_stop_reply (ptid
))
5122 write_ptid (p
, endp
, nptid
);
5125 /* In non-stop, we get an immediate OK reply. The stop reply will
5126 come in asynchronously by notification. */
5128 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5129 if (strcmp (rs
->buf
, "OK") != 0)
5130 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5133 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5134 remote target. It is undefined which thread of which process
5135 reports the stop. */
5138 remote_stop_as (ptid_t ptid
)
5140 struct remote_state
*rs
= get_remote_state ();
5142 rs
->ctrlc_pending_p
= 1;
5144 /* If the inferior is stopped already, but the core didn't know
5145 about it yet, just ignore the request. The cached wait status
5146 will be collected in remote_wait. */
5147 if (rs
->cached_wait_status
)
5150 /* Send interrupt_sequence to remote target. */
5151 send_interrupt_sequence ();
5154 /* This is the generic stop called via the target vector. When a target
5155 interrupt is requested, either by the command line or the GUI, we
5156 will eventually end up here. */
5159 remote_stop (ptid_t ptid
)
5162 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5165 remote_stop_ns (ptid
);
5167 remote_stop_as (ptid
);
5170 /* Ask the user what to do when an interrupt is received. */
5173 interrupt_query (void)
5175 target_terminal_ours ();
5177 if (target_can_async_p ())
5179 signal (SIGINT
, handle_sigint
);
5184 if (query (_("Interrupted while waiting for the program.\n\
5185 Give up (and stop debugging it)? ")))
5187 remote_unpush_target ();
5192 target_terminal_inferior ();
5195 /* Enable/disable target terminal ownership. Most targets can use
5196 terminal groups to control terminal ownership. Remote targets are
5197 different in that explicit transfer of ownership to/from GDB/target
5201 remote_terminal_inferior (void)
5203 if (!target_async_permitted
)
5204 /* Nothing to do. */
5207 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5208 idempotent. The event-loop GDB talking to an asynchronous target
5209 with a synchronous command calls this function from both
5210 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5211 transfer the terminal to the target when it shouldn't this guard
5213 if (!remote_async_terminal_ours_p
)
5215 delete_file_handler (input_fd
);
5216 remote_async_terminal_ours_p
= 0;
5217 async_initialize_sigint_signal_handler ();
5218 /* NOTE: At this point we could also register our selves as the
5219 recipient of all input. Any characters typed could then be
5220 passed on down to the target. */
5224 remote_terminal_ours (void)
5226 if (!target_async_permitted
)
5227 /* Nothing to do. */
5230 /* See FIXME in remote_terminal_inferior. */
5231 if (remote_async_terminal_ours_p
)
5233 async_cleanup_sigint_signal_handler (NULL
);
5234 add_file_handler (input_fd
, stdin_event_handler
, 0);
5235 remote_async_terminal_ours_p
= 1;
5239 remote_console_output (char *msg
)
5243 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5246 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5250 fputs_unfiltered (tb
, gdb_stdtarg
);
5252 gdb_flush (gdb_stdtarg
);
5255 typedef struct cached_reg
5258 gdb_byte data
[MAX_REGISTER_SIZE
];
5261 DEF_VEC_O(cached_reg_t
);
5263 typedef struct stop_reply
5265 struct notif_event base
;
5267 /* The identifier of the thread about this event */
5270 struct target_waitstatus ws
;
5272 /* Expedited registers. This makes remote debugging a bit more
5273 efficient for those targets that provide critical registers as
5274 part of their normal status mechanism (as another roundtrip to
5275 fetch them is avoided). */
5276 VEC(cached_reg_t
) *regcache
;
5278 int stopped_by_watchpoint_p
;
5279 CORE_ADDR watch_data_address
;
5287 DECLARE_QUEUE_P (stop_reply_p
);
5288 DEFINE_QUEUE_P (stop_reply_p
);
5289 /* The list of already fetched and acknowledged stop events. This
5290 queue is used for notification Stop, and other notifications
5291 don't need queue for their events, because the notification events
5292 of Stop can't be consumed immediately, so that events should be
5293 queued first, and be consumed by remote_wait_{ns,as} one per
5294 time. Other notifications can consume their events immediately,
5295 so queue is not needed for them. */
5296 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5299 stop_reply_xfree (struct stop_reply
*r
)
5303 VEC_free (cached_reg_t
, r
->regcache
);
5309 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5310 struct notif_event
*event
)
5312 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5316 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5317 struct notif_event
*event
)
5319 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5322 putpkt ((char *) self
->ack_command
);
5324 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5325 /* We got an unknown stop reply. */
5326 error (_("Unknown stop reply"));
5328 push_stop_reply (stop_reply
);
5332 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5334 /* We can't get pending events in remote_notif_process for
5335 notification stop, and we have to do this in remote_wait_ns
5336 instead. If we fetch all queued events from stub, remote stub
5337 may exit and we have no chance to process them back in
5339 mark_async_event_handler (remote_async_inferior_event_token
);
5344 stop_reply_dtr (struct notif_event
*event
)
5346 struct stop_reply
*r
= (struct stop_reply
*) event
;
5348 VEC_free (cached_reg_t
, r
->regcache
);
5351 static struct notif_event
*
5352 remote_notif_stop_alloc_reply (void)
5354 struct notif_event
*r
5355 = (struct notif_event
*) XMALLOC (struct stop_reply
);
5357 r
->dtr
= stop_reply_dtr
;
5362 /* A client of notification Stop. */
5364 struct notif_client notif_client_stop
=
5368 remote_notif_stop_parse
,
5369 remote_notif_stop_ack
,
5370 remote_notif_stop_can_get_pending_events
,
5371 remote_notif_stop_alloc_reply
,
5375 /* A parameter to pass data in and out. */
5377 struct queue_iter_param
5380 struct stop_reply
*output
;
5383 /* Remove all queue elements meet the condition it checks. */
5386 remote_notif_remove_all (QUEUE (stop_reply_p
) *q
,
5387 QUEUE_ITER (stop_reply_p
) *iter
,
5391 struct queue_iter_param
*param
= data
;
5392 struct inferior
*inf
= param
->input
;
5394 if (inf
== NULL
|| ptid_get_pid (event
->ptid
) == inf
->pid
)
5396 stop_reply_xfree (event
);
5397 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5403 /* Discard all pending stop replies of inferior INF. If INF is NULL,
5404 discard everything. */
5407 discard_pending_stop_replies (struct inferior
*inf
)
5410 struct queue_iter_param param
;
5411 struct stop_reply
*reply
5412 = (struct stop_reply
*) notif_client_stop
.pending_event
;
5414 /* Discard the in-flight notification. */
5417 || ptid_get_pid (reply
->ptid
) == inf
->pid
))
5419 stop_reply_xfree (reply
);
5420 notif_client_stop
.pending_event
= NULL
;
5424 param
.output
= NULL
;
5425 /* Discard the stop replies we have already pulled with
5427 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5428 remote_notif_remove_all
, ¶m
);
5431 /* A parameter to pass data in and out. */
5434 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5435 QUEUE_ITER (stop_reply_p
) *iter
,
5439 struct queue_iter_param
*param
= data
;
5440 ptid_t
*ptid
= param
->input
;
5442 if (ptid_match (event
->ptid
, *ptid
))
5444 param
->output
= event
;
5445 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5452 /* Remove the first reply in 'stop_reply_queue' which matches
5455 static struct stop_reply
*
5456 remote_notif_remove_queued_reply (ptid_t ptid
)
5458 struct queue_iter_param param
;
5460 param
.input
= &ptid
;
5461 param
.output
= NULL
;
5463 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5464 remote_notif_remove_once_on_match
, ¶m
);
5466 fprintf_unfiltered (gdb_stdlog
,
5467 "notif: discard queued event: 'Stop' in %s\n",
5468 target_pid_to_str (ptid
));
5470 return param
.output
;
5473 /* Look for a queued stop reply belonging to PTID. If one is found,
5474 remove it from the queue, and return it. Returns NULL if none is
5475 found. If there are still queued events left to process, tell the
5476 event loop to get back to target_wait soon. */
5478 static struct stop_reply
*
5479 queued_stop_reply (ptid_t ptid
)
5481 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5483 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5484 /* There's still at least an event left. */
5485 mark_async_event_handler (remote_async_inferior_event_token
);
5490 /* Push a fully parsed stop reply in the stop reply queue. Since we
5491 know that we now have at least one queued event left to pass to the
5492 core side, tell the event loop to get back to target_wait soon. */
5495 push_stop_reply (struct stop_reply
*new_event
)
5497 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5500 fprintf_unfiltered (gdb_stdlog
,
5501 "notif: push 'Stop' %s to queue %d\n",
5502 target_pid_to_str (new_event
->ptid
),
5503 QUEUE_length (stop_reply_p
,
5506 mark_async_event_handler (remote_async_inferior_event_token
);
5510 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5511 QUEUE_ITER (stop_reply_p
) *iter
,
5512 struct stop_reply
*event
,
5515 ptid_t
*ptid
= data
;
5517 return !(ptid_equal (*ptid
, event
->ptid
)
5518 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5521 /* Returns true if we have a stop reply for PTID. */
5524 peek_stop_reply (ptid_t ptid
)
5526 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5527 stop_reply_match_ptid_and_ws
, &ptid
);
5530 /* Parse the stop reply in BUF. Either the function succeeds, and the
5531 result is stored in EVENT, or throws an error. */
5534 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5536 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5540 event
->ptid
= null_ptid
;
5541 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5542 event
->ws
.value
.integer
= 0;
5543 event
->solibs_changed
= 0;
5544 event
->replay_event
= 0;
5545 event
->stopped_by_watchpoint_p
= 0;
5546 event
->regcache
= NULL
;
5551 case 'T': /* Status with PC, SP, FP, ... */
5552 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5553 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5555 n... = register number
5556 r... = register contents
5559 p
= &buf
[3]; /* after Txx */
5567 /* If the packet contains a register number, save it in
5568 pnum and set p1 to point to the character following it.
5569 Otherwise p1 points to p. */
5571 /* If this packet is an awatch packet, don't parse the 'a'
5572 as a register number. */
5574 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5575 && strncmp (p
, "core", strlen ("core") != 0))
5577 /* Read the ``P'' register number. */
5578 pnum
= strtol (p
, &p_temp
, 16);
5584 if (p1
== p
) /* No register number present here. */
5586 p1
= strchr (p
, ':');
5588 error (_("Malformed packet(a) (missing colon): %s\n\
5591 if (strncmp (p
, "thread", p1
- p
) == 0)
5592 event
->ptid
= read_ptid (++p1
, &p
);
5593 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5594 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5595 || (strncmp (p
, "awatch", p1
- p
) == 0))
5597 event
->stopped_by_watchpoint_p
= 1;
5598 p
= unpack_varlen_hex (++p1
, &addr
);
5599 event
->watch_data_address
= (CORE_ADDR
) addr
;
5601 else if (strncmp (p
, "library", p1
- p
) == 0)
5605 while (*p_temp
&& *p_temp
!= ';')
5608 event
->solibs_changed
= 1;
5611 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5613 /* NO_HISTORY event.
5614 p1 will indicate "begin" or "end", but
5615 it makes no difference for now, so ignore it. */
5616 event
->replay_event
= 1;
5617 p_temp
= strchr (p1
+ 1, ';');
5621 else if (strncmp (p
, "core", p1
- p
) == 0)
5625 p
= unpack_varlen_hex (++p1
, &c
);
5630 /* Silently skip unknown optional info. */
5631 p_temp
= strchr (p1
+ 1, ';');
5638 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5639 cached_reg_t cached_reg
;
5644 error (_("Malformed packet(b) (missing colon): %s\n\
5650 error (_("Remote sent bad register number %s: %s\n\
5652 hex_string (pnum
), p
, buf
);
5654 cached_reg
.num
= reg
->regnum
;
5656 fieldsize
= hex2bin (p
, cached_reg
.data
,
5657 register_size (target_gdbarch (),
5660 if (fieldsize
< register_size (target_gdbarch (),
5662 warning (_("Remote reply is too short: %s"), buf
);
5664 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5668 error (_("Remote register badly formatted: %s\nhere: %s"),
5673 case 'S': /* Old style status, just signal only. */
5674 if (event
->solibs_changed
)
5675 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5676 else if (event
->replay_event
)
5677 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5680 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5681 event
->ws
.value
.sig
= (enum gdb_signal
)
5682 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5685 case 'W': /* Target exited. */
5692 /* GDB used to accept only 2 hex chars here. Stubs should
5693 only send more if they detect GDB supports multi-process
5695 p
= unpack_varlen_hex (&buf
[1], &value
);
5699 /* The remote process exited. */
5700 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5701 event
->ws
.value
.integer
= value
;
5705 /* The remote process exited with a signal. */
5706 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5707 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5710 /* If no process is specified, assume inferior_ptid. */
5711 pid
= ptid_get_pid (inferior_ptid
);
5720 else if (strncmp (p
,
5721 "process:", sizeof ("process:") - 1) == 0)
5725 p
+= sizeof ("process:") - 1;
5726 unpack_varlen_hex (p
, &upid
);
5730 error (_("unknown stop reply packet: %s"), buf
);
5733 error (_("unknown stop reply packet: %s"), buf
);
5734 event
->ptid
= pid_to_ptid (pid
);
5739 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5740 error (_("No process or thread specified in stop reply: %s"), buf
);
5743 /* When the stub wants to tell GDB about a new notification reply, it
5744 sends a notification (%Stop, for example). Those can come it at
5745 any time, hence, we have to make sure that any pending
5746 putpkt/getpkt sequence we're making is finished, before querying
5747 the stub for more events with the corresponding ack command
5748 (vStopped, for example). E.g., if we started a vStopped sequence
5749 immediately upon receiving the notification, something like this
5757 1.6) <-- (registers reply to step #1.3)
5759 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5762 To solve this, whenever we parse a %Stop notification successfully,
5763 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5764 doing whatever we were doing:
5770 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5771 2.5) <-- (registers reply to step #2.3)
5773 Eventualy after step #2.5, we return to the event loop, which
5774 notices there's an event on the
5775 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5776 associated callback --- the function below. At this point, we're
5777 always safe to start a vStopped sequence. :
5780 2.7) <-- T05 thread:2
5786 remote_notif_get_pending_events (struct notif_client
*nc
)
5788 struct remote_state
*rs
= get_remote_state ();
5790 if (nc
->pending_event
)
5793 fprintf_unfiltered (gdb_stdlog
,
5794 "notif: process: '%s' ack pending event\n",
5798 nc
->ack (nc
, rs
->buf
, nc
->pending_event
);
5799 nc
->pending_event
= NULL
;
5803 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5804 if (strcmp (rs
->buf
, "OK") == 0)
5807 remote_notif_ack (nc
, rs
->buf
);
5813 fprintf_unfiltered (gdb_stdlog
,
5814 "notif: process: '%s' no pending reply\n",
5819 /* Called when it is decided that STOP_REPLY holds the info of the
5820 event that is to be returned to the core. This function always
5821 destroys STOP_REPLY. */
5824 process_stop_reply (struct stop_reply
*stop_reply
,
5825 struct target_waitstatus
*status
)
5829 *status
= stop_reply
->ws
;
5830 ptid
= stop_reply
->ptid
;
5832 /* If no thread/process was reported by the stub, assume the current
5834 if (ptid_equal (ptid
, null_ptid
))
5835 ptid
= inferior_ptid
;
5837 if (status
->kind
!= TARGET_WAITKIND_EXITED
5838 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5840 /* Expedited registers. */
5841 if (stop_reply
->regcache
)
5843 struct regcache
*regcache
5844 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5849 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5851 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5852 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5855 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5856 remote_watch_data_address
= stop_reply
->watch_data_address
;
5858 remote_notice_new_inferior (ptid
, 0);
5859 demand_private_info (ptid
)->core
= stop_reply
->core
;
5862 stop_reply_xfree (stop_reply
);
5866 /* The non-stop mode version of target_wait. */
5869 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5871 struct remote_state
*rs
= get_remote_state ();
5872 struct stop_reply
*stop_reply
;
5876 /* If in non-stop mode, get out of getpkt even if a
5877 notification is received. */
5879 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5880 0 /* forever */, &is_notif
);
5883 if (ret
!= -1 && !is_notif
)
5886 case 'E': /* Error of some sort. */
5887 /* We're out of sync with the target now. Did it continue
5888 or not? We can't tell which thread it was in non-stop,
5889 so just ignore this. */
5890 warning (_("Remote failure reply: %s"), rs
->buf
);
5892 case 'O': /* Console output. */
5893 remote_console_output (rs
->buf
+ 1);
5896 warning (_("Invalid remote reply: %s"), rs
->buf
);
5900 /* Acknowledge a pending stop reply that may have arrived in the
5902 if (notif_client_stop
.pending_event
!= NULL
)
5903 remote_notif_get_pending_events (¬if_client_stop
);
5905 /* If indeed we noticed a stop reply, we're done. */
5906 stop_reply
= queued_stop_reply (ptid
);
5907 if (stop_reply
!= NULL
)
5908 return process_stop_reply (stop_reply
, status
);
5910 /* Still no event. If we're just polling for an event, then
5911 return to the event loop. */
5912 if (options
& TARGET_WNOHANG
)
5914 status
->kind
= TARGET_WAITKIND_IGNORE
;
5915 return minus_one_ptid
;
5918 /* Otherwise do a blocking wait. */
5919 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5920 1 /* forever */, &is_notif
);
5924 /* Wait until the remote machine stops, then return, storing status in
5925 STATUS just as `wait' would. */
5928 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5930 struct remote_state
*rs
= get_remote_state ();
5931 ptid_t event_ptid
= null_ptid
;
5933 struct stop_reply
*stop_reply
;
5937 status
->kind
= TARGET_WAITKIND_IGNORE
;
5938 status
->value
.integer
= 0;
5940 stop_reply
= queued_stop_reply (ptid
);
5941 if (stop_reply
!= NULL
)
5942 return process_stop_reply (stop_reply
, status
);
5944 if (rs
->cached_wait_status
)
5945 /* Use the cached wait status, but only once. */
5946 rs
->cached_wait_status
= 0;
5952 if (!target_is_async_p ())
5954 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
5955 /* If the user hit C-c before this packet, or between packets,
5956 pretend that it was hit right here. */
5957 if (check_quit_flag ())
5960 sync_remote_interrupt (SIGINT
);
5964 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5965 _never_ wait for ever -> test on target_is_async_p().
5966 However, before we do that we need to ensure that the caller
5967 knows how to take the target into/out of async mode. */
5968 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5969 wait_forever_enabled_p
, &is_notif
);
5971 if (!target_is_async_p ())
5972 signal (SIGINT
, ofunc
);
5974 /* GDB gets a notification. Return to core as this event is
5976 if (ret
!= -1 && is_notif
)
5977 return minus_one_ptid
;
5982 remote_stopped_by_watchpoint_p
= 0;
5984 /* We got something. */
5985 rs
->waiting_for_stop_reply
= 0;
5987 /* Assume that the target has acknowledged Ctrl-C unless we receive
5988 an 'F' or 'O' packet. */
5989 if (buf
[0] != 'F' && buf
[0] != 'O')
5990 rs
->ctrlc_pending_p
= 0;
5994 case 'E': /* Error of some sort. */
5995 /* We're out of sync with the target now. Did it continue or
5996 not? Not is more likely, so report a stop. */
5997 warning (_("Remote failure reply: %s"), buf
);
5998 status
->kind
= TARGET_WAITKIND_STOPPED
;
5999 status
->value
.sig
= GDB_SIGNAL_0
;
6001 case 'F': /* File-I/O request. */
6002 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6003 rs
->ctrlc_pending_p
= 0;
6005 case 'T': case 'S': case 'X': case 'W':
6007 struct stop_reply
*stop_reply
6008 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6011 event_ptid
= process_stop_reply (stop_reply
, status
);
6014 case 'O': /* Console output. */
6015 remote_console_output (buf
+ 1);
6017 /* The target didn't really stop; keep waiting. */
6018 rs
->waiting_for_stop_reply
= 1;
6022 if (last_sent_signal
!= GDB_SIGNAL_0
)
6024 /* Zero length reply means that we tried 'S' or 'C' and the
6025 remote system doesn't support it. */
6026 target_terminal_ours_for_output ();
6028 ("Can't send signals to this remote system. %s not sent.\n",
6029 gdb_signal_to_name (last_sent_signal
));
6030 last_sent_signal
= GDB_SIGNAL_0
;
6031 target_terminal_inferior ();
6033 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
6034 putpkt ((char *) buf
);
6036 /* We just told the target to resume, so a stop reply is in
6038 rs
->waiting_for_stop_reply
= 1;
6041 /* else fallthrough */
6043 warning (_("Invalid remote reply: %s"), buf
);
6045 rs
->waiting_for_stop_reply
= 1;
6049 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6051 /* Nothing interesting happened. If we're doing a non-blocking
6052 poll, we're done. Otherwise, go back to waiting. */
6053 if (options
& TARGET_WNOHANG
)
6054 return minus_one_ptid
;
6058 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6059 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6061 if (!ptid_equal (event_ptid
, null_ptid
))
6062 record_currthread (rs
, event_ptid
);
6064 event_ptid
= inferior_ptid
;
6067 /* A process exit. Invalidate our notion of current thread. */
6068 record_currthread (rs
, minus_one_ptid
);
6073 /* Wait until the remote machine stops, then return, storing status in
6074 STATUS just as `wait' would. */
6077 remote_wait (struct target_ops
*ops
,
6078 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6083 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6085 event_ptid
= remote_wait_as (ptid
, status
, options
);
6087 if (target_can_async_p ())
6089 /* If there are are events left in the queue tell the event loop
6091 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6092 mark_async_event_handler (remote_async_inferior_event_token
);
6098 /* Fetch a single register using a 'p' packet. */
6101 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6103 struct remote_state
*rs
= get_remote_state ();
6105 char regp
[MAX_REGISTER_SIZE
];
6108 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
6111 if (reg
->pnum
== -1)
6116 p
+= hexnumstr (p
, reg
->pnum
);
6119 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6123 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6127 case PACKET_UNKNOWN
:
6130 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6131 gdbarch_register_name (get_regcache_arch (regcache
),
6136 /* If this register is unfetchable, tell the regcache. */
6139 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6143 /* Otherwise, parse and supply the value. */
6149 error (_("fetch_register_using_p: early buf termination"));
6151 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6154 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6158 /* Fetch the registers included in the target's 'g' packet. */
6161 send_g_packet (void)
6163 struct remote_state
*rs
= get_remote_state ();
6166 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6167 remote_send (&rs
->buf
, &rs
->buf_size
);
6169 /* We can get out of synch in various cases. If the first character
6170 in the buffer is not a hex character, assume that has happened
6171 and try to fetch another packet to read. */
6172 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6173 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6174 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6175 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6178 fprintf_unfiltered (gdb_stdlog
,
6179 "Bad register packet; fetching a new packet\n");
6180 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6183 buf_len
= strlen (rs
->buf
);
6185 /* Sanity check the received packet. */
6186 if (buf_len
% 2 != 0)
6187 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6193 process_g_packet (struct regcache
*regcache
)
6195 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6196 struct remote_state
*rs
= get_remote_state ();
6197 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6202 buf_len
= strlen (rs
->buf
);
6204 /* Further sanity checks, with knowledge of the architecture. */
6205 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6206 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6208 /* Save the size of the packet sent to us by the target. It is used
6209 as a heuristic when determining the max size of packets that the
6210 target can safely receive. */
6211 if (rsa
->actual_register_packet_size
== 0)
6212 rsa
->actual_register_packet_size
= buf_len
;
6214 /* If this is smaller than we guessed the 'g' packet would be,
6215 update our records. A 'g' reply that doesn't include a register's
6216 value implies either that the register is not available, or that
6217 the 'p' packet must be used. */
6218 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6220 rsa
->sizeof_g_packet
= buf_len
/ 2;
6222 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6224 if (rsa
->regs
[i
].pnum
== -1)
6227 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6228 rsa
->regs
[i
].in_g_packet
= 0;
6230 rsa
->regs
[i
].in_g_packet
= 1;
6234 regs
= alloca (rsa
->sizeof_g_packet
);
6236 /* Unimplemented registers read as all bits zero. */
6237 memset (regs
, 0, rsa
->sizeof_g_packet
);
6239 /* Reply describes registers byte by byte, each byte encoded as two
6240 hex characters. Suck them all up, then supply them to the
6241 register cacheing/storage mechanism. */
6244 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6246 if (p
[0] == 0 || p
[1] == 0)
6247 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6248 internal_error (__FILE__
, __LINE__
,
6249 _("unexpected end of 'g' packet reply"));
6251 if (p
[0] == 'x' && p
[1] == 'x')
6252 regs
[i
] = 0; /* 'x' */
6254 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6258 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6260 struct packet_reg
*r
= &rsa
->regs
[i
];
6264 if (r
->offset
* 2 >= strlen (rs
->buf
))
6265 /* This shouldn't happen - we adjusted in_g_packet above. */
6266 internal_error (__FILE__
, __LINE__
,
6267 _("unexpected end of 'g' packet reply"));
6268 else if (rs
->buf
[r
->offset
* 2] == 'x')
6270 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6271 /* The register isn't available, mark it as such (at
6272 the same time setting the value to zero). */
6273 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6276 regcache_raw_supply (regcache
, r
->regnum
,
6283 fetch_registers_using_g (struct regcache
*regcache
)
6286 process_g_packet (regcache
);
6289 /* Make the remote selected traceframe match GDB's selected
6293 set_remote_traceframe (void)
6296 struct remote_state
*rs
= get_remote_state ();
6298 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6301 /* Avoid recursion, remote_trace_find calls us again. */
6302 rs
->remote_traceframe_number
= get_traceframe_number ();
6304 newnum
= target_trace_find (tfind_number
,
6305 get_traceframe_number (), 0, 0, NULL
);
6307 /* Should not happen. If it does, all bets are off. */
6308 if (newnum
!= get_traceframe_number ())
6309 warning (_("could not set remote traceframe"));
6313 remote_fetch_registers (struct target_ops
*ops
,
6314 struct regcache
*regcache
, int regnum
)
6316 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6319 set_remote_traceframe ();
6320 set_general_thread (inferior_ptid
);
6324 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6326 gdb_assert (reg
!= NULL
);
6328 /* If this register might be in the 'g' packet, try that first -
6329 we are likely to read more than one register. If this is the
6330 first 'g' packet, we might be overly optimistic about its
6331 contents, so fall back to 'p'. */
6332 if (reg
->in_g_packet
)
6334 fetch_registers_using_g (regcache
);
6335 if (reg
->in_g_packet
)
6339 if (fetch_register_using_p (regcache
, reg
))
6342 /* This register is not available. */
6343 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6348 fetch_registers_using_g (regcache
);
6350 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6351 if (!rsa
->regs
[i
].in_g_packet
)
6352 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6354 /* This register is not available. */
6355 regcache_raw_supply (regcache
, i
, NULL
);
6359 /* Prepare to store registers. Since we may send them all (using a
6360 'G' request), we have to read out the ones we don't want to change
6364 remote_prepare_to_store (struct regcache
*regcache
)
6366 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6368 gdb_byte buf
[MAX_REGISTER_SIZE
];
6370 /* Make sure the entire registers array is valid. */
6371 switch (remote_protocol_packets
[PACKET_P
].support
)
6373 case PACKET_DISABLE
:
6374 case PACKET_SUPPORT_UNKNOWN
:
6375 /* Make sure all the necessary registers are cached. */
6376 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6377 if (rsa
->regs
[i
].in_g_packet
)
6378 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6385 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6386 packet was not recognized. */
6389 store_register_using_P (const struct regcache
*regcache
,
6390 struct packet_reg
*reg
)
6392 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6393 struct remote_state
*rs
= get_remote_state ();
6394 /* Try storing a single register. */
6395 char *buf
= rs
->buf
;
6396 gdb_byte regp
[MAX_REGISTER_SIZE
];
6399 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
6402 if (reg
->pnum
== -1)
6405 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6406 p
= buf
+ strlen (buf
);
6407 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6408 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6410 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6412 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6417 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6418 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6419 case PACKET_UNKNOWN
:
6422 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6426 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6427 contents of the register cache buffer. FIXME: ignores errors. */
6430 store_registers_using_G (const struct regcache
*regcache
)
6432 struct remote_state
*rs
= get_remote_state ();
6433 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6437 /* Extract all the registers in the regcache copying them into a
6442 regs
= alloca (rsa
->sizeof_g_packet
);
6443 memset (regs
, 0, rsa
->sizeof_g_packet
);
6444 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6446 struct packet_reg
*r
= &rsa
->regs
[i
];
6449 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6453 /* Command describes registers byte by byte,
6454 each byte encoded as two hex characters. */
6457 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6459 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6461 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6462 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6463 error (_("Could not write registers; remote failure reply '%s'"),
6467 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6468 of the register cache buffer. FIXME: ignores errors. */
6471 remote_store_registers (struct target_ops
*ops
,
6472 struct regcache
*regcache
, int regnum
)
6474 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6477 set_remote_traceframe ();
6478 set_general_thread (inferior_ptid
);
6482 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6484 gdb_assert (reg
!= NULL
);
6486 /* Always prefer to store registers using the 'P' packet if
6487 possible; we often change only a small number of registers.
6488 Sometimes we change a larger number; we'd need help from a
6489 higher layer to know to use 'G'. */
6490 if (store_register_using_P (regcache
, reg
))
6493 /* For now, don't complain if we have no way to write the
6494 register. GDB loses track of unavailable registers too
6495 easily. Some day, this may be an error. We don't have
6496 any way to read the register, either... */
6497 if (!reg
->in_g_packet
)
6500 store_registers_using_G (regcache
);
6504 store_registers_using_G (regcache
);
6506 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6507 if (!rsa
->regs
[i
].in_g_packet
)
6508 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6509 /* See above for why we do not issue an error here. */
6514 /* Return the number of hex digits in num. */
6517 hexnumlen (ULONGEST num
)
6521 for (i
= 0; num
!= 0; i
++)
6527 /* Set BUF to the minimum number of hex digits representing NUM. */
6530 hexnumstr (char *buf
, ULONGEST num
)
6532 int len
= hexnumlen (num
);
6534 return hexnumnstr (buf
, num
, len
);
6538 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6541 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6547 for (i
= width
- 1; i
>= 0; i
--)
6549 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6556 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6559 remote_address_masked (CORE_ADDR addr
)
6561 unsigned int address_size
= remote_address_size
;
6563 /* If "remoteaddresssize" was not set, default to target address size. */
6565 address_size
= gdbarch_addr_bit (target_gdbarch ());
6567 if (address_size
> 0
6568 && address_size
< (sizeof (ULONGEST
) * 8))
6570 /* Only create a mask when that mask can safely be constructed
6571 in a ULONGEST variable. */
6574 mask
= (mask
<< address_size
) - 1;
6580 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6581 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6582 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6583 (which may be more than *OUT_LEN due to escape characters). The
6584 total number of bytes in the output buffer will be at most
6588 remote_escape_output (const gdb_byte
*buffer
, int len
,
6589 gdb_byte
*out_buf
, int *out_len
,
6592 int input_index
, output_index
;
6595 for (input_index
= 0; input_index
< len
; input_index
++)
6597 gdb_byte b
= buffer
[input_index
];
6599 if (b
== '$' || b
== '#' || b
== '}')
6601 /* These must be escaped. */
6602 if (output_index
+ 2 > out_maxlen
)
6604 out_buf
[output_index
++] = '}';
6605 out_buf
[output_index
++] = b
^ 0x20;
6609 if (output_index
+ 1 > out_maxlen
)
6611 out_buf
[output_index
++] = b
;
6615 *out_len
= input_index
;
6616 return output_index
;
6619 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6620 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6621 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6623 This function reverses remote_escape_output. It allows more
6624 escaped characters than that function does, in particular because
6625 '*' must be escaped to avoid the run-length encoding processing
6626 in reading packets. */
6629 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6630 gdb_byte
*out_buf
, int out_maxlen
)
6632 int input_index
, output_index
;
6637 for (input_index
= 0; input_index
< len
; input_index
++)
6639 gdb_byte b
= buffer
[input_index
];
6641 if (output_index
+ 1 > out_maxlen
)
6643 warning (_("Received too much data from remote target;"
6644 " ignoring overflow."));
6645 return output_index
;
6650 out_buf
[output_index
++] = b
^ 0x20;
6656 out_buf
[output_index
++] = b
;
6660 error (_("Unmatched escape character in target response."));
6662 return output_index
;
6665 /* Determine whether the remote target supports binary downloading.
6666 This is accomplished by sending a no-op memory write of zero length
6667 to the target at the specified address. It does not suffice to send
6668 the whole packet, since many stubs strip the eighth bit and
6669 subsequently compute a wrong checksum, which causes real havoc with
6672 NOTE: This can still lose if the serial line is not eight-bit
6673 clean. In cases like this, the user should clear "remote
6677 check_binary_download (CORE_ADDR addr
)
6679 struct remote_state
*rs
= get_remote_state ();
6681 switch (remote_protocol_packets
[PACKET_X
].support
)
6683 case PACKET_DISABLE
:
6687 case PACKET_SUPPORT_UNKNOWN
:
6693 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6695 p
+= hexnumstr (p
, (ULONGEST
) 0);
6699 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6700 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6702 if (rs
->buf
[0] == '\0')
6705 fprintf_unfiltered (gdb_stdlog
,
6706 "binary downloading NOT "
6707 "supported by target\n");
6708 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6713 fprintf_unfiltered (gdb_stdlog
,
6714 "binary downloading supported by target\n");
6715 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6722 /* Write memory data directly to the remote machine.
6723 This does not inform the data cache; the data cache uses this.
6724 HEADER is the starting part of the packet.
6725 MEMADDR is the address in the remote memory space.
6726 MYADDR is the address of the buffer in our space.
6727 LEN is the number of bytes.
6728 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6729 should send data as binary ('X'), or hex-encoded ('M').
6731 The function creates packet of the form
6732 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6734 where encoding of <DATA> is termined by PACKET_FORMAT.
6736 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6739 Returns the number of bytes transferred, or 0 (setting errno) for
6740 error. Only transfer a single packet. */
6743 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6744 const gdb_byte
*myaddr
, ssize_t len
,
6745 char packet_format
, int use_length
)
6747 struct remote_state
*rs
= get_remote_state ();
6757 if (packet_format
!= 'X' && packet_format
!= 'M')
6758 internal_error (__FILE__
, __LINE__
,
6759 _("remote_write_bytes_aux: bad packet format"));
6764 payload_size
= get_memory_write_packet_size ();
6766 /* The packet buffer will be large enough for the payload;
6767 get_memory_packet_size ensures this. */
6770 /* Compute the size of the actual payload by subtracting out the
6771 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6773 payload_size
-= strlen ("$,:#NN");
6775 /* The comma won't be used. */
6777 header_length
= strlen (header
);
6778 payload_size
-= header_length
;
6779 payload_size
-= hexnumlen (memaddr
);
6781 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6783 strcat (rs
->buf
, header
);
6784 p
= rs
->buf
+ strlen (header
);
6786 /* Compute a best guess of the number of bytes actually transfered. */
6787 if (packet_format
== 'X')
6789 /* Best guess at number of bytes that will fit. */
6790 todo
= min (len
, payload_size
);
6792 payload_size
-= hexnumlen (todo
);
6793 todo
= min (todo
, payload_size
);
6797 /* Num bytes that will fit. */
6798 todo
= min (len
, payload_size
/ 2);
6800 payload_size
-= hexnumlen (todo
);
6801 todo
= min (todo
, payload_size
/ 2);
6805 internal_error (__FILE__
, __LINE__
,
6806 _("minimum packet size too small to write data"));
6808 /* If we already need another packet, then try to align the end
6809 of this packet to a useful boundary. */
6810 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6811 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6813 /* Append "<memaddr>". */
6814 memaddr
= remote_address_masked (memaddr
);
6815 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6822 /* Append <len>. Retain the location/size of <len>. It may need to
6823 be adjusted once the packet body has been created. */
6825 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6833 /* Append the packet body. */
6834 if (packet_format
== 'X')
6836 /* Binary mode. Send target system values byte by byte, in
6837 increasing byte addresses. Only escape certain critical
6839 payload_length
= remote_escape_output (myaddr
, todo
, (gdb_byte
*) p
,
6840 &nr_bytes
, payload_size
);
6842 /* If not all TODO bytes fit, then we'll need another packet. Make
6843 a second try to keep the end of the packet aligned. Don't do
6844 this if the packet is tiny. */
6845 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6849 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6851 if (new_nr_bytes
!= nr_bytes
)
6852 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6853 (gdb_byte
*) p
, &nr_bytes
,
6857 p
+= payload_length
;
6858 if (use_length
&& nr_bytes
< todo
)
6860 /* Escape chars have filled up the buffer prematurely,
6861 and we have actually sent fewer bytes than planned.
6862 Fix-up the length field of the packet. Use the same
6863 number of characters as before. */
6864 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6865 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6870 /* Normal mode: Send target system values byte by byte, in
6871 increasing byte addresses. Each byte is encoded as a two hex
6873 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6877 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6878 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6880 if (rs
->buf
[0] == 'E')
6882 /* There is no correspondance between what the remote protocol
6883 uses for errors and errno codes. We would like a cleaner way
6884 of representing errors (big enough to include errno codes,
6885 bfd_error codes, and others). But for now just return EIO. */
6890 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6891 fewer bytes than we'd planned. */
6895 /* Write memory data directly to the remote machine.
6896 This does not inform the data cache; the data cache uses this.
6897 MEMADDR is the address in the remote memory space.
6898 MYADDR is the address of the buffer in our space.
6899 LEN is the number of bytes.
6901 Returns number of bytes transferred, or 0 (setting errno) for
6902 error. Only transfer a single packet. */
6905 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
6907 char *packet_format
= 0;
6909 /* Check whether the target supports binary download. */
6910 check_binary_download (memaddr
);
6912 switch (remote_protocol_packets
[PACKET_X
].support
)
6915 packet_format
= "X";
6917 case PACKET_DISABLE
:
6918 packet_format
= "M";
6920 case PACKET_SUPPORT_UNKNOWN
:
6921 internal_error (__FILE__
, __LINE__
,
6922 _("remote_write_bytes: bad internal state"));
6924 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6927 return remote_write_bytes_aux (packet_format
,
6928 memaddr
, myaddr
, len
, packet_format
[0], 1);
6931 /* Read memory data directly from the remote machine.
6932 This does not use the data cache; the data cache uses this.
6933 MEMADDR is the address in the remote memory space.
6934 MYADDR is the address of the buffer in our space.
6935 LEN is the number of bytes.
6937 Returns number of bytes transferred, or 0 for error. */
6940 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6942 struct remote_state
*rs
= get_remote_state ();
6943 int max_buf_size
; /* Max size of packet output buffer. */
6951 max_buf_size
= get_memory_read_packet_size ();
6952 /* The packet buffer will be large enough for the payload;
6953 get_memory_packet_size ensures this. */
6955 /* Number if bytes that will fit. */
6956 todo
= min (len
, max_buf_size
/ 2);
6958 /* Construct "m"<memaddr>","<len>". */
6959 memaddr
= remote_address_masked (memaddr
);
6962 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6964 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6967 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6968 if (rs
->buf
[0] == 'E'
6969 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6970 && rs
->buf
[3] == '\0')
6972 /* There is no correspondance between what the remote protocol
6973 uses for errors and errno codes. We would like a cleaner way
6974 of representing errors (big enough to include errno codes,
6975 bfd_error codes, and others). But for now just return
6980 /* Reply describes memory byte by byte, each byte encoded as two hex
6983 i
= hex2bin (p
, myaddr
, todo
);
6984 /* Return what we have. Let higher layers handle partial reads. */
6989 /* Read or write LEN bytes from inferior memory at MEMADDR,
6990 transferring to or from debugger address BUFFER. Write to inferior
6991 if SHOULD_WRITE is nonzero. Returns length of data written or
6992 read; 0 for error. TARGET is unused. */
6995 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6996 int should_write
, struct mem_attrib
*attrib
,
6997 struct target_ops
*target
)
7001 set_remote_traceframe ();
7002 set_general_thread (inferior_ptid
);
7005 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
7007 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
7012 /* Sends a packet with content determined by the printf format string
7013 FORMAT and the remaining arguments, then gets the reply. Returns
7014 whether the packet was a success, a failure, or unknown. */
7016 static enum packet_result
7017 remote_send_printf (const char *format
, ...)
7019 struct remote_state
*rs
= get_remote_state ();
7020 int max_size
= get_remote_packet_size ();
7023 va_start (ap
, format
);
7026 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7027 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7029 if (putpkt (rs
->buf
) < 0)
7030 error (_("Communication problem with target."));
7033 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7035 return packet_check_result (rs
->buf
);
7039 restore_remote_timeout (void *p
)
7041 int value
= *(int *)p
;
7043 remote_timeout
= value
;
7046 /* Flash writing can take quite some time. We'll set
7047 effectively infinite timeout for flash operations.
7048 In future, we'll need to decide on a better approach. */
7049 static const int remote_flash_timeout
= 1000;
7052 remote_flash_erase (struct target_ops
*ops
,
7053 ULONGEST address
, LONGEST length
)
7055 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7056 int saved_remote_timeout
= remote_timeout
;
7057 enum packet_result ret
;
7058 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7059 &saved_remote_timeout
);
7061 remote_timeout
= remote_flash_timeout
;
7063 ret
= remote_send_printf ("vFlashErase:%s,%s",
7064 phex (address
, addr_size
),
7068 case PACKET_UNKNOWN
:
7069 error (_("Remote target does not support flash erase"));
7071 error (_("Error erasing flash with vFlashErase packet"));
7076 do_cleanups (back_to
);
7080 remote_flash_write (struct target_ops
*ops
,
7081 ULONGEST address
, LONGEST length
,
7082 const gdb_byte
*data
)
7084 int saved_remote_timeout
= remote_timeout
;
7086 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7087 &saved_remote_timeout
);
7089 remote_timeout
= remote_flash_timeout
;
7090 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
7091 do_cleanups (back_to
);
7097 remote_flash_done (struct target_ops
*ops
)
7099 int saved_remote_timeout
= remote_timeout
;
7101 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7102 &saved_remote_timeout
);
7104 remote_timeout
= remote_flash_timeout
;
7105 ret
= remote_send_printf ("vFlashDone");
7106 do_cleanups (back_to
);
7110 case PACKET_UNKNOWN
:
7111 error (_("Remote target does not support vFlashDone"));
7113 error (_("Error finishing flash operation"));
7120 remote_files_info (struct target_ops
*ignore
)
7122 puts_filtered ("Debugging a target over a serial line.\n");
7125 /* Stuff for dealing with the packets which are part of this protocol.
7126 See comment at top of file for details. */
7128 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7129 error to higher layers. Called when a serial error is detected.
7130 The exception message is STRING, followed by a colon and a blank,
7131 the system error message for errno at function entry and final dot
7132 for output compatibility with throw_perror_with_name. */
7135 unpush_and_perror (const char *string
)
7137 int saved_errno
= errno
;
7139 remote_unpush_target ();
7140 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7141 safe_strerror (saved_errno
));
7144 /* Read a single character from the remote end. */
7147 readchar (int timeout
)
7150 struct remote_state
*rs
= get_remote_state ();
7152 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7157 switch ((enum serial_rc
) ch
)
7160 remote_unpush_target ();
7161 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7164 unpush_and_perror (_("Remote communication error. "
7165 "Target disconnected."));
7167 case SERIAL_TIMEOUT
:
7173 /* Wrapper for serial_write that closes the target and throws if
7177 remote_serial_write (const char *str
, int len
)
7179 struct remote_state
*rs
= get_remote_state ();
7181 if (serial_write (rs
->remote_desc
, str
, len
))
7183 unpush_and_perror (_("Remote communication error. "
7184 "Target disconnected."));
7188 /* Send the command in *BUF to the remote machine, and read the reply
7189 into *BUF. Report an error if we get an error reply. Resize
7190 *BUF using xrealloc if necessary to hold the result, and update
7194 remote_send (char **buf
,
7198 getpkt (buf
, sizeof_buf
, 0);
7200 if ((*buf
)[0] == 'E')
7201 error (_("Remote failure reply: %s"), *buf
);
7204 /* Return a pointer to an xmalloc'ed string representing an escaped
7205 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7206 etc. The caller is responsible for releasing the returned
7210 escape_buffer (const char *buf
, int n
)
7212 struct cleanup
*old_chain
;
7213 struct ui_file
*stb
;
7216 stb
= mem_fileopen ();
7217 old_chain
= make_cleanup_ui_file_delete (stb
);
7219 fputstrn_unfiltered (buf
, n
, 0, stb
);
7220 str
= ui_file_xstrdup (stb
, NULL
);
7221 do_cleanups (old_chain
);
7225 /* Display a null-terminated packet on stdout, for debugging, using C
7229 print_packet (char *buf
)
7231 puts_filtered ("\"");
7232 fputstr_filtered (buf
, '"', gdb_stdout
);
7233 puts_filtered ("\"");
7239 return putpkt_binary (buf
, strlen (buf
));
7242 /* Send a packet to the remote machine, with error checking. The data
7243 of the packet is in BUF. The string in BUF can be at most
7244 get_remote_packet_size () - 5 to account for the $, # and checksum,
7245 and for a possible /0 if we are debugging (remote_debug) and want
7246 to print the sent packet as a string. */
7249 putpkt_binary (char *buf
, int cnt
)
7251 struct remote_state
*rs
= get_remote_state ();
7253 unsigned char csum
= 0;
7254 char *buf2
= alloca (cnt
+ 6);
7261 /* Catch cases like trying to read memory or listing threads while
7262 we're waiting for a stop reply. The remote server wouldn't be
7263 ready to handle this request, so we'd hang and timeout. We don't
7264 have to worry about this in synchronous mode, because in that
7265 case it's not possible to issue a command while the target is
7266 running. This is not a problem in non-stop mode, because in that
7267 case, the stub is always ready to process serial input. */
7268 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
7269 error (_("Cannot execute this command while the target is running."));
7271 /* We're sending out a new packet. Make sure we don't look at a
7272 stale cached response. */
7273 rs
->cached_wait_status
= 0;
7275 /* Copy the packet into buffer BUF2, encapsulating it
7276 and giving it a checksum. */
7281 for (i
= 0; i
< cnt
; i
++)
7287 *p
++ = tohex ((csum
>> 4) & 0xf);
7288 *p
++ = tohex (csum
& 0xf);
7290 /* Send it over and over until we get a positive ack. */
7294 int started_error_output
= 0;
7298 struct cleanup
*old_chain
;
7302 str
= escape_buffer (buf2
, p
- buf2
);
7303 old_chain
= make_cleanup (xfree
, str
);
7304 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7305 gdb_flush (gdb_stdlog
);
7306 do_cleanups (old_chain
);
7308 remote_serial_write (buf2
, p
- buf2
);
7310 /* If this is a no acks version of the remote protocol, send the
7311 packet and move on. */
7315 /* Read until either a timeout occurs (-2) or '+' is read.
7316 Handle any notification that arrives in the mean time. */
7319 ch
= readchar (remote_timeout
);
7327 case SERIAL_TIMEOUT
:
7330 if (started_error_output
)
7332 putchar_unfiltered ('\n');
7333 started_error_output
= 0;
7342 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7346 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7348 case SERIAL_TIMEOUT
:
7352 break; /* Retransmit buffer. */
7356 fprintf_unfiltered (gdb_stdlog
,
7357 "Packet instead of Ack, ignoring it\n");
7358 /* It's probably an old response sent because an ACK
7359 was lost. Gobble up the packet and ack it so it
7360 doesn't get retransmitted when we resend this
7363 remote_serial_write ("+", 1);
7364 continue; /* Now, go look for +. */
7371 /* If we got a notification, handle it, and go back to looking
7373 /* We've found the start of a notification. Now
7374 collect the data. */
7375 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7380 struct cleanup
*old_chain
;
7383 str
= escape_buffer (rs
->buf
, val
);
7384 old_chain
= make_cleanup (xfree
, str
);
7385 fprintf_unfiltered (gdb_stdlog
,
7386 " Notification received: %s\n",
7388 do_cleanups (old_chain
);
7390 handle_notification (rs
->buf
);
7391 /* We're in sync now, rewait for the ack. */
7398 if (!started_error_output
)
7400 started_error_output
= 1;
7401 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7403 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7404 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7413 if (!started_error_output
)
7415 started_error_output
= 1;
7416 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7418 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7422 break; /* Here to retransmit. */
7426 /* This is wrong. If doing a long backtrace, the user should be
7427 able to get out next time we call QUIT, without anything as
7428 violent as interrupt_query. If we want to provide a way out of
7429 here without getting to the next QUIT, it should be based on
7430 hitting ^C twice as in remote_wait. */
7441 /* Come here after finding the start of a frame when we expected an
7442 ack. Do our best to discard the rest of this packet. */
7451 c
= readchar (remote_timeout
);
7454 case SERIAL_TIMEOUT
:
7455 /* Nothing we can do. */
7458 /* Discard the two bytes of checksum and stop. */
7459 c
= readchar (remote_timeout
);
7461 c
= readchar (remote_timeout
);
7464 case '*': /* Run length encoding. */
7465 /* Discard the repeat count. */
7466 c
= readchar (remote_timeout
);
7471 /* A regular character. */
7477 /* Come here after finding the start of the frame. Collect the rest
7478 into *BUF, verifying the checksum, length, and handling run-length
7479 compression. NUL terminate the buffer. If there is not enough room,
7480 expand *BUF using xrealloc.
7482 Returns -1 on error, number of characters in buffer (ignoring the
7483 trailing NULL) on success. (could be extended to return one of the
7484 SERIAL status indications). */
7487 read_frame (char **buf_p
,
7494 struct remote_state
*rs
= get_remote_state ();
7501 c
= readchar (remote_timeout
);
7504 case SERIAL_TIMEOUT
:
7506 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7510 fputs_filtered ("Saw new packet start in middle of old one\n",
7512 return -1; /* Start a new packet, count retries. */
7515 unsigned char pktcsum
;
7521 check_0
= readchar (remote_timeout
);
7523 check_1
= readchar (remote_timeout
);
7525 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7528 fputs_filtered ("Timeout in checksum, retrying\n",
7532 else if (check_0
< 0 || check_1
< 0)
7535 fputs_filtered ("Communication error in checksum\n",
7540 /* Don't recompute the checksum; with no ack packets we
7541 don't have any way to indicate a packet retransmission
7546 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7547 if (csum
== pktcsum
)
7552 struct cleanup
*old_chain
;
7555 str
= escape_buffer (buf
, bc
);
7556 old_chain
= make_cleanup (xfree
, str
);
7557 fprintf_unfiltered (gdb_stdlog
,
7558 "Bad checksum, sentsum=0x%x, "
7559 "csum=0x%x, buf=%s\n",
7560 pktcsum
, csum
, str
);
7561 do_cleanups (old_chain
);
7563 /* Number of characters in buffer ignoring trailing
7567 case '*': /* Run length encoding. */
7572 c
= readchar (remote_timeout
);
7574 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7576 /* The character before ``*'' is repeated. */
7578 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7580 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7582 /* Make some more room in the buffer. */
7583 *sizeof_buf
+= repeat
;
7584 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7588 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7594 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7598 if (bc
>= *sizeof_buf
- 1)
7600 /* Make some more room in the buffer. */
7602 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7613 /* Read a packet from the remote machine, with error checking, and
7614 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7615 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7616 rather than timing out; this is used (in synchronous mode) to wait
7617 for a target that is is executing user code to stop. */
7618 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7619 don't have to change all the calls to getpkt to deal with the
7620 return value, because at the moment I don't know what the right
7621 thing to do it for those. */
7629 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7633 /* Read a packet from the remote machine, with error checking, and
7634 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7635 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7636 rather than timing out; this is used (in synchronous mode) to wait
7637 for a target that is is executing user code to stop. If FOREVER ==
7638 0, this function is allowed to time out gracefully and return an
7639 indication of this to the caller. Otherwise return the number of
7640 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7641 enough reason to return to the caller. *IS_NOTIF is an output
7642 boolean that indicates whether *BUF holds a notification or not
7643 (a regular packet). */
7646 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7647 int expecting_notif
, int *is_notif
)
7649 struct remote_state
*rs
= get_remote_state ();
7655 /* We're reading a new response. Make sure we don't look at a
7656 previously cached response. */
7657 rs
->cached_wait_status
= 0;
7659 strcpy (*buf
, "timeout");
7662 timeout
= watchdog
> 0 ? watchdog
: -1;
7663 else if (expecting_notif
)
7664 timeout
= 0; /* There should already be a char in the buffer. If
7667 timeout
= remote_timeout
;
7671 /* Process any number of notifications, and then return when
7675 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7677 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7679 /* This can loop forever if the remote side sends us
7680 characters continuously, but if it pauses, we'll get
7681 SERIAL_TIMEOUT from readchar because of timeout. Then
7682 we'll count that as a retry.
7684 Note that even when forever is set, we will only wait
7685 forever prior to the start of a packet. After that, we
7686 expect characters to arrive at a brisk pace. They should
7687 show up within remote_timeout intervals. */
7689 c
= readchar (timeout
);
7690 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7692 if (c
== SERIAL_TIMEOUT
)
7694 if (expecting_notif
)
7695 return -1; /* Don't complain, it's normal to not get
7696 anything in this case. */
7698 if (forever
) /* Watchdog went off? Kill the target. */
7701 remote_unpush_target ();
7702 throw_error (TARGET_CLOSE_ERROR
,
7703 _("Watchdog timeout has expired. "
7704 "Target detached."));
7707 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7711 /* We've found the start of a packet or notification.
7712 Now collect the data. */
7713 val
= read_frame (buf
, sizeof_buf
);
7718 remote_serial_write ("-", 1);
7721 if (tries
> MAX_TRIES
)
7723 /* We have tried hard enough, and just can't receive the
7724 packet/notification. Give up. */
7725 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7727 /* Skip the ack char if we're in no-ack mode. */
7728 if (!rs
->noack_mode
)
7729 remote_serial_write ("+", 1);
7733 /* If we got an ordinary packet, return that to our caller. */
7738 struct cleanup
*old_chain
;
7741 str
= escape_buffer (*buf
, val
);
7742 old_chain
= make_cleanup (xfree
, str
);
7743 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7744 do_cleanups (old_chain
);
7747 /* Skip the ack char if we're in no-ack mode. */
7748 if (!rs
->noack_mode
)
7749 remote_serial_write ("+", 1);
7750 if (is_notif
!= NULL
)
7755 /* If we got a notification, handle it, and go back to looking
7759 gdb_assert (c
== '%');
7763 struct cleanup
*old_chain
;
7766 str
= escape_buffer (*buf
, val
);
7767 old_chain
= make_cleanup (xfree
, str
);
7768 fprintf_unfiltered (gdb_stdlog
,
7769 " Notification received: %s\n",
7771 do_cleanups (old_chain
);
7773 if (is_notif
!= NULL
)
7776 handle_notification (*buf
);
7778 /* Notifications require no acknowledgement. */
7780 if (expecting_notif
)
7787 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7789 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7793 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7796 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7801 /* A helper function that just calls putpkt; for type correctness. */
7804 putpkt_for_catch_errors (void *arg
)
7806 return putpkt (arg
);
7810 remote_kill (struct target_ops
*ops
)
7812 /* Use catch_errors so the user can quit from gdb even when we
7813 aren't on speaking terms with the remote system. */
7814 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7816 /* Don't wait for it to die. I'm not really sure it matters whether
7817 we do or not. For the existing stubs, kill is a noop. */
7818 target_mourn_inferior ();
7822 remote_vkill (int pid
, struct remote_state
*rs
)
7824 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7827 /* Tell the remote target to detach. */
7828 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7830 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7832 if (packet_ok (rs
->buf
,
7833 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7835 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7842 extended_remote_kill (struct target_ops
*ops
)
7845 int pid
= ptid_get_pid (inferior_ptid
);
7846 struct remote_state
*rs
= get_remote_state ();
7848 res
= remote_vkill (pid
, rs
);
7849 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7851 /* Don't try 'k' on a multi-process aware stub -- it has no way
7852 to specify the pid. */
7856 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7857 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7860 /* Don't wait for it to die. I'm not really sure it matters whether
7861 we do or not. For the existing stubs, kill is a noop. */
7867 error (_("Can't kill process"));
7869 target_mourn_inferior ();
7873 remote_mourn (struct target_ops
*ops
)
7875 remote_mourn_1 (ops
);
7878 /* Worker function for remote_mourn. */
7880 remote_mourn_1 (struct target_ops
*target
)
7882 unpush_target (target
);
7884 /* remote_close takes care of doing most of the clean up. */
7885 generic_mourn_inferior ();
7889 extended_remote_mourn_1 (struct target_ops
*target
)
7891 struct remote_state
*rs
= get_remote_state ();
7893 /* In case we got here due to an error, but we're going to stay
7895 rs
->waiting_for_stop_reply
= 0;
7897 /* If the current general thread belonged to the process we just
7898 detached from or has exited, the remote side current general
7899 thread becomes undefined. Considering a case like this:
7901 - We just got here due to a detach.
7902 - The process that we're detaching from happens to immediately
7903 report a global breakpoint being hit in non-stop mode, in the
7904 same thread we had selected before.
7905 - GDB attaches to this process again.
7906 - This event happens to be the next event we handle.
7908 GDB would consider that the current general thread didn't need to
7909 be set on the stub side (with Hg), since for all it knew,
7910 GENERAL_THREAD hadn't changed.
7912 Notice that although in all-stop mode, the remote server always
7913 sets the current thread to the thread reporting the stop event,
7914 that doesn't happen in non-stop mode; in non-stop, the stub *must
7915 not* change the current thread when reporting a breakpoint hit,
7916 due to the decoupling of event reporting and event handling.
7918 To keep things simple, we always invalidate our notion of the
7920 record_currthread (rs
, minus_one_ptid
);
7922 /* Unlike "target remote", we do not want to unpush the target; then
7923 the next time the user says "run", we won't be connected. */
7925 /* Call common code to mark the inferior as not running. */
7926 generic_mourn_inferior ();
7928 if (!have_inferiors ())
7930 if (!remote_multi_process_p (rs
))
7932 /* Check whether the target is running now - some remote stubs
7933 automatically restart after kill. */
7935 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7937 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7939 /* Assume that the target has been restarted. Set
7940 inferior_ptid so that bits of core GDB realizes
7941 there's something here, e.g., so that the user can
7942 say "kill" again. */
7943 inferior_ptid
= magic_null_ptid
;
7950 extended_remote_mourn (struct target_ops
*ops
)
7952 extended_remote_mourn_1 (ops
);
7956 extended_remote_supports_disable_randomization (void)
7958 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7963 extended_remote_disable_randomization (int val
)
7965 struct remote_state
*rs
= get_remote_state ();
7968 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
7971 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7973 error (_("Target does not support QDisableRandomization."));
7974 if (strcmp (reply
, "OK") != 0)
7975 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7979 extended_remote_run (char *args
)
7981 struct remote_state
*rs
= get_remote_state ();
7984 /* If the user has disabled vRun support, or we have detected that
7985 support is not available, do not try it. */
7986 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7989 strcpy (rs
->buf
, "vRun;");
7990 len
= strlen (rs
->buf
);
7992 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7993 error (_("Remote file name too long for run packet"));
7994 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7996 gdb_assert (args
!= NULL
);
7999 struct cleanup
*back_to
;
8003 argv
= gdb_buildargv (args
);
8004 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
8005 for (i
= 0; argv
[i
] != NULL
; i
++)
8007 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8008 error (_("Argument list too long for run packet"));
8009 rs
->buf
[len
++] = ';';
8010 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
8012 do_cleanups (back_to
);
8015 rs
->buf
[len
++] = '\0';
8018 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8020 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
8022 /* We have a wait response. All is well. */
8025 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
8026 /* It wasn't disabled before, but it is now. */
8030 if (remote_exec_file
[0] == '\0')
8031 error (_("Running the default executable on the remote target failed; "
8032 "try \"set remote exec-file\"?"));
8034 error (_("Running \"%s\" on the remote target failed"),
8039 /* In the extended protocol we want to be able to do things like
8040 "run" and have them basically work as expected. So we need
8041 a special create_inferior function. We support changing the
8042 executable file and the command line arguments, but not the
8046 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
8047 char **env
, int from_tty
)
8051 struct remote_state
*rs
= get_remote_state ();
8053 /* If running asynchronously, register the target file descriptor
8054 with the event loop. */
8055 if (target_can_async_p ())
8056 target_async (inferior_event_handler
, 0);
8058 /* Disable address space randomization if requested (and supported). */
8059 if (extended_remote_supports_disable_randomization ())
8060 extended_remote_disable_randomization (disable_randomization
);
8062 /* Now restart the remote server. */
8063 run_worked
= extended_remote_run (args
) != -1;
8066 /* vRun was not supported. Fail if we need it to do what the
8068 if (remote_exec_file
[0])
8069 error (_("Remote target does not support \"set remote exec-file\""));
8071 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8073 /* Fall back to "R". */
8074 extended_remote_restart ();
8077 if (!have_inferiors ())
8079 /* Clean up from the last time we ran, before we mark the target
8080 running again. This will mark breakpoints uninserted, and
8081 get_offsets may insert breakpoints. */
8082 init_thread_list ();
8083 init_wait_for_inferior ();
8086 /* vRun's success return is a stop reply. */
8087 stop_reply
= run_worked
? rs
->buf
: NULL
;
8088 add_current_inferior_and_thread (stop_reply
);
8090 /* Get updated offsets, if the stub uses qOffsets. */
8095 extended_remote_create_inferior (struct target_ops
*ops
,
8096 char *exec_file
, char *args
,
8097 char **env
, int from_tty
)
8099 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
8103 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8104 the list of conditions (in agent expression bytecode format), if any, the
8105 target needs to evaluate. The output is placed into the packet buffer
8106 started from BUF and ended at BUF_END. */
8109 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8110 struct bp_target_info
*bp_tgt
, char *buf
,
8113 struct agent_expr
*aexpr
= NULL
;
8116 char *buf_start
= buf
;
8118 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8121 buf
+= strlen (buf
);
8122 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8125 /* Send conditions to the target and free the vector. */
8127 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8130 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8131 buf
+= strlen (buf
);
8132 for (i
= 0; i
< aexpr
->len
; ++i
)
8133 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8137 VEC_free (agent_expr_p
, bp_tgt
->conditions
);
8142 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8143 struct bp_target_info
*bp_tgt
, char *buf
)
8145 struct agent_expr
*aexpr
= NULL
;
8148 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8151 buf
+= strlen (buf
);
8153 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8154 buf
+= strlen (buf
);
8156 /* Concatenate all the agent expressions that are commands into the
8159 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8162 sprintf (buf
, "X%x,", aexpr
->len
);
8163 buf
+= strlen (buf
);
8164 for (i
= 0; i
< aexpr
->len
; ++i
)
8165 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8169 VEC_free (agent_expr_p
, bp_tgt
->tcommands
);
8172 /* Insert a breakpoint. On targets that have software breakpoint
8173 support, we ask the remote target to do the work; on targets
8174 which don't, we insert a traditional memory breakpoint. */
8177 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
8178 struct bp_target_info
*bp_tgt
)
8180 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8181 If it succeeds, then set the support to PACKET_ENABLE. If it
8182 fails, and the user has explicitly requested the Z support then
8183 report an error, otherwise, mark it disabled and go on. */
8185 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8187 CORE_ADDR addr
= bp_tgt
->placed_address
;
8188 struct remote_state
*rs
;
8191 struct condition_list
*cond
= NULL
;
8193 /* Make sure the remote is pointing at the right process, if
8195 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8196 set_general_process ();
8198 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8200 rs
= get_remote_state ();
8202 endbuf
= rs
->buf
+ get_remote_packet_size ();
8207 addr
= (ULONGEST
) remote_address_masked (addr
);
8208 p
+= hexnumstr (p
, addr
);
8209 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8211 if (remote_supports_cond_breakpoints ())
8212 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8214 if (remote_can_run_breakpoint_commands ())
8215 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8218 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8220 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8225 bp_tgt
->placed_address
= addr
;
8226 bp_tgt
->placed_size
= bpsize
;
8228 case PACKET_UNKNOWN
:
8233 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
8237 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
8238 struct bp_target_info
*bp_tgt
)
8240 CORE_ADDR addr
= bp_tgt
->placed_address
;
8241 struct remote_state
*rs
= get_remote_state ();
8243 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8246 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8248 /* Make sure the remote is pointing at the right process, if
8250 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8251 set_general_process ();
8257 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8258 p
+= hexnumstr (p
, addr
);
8259 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8262 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8264 return (rs
->buf
[0] == 'E');
8267 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
8271 watchpoint_to_Z_packet (int type
)
8276 return Z_PACKET_WRITE_WP
;
8279 return Z_PACKET_READ_WP
;
8282 return Z_PACKET_ACCESS_WP
;
8285 internal_error (__FILE__
, __LINE__
,
8286 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8291 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
8292 struct expression
*cond
)
8294 struct remote_state
*rs
= get_remote_state ();
8295 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8297 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8299 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8302 /* Make sure the remote is pointing at the right process, if
8304 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8305 set_general_process ();
8307 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8308 p
= strchr (rs
->buf
, '\0');
8309 addr
= remote_address_masked (addr
);
8310 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8311 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8314 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8316 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8320 case PACKET_UNKNOWN
:
8325 internal_error (__FILE__
, __LINE__
,
8326 _("remote_insert_watchpoint: reached end of function"));
8330 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8331 CORE_ADDR start
, int length
)
8333 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8335 return diff
< length
;
8340 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
8341 struct expression
*cond
)
8343 struct remote_state
*rs
= get_remote_state ();
8344 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8346 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8348 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8351 /* Make sure the remote is pointing at the right process, if
8353 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8354 set_general_process ();
8356 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8357 p
= strchr (rs
->buf
, '\0');
8358 addr
= remote_address_masked (addr
);
8359 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8360 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8362 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8364 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8367 case PACKET_UNKNOWN
:
8372 internal_error (__FILE__
, __LINE__
,
8373 _("remote_remove_watchpoint: reached end of function"));
8377 int remote_hw_watchpoint_limit
= -1;
8378 int remote_hw_watchpoint_length_limit
= -1;
8379 int remote_hw_breakpoint_limit
= -1;
8382 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
8384 if (remote_hw_watchpoint_length_limit
== 0)
8386 else if (remote_hw_watchpoint_length_limit
< 0)
8388 else if (len
<= remote_hw_watchpoint_length_limit
)
8395 remote_check_watch_resources (int type
, int cnt
, int ot
)
8397 if (type
== bp_hardware_breakpoint
)
8399 if (remote_hw_breakpoint_limit
== 0)
8401 else if (remote_hw_breakpoint_limit
< 0)
8403 else if (cnt
<= remote_hw_breakpoint_limit
)
8408 if (remote_hw_watchpoint_limit
== 0)
8410 else if (remote_hw_watchpoint_limit
< 0)
8414 else if (cnt
<= remote_hw_watchpoint_limit
)
8421 remote_stopped_by_watchpoint (void)
8423 return remote_stopped_by_watchpoint_p
;
8427 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8431 if (remote_stopped_by_watchpoint ())
8433 *addr_p
= remote_watch_data_address
;
8442 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
8443 struct bp_target_info
*bp_tgt
)
8446 struct remote_state
*rs
;
8450 /* The length field should be set to the size of a breakpoint
8451 instruction, even though we aren't inserting one ourselves. */
8453 gdbarch_remote_breakpoint_from_pc
8454 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
8456 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8459 /* Make sure the remote is pointing at the right process, if
8461 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8462 set_general_process ();
8464 rs
= get_remote_state ();
8466 endbuf
= rs
->buf
+ get_remote_packet_size ();
8472 addr
= remote_address_masked (bp_tgt
->placed_address
);
8473 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8474 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8476 if (remote_supports_cond_breakpoints ())
8477 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8479 if (remote_can_run_breakpoint_commands ())
8480 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8483 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8485 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8488 if (rs
->buf
[1] == '.')
8490 message
= strchr (rs
->buf
+ 2, '.');
8492 error (_("Remote failure reply: %s"), message
+ 1);
8495 case PACKET_UNKNOWN
:
8500 internal_error (__FILE__
, __LINE__
,
8501 _("remote_insert_hw_breakpoint: reached end of function"));
8506 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
8507 struct bp_target_info
*bp_tgt
)
8510 struct remote_state
*rs
= get_remote_state ();
8512 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8514 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8517 /* Make sure the remote is pointing at the right process, if
8519 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8520 set_general_process ();
8526 addr
= remote_address_masked (bp_tgt
->placed_address
);
8527 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8528 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8531 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8533 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8536 case PACKET_UNKNOWN
:
8541 internal_error (__FILE__
, __LINE__
,
8542 _("remote_remove_hw_breakpoint: reached end of function"));
8545 /* Verify memory using the "qCRC:" request. */
8548 remote_verify_memory (struct target_ops
*ops
,
8549 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8551 struct remote_state
*rs
= get_remote_state ();
8552 unsigned long host_crc
, target_crc
;
8555 /* Make sure the remote is pointing at the right process. */
8556 set_general_process ();
8558 /* FIXME: assumes lma can fit into long. */
8559 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8560 (long) lma
, (long) size
);
8563 /* Be clever; compute the host_crc before waiting for target
8565 host_crc
= xcrc32 (data
, size
, 0xffffffff);
8567 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8568 if (rs
->buf
[0] == 'E')
8571 if (rs
->buf
[0] != 'C')
8572 error (_("remote target does not support this operation"));
8574 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8575 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8577 return (host_crc
== target_crc
);
8580 /* compare-sections command
8582 With no arguments, compares each loadable section in the exec bfd
8583 with the same memory range on the target, and reports mismatches.
8584 Useful for verifying the image on the target against the exec file. */
8587 compare_sections_command (char *args
, int from_tty
)
8590 struct cleanup
*old_chain
;
8592 const char *sectname
;
8600 error (_("command cannot be used without an exec file"));
8602 /* Make sure the remote is pointing at the right process. */
8603 set_general_process ();
8605 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8607 if (!(s
->flags
& SEC_LOAD
))
8608 continue; /* Skip non-loadable section. */
8610 size
= bfd_get_section_size (s
);
8612 continue; /* Skip zero-length section. */
8614 sectname
= bfd_get_section_name (exec_bfd
, s
);
8615 if (args
&& strcmp (args
, sectname
) != 0)
8616 continue; /* Not the section selected by user. */
8618 matched
= 1; /* Do this section. */
8621 sectdata
= xmalloc (size
);
8622 old_chain
= make_cleanup (xfree
, sectdata
);
8623 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8625 res
= target_verify_memory (sectdata
, lma
, size
);
8628 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8629 paddress (target_gdbarch (), lma
),
8630 paddress (target_gdbarch (), lma
+ size
));
8632 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8633 paddress (target_gdbarch (), lma
),
8634 paddress (target_gdbarch (), lma
+ size
));
8636 printf_filtered ("matched.\n");
8639 printf_filtered ("MIS-MATCHED!\n");
8643 do_cleanups (old_chain
);
8646 warning (_("One or more sections of the remote executable does not match\n\
8647 the loaded file\n"));
8648 if (args
&& !matched
)
8649 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8652 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8653 into remote target. The number of bytes written to the remote
8654 target is returned, or -1 for error. */
8657 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8658 const char *annex
, const gdb_byte
*writebuf
,
8659 ULONGEST offset
, LONGEST len
,
8660 struct packet_config
*packet
)
8664 struct remote_state
*rs
= get_remote_state ();
8665 int max_size
= get_memory_write_packet_size ();
8667 if (packet
->support
== PACKET_DISABLE
)
8670 /* Insert header. */
8671 i
= snprintf (rs
->buf
, max_size
,
8672 "qXfer:%s:write:%s:%s:",
8673 object_name
, annex
? annex
: "",
8674 phex_nz (offset
, sizeof offset
));
8675 max_size
-= (i
+ 1);
8677 /* Escape as much data as fits into rs->buf. */
8678 buf_len
= remote_escape_output
8679 (writebuf
, len
, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
8681 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8682 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8683 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8686 unpack_varlen_hex (rs
->buf
, &n
);
8690 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8691 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8692 number of bytes read is returned, or 0 for EOF, or -1 for error.
8693 The number of bytes read may be less than LEN without indicating an
8694 EOF. PACKET is checked and updated to indicate whether the remote
8695 target supports this object. */
8698 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8700 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8701 struct packet_config
*packet
)
8703 static char *finished_object
;
8704 static char *finished_annex
;
8705 static ULONGEST finished_offset
;
8707 struct remote_state
*rs
= get_remote_state ();
8708 LONGEST i
, n
, packet_len
;
8710 if (packet
->support
== PACKET_DISABLE
)
8713 /* Check whether we've cached an end-of-object packet that matches
8715 if (finished_object
)
8717 if (strcmp (object_name
, finished_object
) == 0
8718 && strcmp (annex
? annex
: "", finished_annex
) == 0
8719 && offset
== finished_offset
)
8722 /* Otherwise, we're now reading something different. Discard
8724 xfree (finished_object
);
8725 xfree (finished_annex
);
8726 finished_object
= NULL
;
8727 finished_annex
= NULL
;
8730 /* Request only enough to fit in a single packet. The actual data
8731 may not, since we don't know how much of it will need to be escaped;
8732 the target is free to respond with slightly less data. We subtract
8733 five to account for the response type and the protocol frame. */
8734 n
= min (get_remote_packet_size () - 5, len
);
8735 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8736 object_name
, annex
? annex
: "",
8737 phex_nz (offset
, sizeof offset
),
8738 phex_nz (n
, sizeof n
));
8739 i
= putpkt (rs
->buf
);
8744 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8745 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8748 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8749 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8751 /* 'm' means there is (or at least might be) more data after this
8752 batch. That does not make sense unless there's at least one byte
8753 of data in this reply. */
8754 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8755 error (_("Remote qXfer reply contained no data."));
8757 /* Got some data. */
8758 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
8759 packet_len
- 1, readbuf
, n
);
8761 /* 'l' is an EOF marker, possibly including a final block of data,
8762 or possibly empty. If we have the final block of a non-empty
8763 object, record this fact to bypass a subsequent partial read. */
8764 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8766 finished_object
= xstrdup (object_name
);
8767 finished_annex
= xstrdup (annex
? annex
: "");
8768 finished_offset
= offset
+ i
;
8775 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8776 const char *annex
, gdb_byte
*readbuf
,
8777 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8779 struct remote_state
*rs
;
8784 set_remote_traceframe ();
8785 set_general_thread (inferior_ptid
);
8787 rs
= get_remote_state ();
8789 /* Handle memory using the standard memory routines. */
8790 if (object
== TARGET_OBJECT_MEMORY
)
8796 /* If the remote target is connected but not running, we should
8797 pass this request down to a lower stratum (e.g. the executable
8799 if (!target_has_execution
)
8802 if (writebuf
!= NULL
)
8803 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8805 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8809 else if (xfered
== 0 && errno
== 0)
8815 /* Handle SPU memory using qxfer packets. */
8816 if (object
== TARGET_OBJECT_SPU
)
8819 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8820 &remote_protocol_packets
8821 [PACKET_qXfer_spu_read
]);
8823 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8824 &remote_protocol_packets
8825 [PACKET_qXfer_spu_write
]);
8828 /* Handle extra signal info using qxfer packets. */
8829 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8832 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8833 &remote_protocol_packets
8834 [PACKET_qXfer_siginfo_read
]);
8836 return remote_write_qxfer (ops
, "siginfo", annex
,
8837 writebuf
, offset
, len
,
8838 &remote_protocol_packets
8839 [PACKET_qXfer_siginfo_write
]);
8842 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8845 return remote_read_qxfer (ops
, "statictrace", annex
,
8846 readbuf
, offset
, len
,
8847 &remote_protocol_packets
8848 [PACKET_qXfer_statictrace_read
]);
8853 /* Only handle flash writes. */
8854 if (writebuf
!= NULL
)
8860 case TARGET_OBJECT_FLASH
:
8861 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8865 else if (xfered
== 0 && errno
== 0)
8875 /* Map pre-existing objects onto letters. DO NOT do this for new
8876 objects!!! Instead specify new query packets. */
8879 case TARGET_OBJECT_AVR
:
8883 case TARGET_OBJECT_AUXV
:
8884 gdb_assert (annex
== NULL
);
8885 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8886 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8888 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8889 return remote_read_qxfer
8890 (ops
, "features", annex
, readbuf
, offset
, len
,
8891 &remote_protocol_packets
[PACKET_qXfer_features
]);
8893 case TARGET_OBJECT_LIBRARIES
:
8894 return remote_read_qxfer
8895 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8896 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8898 case TARGET_OBJECT_LIBRARIES_SVR4
:
8899 return remote_read_qxfer
8900 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8901 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8903 case TARGET_OBJECT_MEMORY_MAP
:
8904 gdb_assert (annex
== NULL
);
8905 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8906 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8908 case TARGET_OBJECT_OSDATA
:
8909 /* Should only get here if we're connected. */
8910 gdb_assert (rs
->remote_desc
);
8911 return remote_read_qxfer
8912 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8913 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8915 case TARGET_OBJECT_THREADS
:
8916 gdb_assert (annex
== NULL
);
8917 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8918 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8920 case TARGET_OBJECT_TRACEFRAME_INFO
:
8921 gdb_assert (annex
== NULL
);
8922 return remote_read_qxfer
8923 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8924 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8926 case TARGET_OBJECT_FDPIC
:
8927 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8928 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8930 case TARGET_OBJECT_OPENVMS_UIB
:
8931 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
8932 &remote_protocol_packets
[PACKET_qXfer_uib
]);
8934 case TARGET_OBJECT_BTRACE
:
8935 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
8936 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
8942 /* Note: a zero OFFSET and LEN can be used to query the minimum
8944 if (offset
== 0 && len
== 0)
8945 return (get_remote_packet_size ());
8946 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8947 large enough let the caller deal with it. */
8948 if (len
< get_remote_packet_size ())
8950 len
= get_remote_packet_size ();
8952 /* Except for querying the minimum buffer size, target must be open. */
8953 if (!rs
->remote_desc
)
8954 error (_("remote query is only available after target open"));
8956 gdb_assert (annex
!= NULL
);
8957 gdb_assert (readbuf
!= NULL
);
8963 /* We used one buffer char for the remote protocol q command and
8964 another for the query type. As the remote protocol encapsulation
8965 uses 4 chars plus one extra in case we are debugging
8966 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8969 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8971 /* Bad caller may have sent forbidden characters. */
8972 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8977 gdb_assert (annex
[i
] == '\0');
8979 i
= putpkt (rs
->buf
);
8983 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8984 strcpy ((char *) readbuf
, rs
->buf
);
8986 return strlen ((char *) readbuf
);
8990 remote_search_memory (struct target_ops
* ops
,
8991 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8992 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8993 CORE_ADDR
*found_addrp
)
8995 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8996 struct remote_state
*rs
= get_remote_state ();
8997 int max_size
= get_memory_write_packet_size ();
8998 struct packet_config
*packet
=
8999 &remote_protocol_packets
[PACKET_qSearch_memory
];
9000 /* Number of packet bytes used to encode the pattern;
9001 this could be more than PATTERN_LEN due to escape characters. */
9002 int escaped_pattern_len
;
9003 /* Amount of pattern that was encodable in the packet. */
9004 int used_pattern_len
;
9007 ULONGEST found_addr
;
9009 /* Don't go to the target if we don't have to.
9010 This is done before checking packet->support to avoid the possibility that
9011 a success for this edge case means the facility works in general. */
9012 if (pattern_len
> search_space_len
)
9014 if (pattern_len
== 0)
9016 *found_addrp
= start_addr
;
9020 /* If we already know the packet isn't supported, fall back to the simple
9021 way of searching memory. */
9023 if (packet
->support
== PACKET_DISABLE
)
9025 /* Target doesn't provided special support, fall back and use the
9026 standard support (copy memory and do the search here). */
9027 return simple_search_memory (ops
, start_addr
, search_space_len
,
9028 pattern
, pattern_len
, found_addrp
);
9031 /* Make sure the remote is pointing at the right process. */
9032 set_general_process ();
9034 /* Insert header. */
9035 i
= snprintf (rs
->buf
, max_size
,
9036 "qSearch:memory:%s;%s;",
9037 phex_nz (start_addr
, addr_size
),
9038 phex_nz (search_space_len
, sizeof (search_space_len
)));
9039 max_size
-= (i
+ 1);
9041 /* Escape as much data as fits into rs->buf. */
9042 escaped_pattern_len
=
9043 remote_escape_output (pattern
, pattern_len
, (gdb_byte
*) rs
->buf
+ i
,
9044 &used_pattern_len
, max_size
);
9046 /* Bail if the pattern is too large. */
9047 if (used_pattern_len
!= pattern_len
)
9048 error (_("Pattern is too large to transmit to remote target."));
9050 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9051 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9052 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9054 /* The request may not have worked because the command is not
9055 supported. If so, fall back to the simple way. */
9056 if (packet
->support
== PACKET_DISABLE
)
9058 return simple_search_memory (ops
, start_addr
, search_space_len
,
9059 pattern
, pattern_len
, found_addrp
);
9064 if (rs
->buf
[0] == '0')
9066 else if (rs
->buf
[0] == '1')
9069 if (rs
->buf
[1] != ',')
9070 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9071 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9072 *found_addrp
= found_addr
;
9075 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9081 remote_rcmd (char *command
,
9082 struct ui_file
*outbuf
)
9084 struct remote_state
*rs
= get_remote_state ();
9087 if (!rs
->remote_desc
)
9088 error (_("remote rcmd is only available after target open"));
9090 /* Send a NULL command across as an empty command. */
9091 if (command
== NULL
)
9094 /* The query prefix. */
9095 strcpy (rs
->buf
, "qRcmd,");
9096 p
= strchr (rs
->buf
, '\0');
9098 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9099 > get_remote_packet_size ())
9100 error (_("\"monitor\" command ``%s'' is too long."), command
);
9102 /* Encode the actual command. */
9103 bin2hex ((gdb_byte
*) command
, p
, 0);
9105 if (putpkt (rs
->buf
) < 0)
9106 error (_("Communication problem with target."));
9108 /* get/display the response */
9113 /* XXX - see also remote_get_noisy_reply(). */
9114 QUIT
; /* Allow user to bail out with ^C. */
9116 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9118 /* Timeout. Continue to (try to) read responses.
9119 This is better than stopping with an error, assuming the stub
9120 is still executing the (long) monitor command.
9121 If needed, the user can interrupt gdb using C-c, obtaining
9122 an effect similar to stop on timeout. */
9127 error (_("Target does not support this command."));
9128 if (buf
[0] == 'O' && buf
[1] != 'K')
9130 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9133 if (strcmp (buf
, "OK") == 0)
9135 if (strlen (buf
) == 3 && buf
[0] == 'E'
9136 && isdigit (buf
[1]) && isdigit (buf
[2]))
9138 error (_("Protocol error with Rcmd"));
9140 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9142 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9144 fputc_unfiltered (c
, outbuf
);
9150 static VEC(mem_region_s
) *
9151 remote_memory_map (struct target_ops
*ops
)
9153 VEC(mem_region_s
) *result
= NULL
;
9154 char *text
= target_read_stralloc (¤t_target
,
9155 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9159 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9161 result
= parse_memory_map (text
);
9162 do_cleanups (back_to
);
9169 packet_command (char *args
, int from_tty
)
9171 struct remote_state
*rs
= get_remote_state ();
9173 if (!rs
->remote_desc
)
9174 error (_("command can only be used with remote target"));
9177 error (_("remote-packet command requires packet text as argument"));
9179 puts_filtered ("sending: ");
9180 print_packet (args
);
9181 puts_filtered ("\n");
9184 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9185 puts_filtered ("received: ");
9186 print_packet (rs
->buf
);
9187 puts_filtered ("\n");
9191 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9193 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9195 static void threadset_test_cmd (char *cmd
, int tty
);
9197 static void threadalive_test (char *cmd
, int tty
);
9199 static void threadlist_test_cmd (char *cmd
, int tty
);
9201 int get_and_display_threadinfo (threadref
*ref
);
9203 static void threadinfo_test_cmd (char *cmd
, int tty
);
9205 static int thread_display_step (threadref
*ref
, void *context
);
9207 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9209 static void init_remote_threadtests (void);
9211 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9214 threadset_test_cmd (char *cmd
, int tty
)
9216 int sample_thread
= SAMPLE_THREAD
;
9218 printf_filtered (_("Remote threadset test\n"));
9219 set_general_thread (sample_thread
);
9224 threadalive_test (char *cmd
, int tty
)
9226 int sample_thread
= SAMPLE_THREAD
;
9227 int pid
= ptid_get_pid (inferior_ptid
);
9228 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
9230 if (remote_thread_alive (ptid
))
9231 printf_filtered ("PASS: Thread alive test\n");
9233 printf_filtered ("FAIL: Thread alive test\n");
9236 void output_threadid (char *title
, threadref
*ref
);
9239 output_threadid (char *title
, threadref
*ref
)
9243 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9245 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9249 threadlist_test_cmd (char *cmd
, int tty
)
9252 threadref nextthread
;
9253 int done
, result_count
;
9254 threadref threadlist
[3];
9256 printf_filtered ("Remote Threadlist test\n");
9257 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9258 &result_count
, &threadlist
[0]))
9259 printf_filtered ("FAIL: threadlist test\n");
9262 threadref
*scan
= threadlist
;
9263 threadref
*limit
= scan
+ result_count
;
9265 while (scan
< limit
)
9266 output_threadid (" thread ", scan
++);
9271 display_thread_info (struct gdb_ext_thread_info
*info
)
9273 output_threadid ("Threadid: ", &info
->threadid
);
9274 printf_filtered ("Name: %s\n ", info
->shortname
);
9275 printf_filtered ("State: %s\n", info
->display
);
9276 printf_filtered ("other: %s\n\n", info
->more_display
);
9280 get_and_display_threadinfo (threadref
*ref
)
9284 struct gdb_ext_thread_info threadinfo
;
9286 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9287 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9288 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9289 display_thread_info (&threadinfo
);
9294 threadinfo_test_cmd (char *cmd
, int tty
)
9296 int athread
= SAMPLE_THREAD
;
9300 int_to_threadref (&thread
, athread
);
9301 printf_filtered ("Remote Threadinfo test\n");
9302 if (!get_and_display_threadinfo (&thread
))
9303 printf_filtered ("FAIL cannot get thread info\n");
9307 thread_display_step (threadref
*ref
, void *context
)
9309 /* output_threadid(" threadstep ",ref); *//* simple test */
9310 return get_and_display_threadinfo (ref
);
9314 threadlist_update_test_cmd (char *cmd
, int tty
)
9316 printf_filtered ("Remote Threadlist update test\n");
9317 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9321 init_remote_threadtests (void)
9323 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9324 _("Fetch and print the remote list of "
9325 "thread identifiers, one pkt only"));
9326 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9327 _("Fetch and display info about one thread"));
9328 add_com ("tset", class_obscure
, threadset_test_cmd
,
9329 _("Test setting to a different thread"));
9330 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9331 _("Iterate through updating all remote thread info"));
9332 add_com ("talive", class_obscure
, threadalive_test
,
9333 _(" Remote thread alive test "));
9338 /* Convert a thread ID to a string. Returns the string in a static
9342 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9344 static char buf
[64];
9345 struct remote_state
*rs
= get_remote_state ();
9347 if (ptid_equal (ptid
, null_ptid
))
9348 return normal_pid_to_str (ptid
);
9349 else if (ptid_is_pid (ptid
))
9351 /* Printing an inferior target id. */
9353 /* When multi-process extensions are off, there's no way in the
9354 remote protocol to know the remote process id, if there's any
9355 at all. There's one exception --- when we're connected with
9356 target extended-remote, and we manually attached to a process
9357 with "attach PID". We don't record anywhere a flag that
9358 allows us to distinguish that case from the case of
9359 connecting with extended-remote and the stub already being
9360 attached to a process, and reporting yes to qAttached, hence
9361 no smart special casing here. */
9362 if (!remote_multi_process_p (rs
))
9364 xsnprintf (buf
, sizeof buf
, "Remote target");
9368 return normal_pid_to_str (ptid
);
9372 if (ptid_equal (magic_null_ptid
, ptid
))
9373 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9374 else if (rs
->extended
&& remote_multi_process_p (rs
))
9375 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9376 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
9378 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9379 ptid_get_tid (ptid
));
9384 /* Get the address of the thread local variable in OBJFILE which is
9385 stored at OFFSET within the thread local storage for thread PTID. */
9388 remote_get_thread_local_address (struct target_ops
*ops
,
9389 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9391 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
9393 struct remote_state
*rs
= get_remote_state ();
9395 char *endp
= rs
->buf
+ get_remote_packet_size ();
9396 enum packet_result result
;
9398 strcpy (p
, "qGetTLSAddr:");
9400 p
= write_ptid (p
, endp
, ptid
);
9402 p
+= hexnumstr (p
, offset
);
9404 p
+= hexnumstr (p
, lm
);
9408 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9409 result
= packet_ok (rs
->buf
,
9410 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9411 if (result
== PACKET_OK
)
9415 unpack_varlen_hex (rs
->buf
, &result
);
9418 else if (result
== PACKET_UNKNOWN
)
9419 throw_error (TLS_GENERIC_ERROR
,
9420 _("Remote target doesn't support qGetTLSAddr packet"));
9422 throw_error (TLS_GENERIC_ERROR
,
9423 _("Remote target failed to process qGetTLSAddr request"));
9426 throw_error (TLS_GENERIC_ERROR
,
9427 _("TLS not supported or disabled on this target"));
9432 /* Provide thread local base, i.e. Thread Information Block address.
9433 Returns 1 if ptid is found and thread_local_base is non zero. */
9436 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
9438 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
9440 struct remote_state
*rs
= get_remote_state ();
9442 char *endp
= rs
->buf
+ get_remote_packet_size ();
9443 enum packet_result result
;
9445 strcpy (p
, "qGetTIBAddr:");
9447 p
= write_ptid (p
, endp
, ptid
);
9451 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9452 result
= packet_ok (rs
->buf
,
9453 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9454 if (result
== PACKET_OK
)
9458 unpack_varlen_hex (rs
->buf
, &result
);
9460 *addr
= (CORE_ADDR
) result
;
9463 else if (result
== PACKET_UNKNOWN
)
9464 error (_("Remote target doesn't support qGetTIBAddr packet"));
9466 error (_("Remote target failed to process qGetTIBAddr request"));
9469 error (_("qGetTIBAddr not supported or disabled on this target"));
9474 /* Support for inferring a target description based on the current
9475 architecture and the size of a 'g' packet. While the 'g' packet
9476 can have any size (since optional registers can be left off the
9477 end), some sizes are easily recognizable given knowledge of the
9478 approximate architecture. */
9480 struct remote_g_packet_guess
9483 const struct target_desc
*tdesc
;
9485 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9486 DEF_VEC_O(remote_g_packet_guess_s
);
9488 struct remote_g_packet_data
9490 VEC(remote_g_packet_guess_s
) *guesses
;
9493 static struct gdbarch_data
*remote_g_packet_data_handle
;
9496 remote_g_packet_data_init (struct obstack
*obstack
)
9498 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9502 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9503 const struct target_desc
*tdesc
)
9505 struct remote_g_packet_data
*data
9506 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9507 struct remote_g_packet_guess new_guess
, *guess
;
9510 gdb_assert (tdesc
!= NULL
);
9513 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9515 if (guess
->bytes
== bytes
)
9516 internal_error (__FILE__
, __LINE__
,
9517 _("Duplicate g packet description added for size %d"),
9520 new_guess
.bytes
= bytes
;
9521 new_guess
.tdesc
= tdesc
;
9522 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9525 /* Return 1 if remote_read_description would do anything on this target
9526 and architecture, 0 otherwise. */
9529 remote_read_description_p (struct target_ops
*target
)
9531 struct remote_g_packet_data
*data
9532 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9534 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9540 static const struct target_desc
*
9541 remote_read_description (struct target_ops
*target
)
9543 struct remote_g_packet_data
*data
9544 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9546 /* Do not try this during initial connection, when we do not know
9547 whether there is a running but stopped thread. */
9548 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9551 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9553 struct remote_g_packet_guess
*guess
;
9555 int bytes
= send_g_packet ();
9558 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9560 if (guess
->bytes
== bytes
)
9561 return guess
->tdesc
;
9563 /* We discard the g packet. A minor optimization would be to
9564 hold on to it, and fill the register cache once we have selected
9565 an architecture, but it's too tricky to do safely. */
9571 /* Remote file transfer support. This is host-initiated I/O, not
9572 target-initiated; for target-initiated, see remote-fileio.c. */
9574 /* If *LEFT is at least the length of STRING, copy STRING to
9575 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9576 decrease *LEFT. Otherwise raise an error. */
9579 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9581 int len
= strlen (string
);
9584 error (_("Packet too long for target."));
9586 memcpy (*buffer
, string
, len
);
9590 /* NUL-terminate the buffer as a convenience, if there is
9596 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9597 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9598 decrease *LEFT. Otherwise raise an error. */
9601 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9604 if (2 * len
> *left
)
9605 error (_("Packet too long for target."));
9607 bin2hex (bytes
, *buffer
, len
);
9611 /* NUL-terminate the buffer as a convenience, if there is
9617 /* If *LEFT is large enough, convert VALUE to hex and add it to
9618 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9619 decrease *LEFT. Otherwise raise an error. */
9622 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9624 int len
= hexnumlen (value
);
9627 error (_("Packet too long for target."));
9629 hexnumstr (*buffer
, value
);
9633 /* NUL-terminate the buffer as a convenience, if there is
9639 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9640 value, *REMOTE_ERRNO to the remote error number or zero if none
9641 was included, and *ATTACHMENT to point to the start of the annex
9642 if any. The length of the packet isn't needed here; there may
9643 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9645 Return 0 if the packet could be parsed, -1 if it could not. If
9646 -1 is returned, the other variables may not be initialized. */
9649 remote_hostio_parse_result (char *buffer
, int *retcode
,
9650 int *remote_errno
, char **attachment
)
9657 if (buffer
[0] != 'F')
9661 *retcode
= strtol (&buffer
[1], &p
, 16);
9662 if (errno
!= 0 || p
== &buffer
[1])
9665 /* Check for ",errno". */
9669 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9670 if (errno
!= 0 || p
+ 1 == p2
)
9675 /* Check for ";attachment". If there is no attachment, the
9676 packet should end here. */
9679 *attachment
= p
+ 1;
9682 else if (*p
== '\0')
9688 /* Send a prepared I/O packet to the target and read its response.
9689 The prepared packet is in the global RS->BUF before this function
9690 is called, and the answer is there when we return.
9692 COMMAND_BYTES is the length of the request to send, which may include
9693 binary data. WHICH_PACKET is the packet configuration to check
9694 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9695 is set to the error number and -1 is returned. Otherwise the value
9696 returned by the function is returned.
9698 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9699 attachment is expected; an error will be reported if there's a
9700 mismatch. If one is found, *ATTACHMENT will be set to point into
9701 the packet buffer and *ATTACHMENT_LEN will be set to the
9702 attachment's length. */
9705 remote_hostio_send_command (int command_bytes
, int which_packet
,
9706 int *remote_errno
, char **attachment
,
9707 int *attachment_len
)
9709 struct remote_state
*rs
= get_remote_state ();
9710 int ret
, bytes_read
;
9711 char *attachment_tmp
;
9713 if (!rs
->remote_desc
9714 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9716 *remote_errno
= FILEIO_ENOSYS
;
9720 putpkt_binary (rs
->buf
, command_bytes
);
9721 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9723 /* If it timed out, something is wrong. Don't try to parse the
9727 *remote_errno
= FILEIO_EINVAL
;
9731 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9734 *remote_errno
= FILEIO_EINVAL
;
9736 case PACKET_UNKNOWN
:
9737 *remote_errno
= FILEIO_ENOSYS
;
9743 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9746 *remote_errno
= FILEIO_EINVAL
;
9750 /* Make sure we saw an attachment if and only if we expected one. */
9751 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9752 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9754 *remote_errno
= FILEIO_EINVAL
;
9758 /* If an attachment was found, it must point into the packet buffer;
9759 work out how many bytes there were. */
9760 if (attachment_tmp
!= NULL
)
9762 *attachment
= attachment_tmp
;
9763 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9769 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9770 remote file descriptor, or -1 if an error occurs (and set
9774 remote_hostio_open (const char *filename
, int flags
, int mode
,
9777 struct remote_state
*rs
= get_remote_state ();
9779 int left
= get_remote_packet_size () - 1;
9781 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9783 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9785 remote_buffer_add_string (&p
, &left
, ",");
9787 remote_buffer_add_int (&p
, &left
, flags
);
9788 remote_buffer_add_string (&p
, &left
, ",");
9790 remote_buffer_add_int (&p
, &left
, mode
);
9792 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9793 remote_errno
, NULL
, NULL
);
9796 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9797 Return the number of bytes written, or -1 if an error occurs (and
9798 set *REMOTE_ERRNO). */
9801 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9802 ULONGEST offset
, int *remote_errno
)
9804 struct remote_state
*rs
= get_remote_state ();
9806 int left
= get_remote_packet_size ();
9809 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9811 remote_buffer_add_int (&p
, &left
, fd
);
9812 remote_buffer_add_string (&p
, &left
, ",");
9814 remote_buffer_add_int (&p
, &left
, offset
);
9815 remote_buffer_add_string (&p
, &left
, ",");
9817 p
+= remote_escape_output (write_buf
, len
, (gdb_byte
*) p
, &out_len
,
9818 get_remote_packet_size () - (p
- rs
->buf
));
9820 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9821 remote_errno
, NULL
, NULL
);
9824 /* Read up to LEN bytes FD on the remote target into READ_BUF
9825 Return the number of bytes read, or -1 if an error occurs (and
9826 set *REMOTE_ERRNO). */
9829 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9830 ULONGEST offset
, int *remote_errno
)
9832 struct remote_state
*rs
= get_remote_state ();
9835 int left
= get_remote_packet_size ();
9836 int ret
, attachment_len
;
9839 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9841 remote_buffer_add_int (&p
, &left
, fd
);
9842 remote_buffer_add_string (&p
, &left
, ",");
9844 remote_buffer_add_int (&p
, &left
, len
);
9845 remote_buffer_add_string (&p
, &left
, ",");
9847 remote_buffer_add_int (&p
, &left
, offset
);
9849 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9850 remote_errno
, &attachment
,
9856 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9858 if (read_len
!= ret
)
9859 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9864 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9865 (and set *REMOTE_ERRNO). */
9868 remote_hostio_close (int fd
, int *remote_errno
)
9870 struct remote_state
*rs
= get_remote_state ();
9872 int left
= get_remote_packet_size () - 1;
9874 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9876 remote_buffer_add_int (&p
, &left
, fd
);
9878 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9879 remote_errno
, NULL
, NULL
);
9882 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9883 occurs (and set *REMOTE_ERRNO). */
9886 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9888 struct remote_state
*rs
= get_remote_state ();
9890 int left
= get_remote_packet_size () - 1;
9892 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9894 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9897 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9898 remote_errno
, NULL
, NULL
);
9901 /* Read value of symbolic link FILENAME on the remote target. Return
9902 a null-terminated string allocated via xmalloc, or NULL if an error
9903 occurs (and set *REMOTE_ERRNO). */
9906 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9908 struct remote_state
*rs
= get_remote_state ();
9911 int left
= get_remote_packet_size ();
9912 int len
, attachment_len
;
9916 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9918 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9921 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9922 remote_errno
, &attachment
,
9928 ret
= xmalloc (len
+ 1);
9930 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9931 (gdb_byte
*) ret
, len
);
9932 if (read_len
!= len
)
9933 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9940 remote_fileio_errno_to_host (int errnum
)
9964 case FILEIO_ENOTDIR
:
9984 case FILEIO_ENAMETOOLONG
:
9985 return ENAMETOOLONG
;
9991 remote_hostio_error (int errnum
)
9993 int host_error
= remote_fileio_errno_to_host (errnum
);
9995 if (host_error
== -1)
9996 error (_("Unknown remote I/O error %d"), errnum
);
9998 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
10002 remote_hostio_close_cleanup (void *opaque
)
10004 int fd
= *(int *) opaque
;
10007 remote_hostio_close (fd
, &remote_errno
);
10012 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
10014 const char *filename
= bfd_get_filename (abfd
);
10015 int fd
, remote_errno
;
10018 gdb_assert (remote_filename_p (filename
));
10020 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
10023 errno
= remote_fileio_errno_to_host (remote_errno
);
10024 bfd_set_error (bfd_error_system_call
);
10028 stream
= xmalloc (sizeof (int));
10034 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
10036 int fd
= *(int *)stream
;
10041 /* Ignore errors on close; these may happen if the remote
10042 connection was already torn down. */
10043 remote_hostio_close (fd
, &remote_errno
);
10045 /* Zero means success. */
10050 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
10051 file_ptr nbytes
, file_ptr offset
)
10053 int fd
= *(int *)stream
;
10055 file_ptr pos
, bytes
;
10058 while (nbytes
> pos
)
10060 bytes
= remote_hostio_pread (fd
, (gdb_byte
*) buf
+ pos
, nbytes
- pos
,
10061 offset
+ pos
, &remote_errno
);
10063 /* Success, but no bytes, means end-of-file. */
10067 errno
= remote_fileio_errno_to_host (remote_errno
);
10068 bfd_set_error (bfd_error_system_call
);
10079 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
10081 /* FIXME: We should probably implement remote_hostio_stat. */
10082 sb
->st_size
= INT_MAX
;
10087 remote_filename_p (const char *filename
)
10089 return strncmp (filename
, "remote:", 7) == 0;
10093 remote_bfd_open (const char *remote_file
, const char *target
)
10095 bfd
*abfd
= gdb_bfd_openr_iovec (remote_file
, target
,
10096 remote_bfd_iovec_open
, NULL
,
10097 remote_bfd_iovec_pread
,
10098 remote_bfd_iovec_close
,
10099 remote_bfd_iovec_stat
);
10105 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10107 struct cleanup
*back_to
, *close_cleanup
;
10108 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10111 int bytes_in_buffer
;
10114 struct remote_state
*rs
= get_remote_state ();
10116 if (!rs
->remote_desc
)
10117 error (_("command can only be used with remote target"));
10119 file
= gdb_fopen_cloexec (local_file
, "rb");
10121 perror_with_name (local_file
);
10122 back_to
= make_cleanup_fclose (file
);
10124 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10126 0700, &remote_errno
);
10128 remote_hostio_error (remote_errno
);
10130 /* Send up to this many bytes at once. They won't all fit in the
10131 remote packet limit, so we'll transfer slightly fewer. */
10132 io_size
= get_remote_packet_size ();
10133 buffer
= xmalloc (io_size
);
10134 make_cleanup (xfree
, buffer
);
10136 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10138 bytes_in_buffer
= 0;
10141 while (bytes_in_buffer
|| !saw_eof
)
10145 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10146 io_size
- bytes_in_buffer
,
10151 error (_("Error reading %s."), local_file
);
10154 /* EOF. Unless there is something still in the
10155 buffer from the last iteration, we are done. */
10157 if (bytes_in_buffer
== 0)
10165 bytes
+= bytes_in_buffer
;
10166 bytes_in_buffer
= 0;
10168 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
10169 offset
, &remote_errno
);
10172 remote_hostio_error (remote_errno
);
10173 else if (retcode
== 0)
10174 error (_("Remote write of %d bytes returned 0!"), bytes
);
10175 else if (retcode
< bytes
)
10177 /* Short write. Save the rest of the read data for the next
10179 bytes_in_buffer
= bytes
- retcode
;
10180 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10186 discard_cleanups (close_cleanup
);
10187 if (remote_hostio_close (fd
, &remote_errno
))
10188 remote_hostio_error (remote_errno
);
10191 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10192 do_cleanups (back_to
);
10196 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10198 struct cleanup
*back_to
, *close_cleanup
;
10199 int fd
, remote_errno
, bytes
, io_size
;
10203 struct remote_state
*rs
= get_remote_state ();
10205 if (!rs
->remote_desc
)
10206 error (_("command can only be used with remote target"));
10208 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10210 remote_hostio_error (remote_errno
);
10212 file
= gdb_fopen_cloexec (local_file
, "wb");
10214 perror_with_name (local_file
);
10215 back_to
= make_cleanup_fclose (file
);
10217 /* Send up to this many bytes at once. They won't all fit in the
10218 remote packet limit, so we'll transfer slightly fewer. */
10219 io_size
= get_remote_packet_size ();
10220 buffer
= xmalloc (io_size
);
10221 make_cleanup (xfree
, buffer
);
10223 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10228 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
10230 /* Success, but no bytes, means end-of-file. */
10233 remote_hostio_error (remote_errno
);
10237 bytes
= fwrite (buffer
, 1, bytes
, file
);
10239 perror_with_name (local_file
);
10242 discard_cleanups (close_cleanup
);
10243 if (remote_hostio_close (fd
, &remote_errno
))
10244 remote_hostio_error (remote_errno
);
10247 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10248 do_cleanups (back_to
);
10252 remote_file_delete (const char *remote_file
, int from_tty
)
10254 int retcode
, remote_errno
;
10255 struct remote_state
*rs
= get_remote_state ();
10257 if (!rs
->remote_desc
)
10258 error (_("command can only be used with remote target"));
10260 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
10262 remote_hostio_error (remote_errno
);
10265 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10269 remote_put_command (char *args
, int from_tty
)
10271 struct cleanup
*back_to
;
10275 error_no_arg (_("file to put"));
10277 argv
= gdb_buildargv (args
);
10278 back_to
= make_cleanup_freeargv (argv
);
10279 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10280 error (_("Invalid parameters to remote put"));
10282 remote_file_put (argv
[0], argv
[1], from_tty
);
10284 do_cleanups (back_to
);
10288 remote_get_command (char *args
, int from_tty
)
10290 struct cleanup
*back_to
;
10294 error_no_arg (_("file to get"));
10296 argv
= gdb_buildargv (args
);
10297 back_to
= make_cleanup_freeargv (argv
);
10298 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10299 error (_("Invalid parameters to remote get"));
10301 remote_file_get (argv
[0], argv
[1], from_tty
);
10303 do_cleanups (back_to
);
10307 remote_delete_command (char *args
, int from_tty
)
10309 struct cleanup
*back_to
;
10313 error_no_arg (_("file to delete"));
10315 argv
= gdb_buildargv (args
);
10316 back_to
= make_cleanup_freeargv (argv
);
10317 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10318 error (_("Invalid parameters to remote delete"));
10320 remote_file_delete (argv
[0], from_tty
);
10322 do_cleanups (back_to
);
10326 remote_command (char *args
, int from_tty
)
10328 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
10332 remote_can_execute_reverse (void)
10334 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
10335 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
10342 remote_supports_non_stop (void)
10348 remote_supports_disable_randomization (void)
10350 /* Only supported in extended mode. */
10355 remote_supports_multi_process (void)
10357 struct remote_state
*rs
= get_remote_state ();
10359 /* Only extended-remote handles being attached to multiple
10360 processes, even though plain remote can use the multi-process
10361 thread id extensions, so that GDB knows the target process's
10363 return rs
->extended
&& remote_multi_process_p (rs
);
10367 remote_supports_cond_tracepoints (void)
10369 struct remote_state
*rs
= get_remote_state ();
10371 return rs
->cond_tracepoints
;
10375 remote_supports_cond_breakpoints (void)
10377 struct remote_state
*rs
= get_remote_state ();
10379 return rs
->cond_breakpoints
;
10383 remote_supports_fast_tracepoints (void)
10385 struct remote_state
*rs
= get_remote_state ();
10387 return rs
->fast_tracepoints
;
10391 remote_supports_static_tracepoints (void)
10393 struct remote_state
*rs
= get_remote_state ();
10395 return rs
->static_tracepoints
;
10399 remote_supports_install_in_trace (void)
10401 struct remote_state
*rs
= get_remote_state ();
10403 return rs
->install_in_trace
;
10407 remote_supports_enable_disable_tracepoint (void)
10409 struct remote_state
*rs
= get_remote_state ();
10411 return rs
->enable_disable_tracepoints
;
10415 remote_supports_string_tracing (void)
10417 struct remote_state
*rs
= get_remote_state ();
10419 return rs
->string_tracing
;
10423 remote_can_run_breakpoint_commands (void)
10425 struct remote_state
*rs
= get_remote_state ();
10427 return rs
->breakpoint_commands
;
10431 remote_trace_init (void)
10434 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10435 if (strcmp (target_buf
, "OK") != 0)
10436 error (_("Target does not support this command."));
10439 static void free_actions_list (char **actions_list
);
10440 static void free_actions_list_cleanup_wrapper (void *);
10442 free_actions_list_cleanup_wrapper (void *al
)
10444 free_actions_list (al
);
10448 free_actions_list (char **actions_list
)
10452 if (actions_list
== 0)
10455 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10456 xfree (actions_list
[ndx
]);
10458 xfree (actions_list
);
10461 /* Recursive routine to walk through command list including loops, and
10462 download packets for each command. */
10465 remote_download_command_source (int num
, ULONGEST addr
,
10466 struct command_line
*cmds
)
10468 struct remote_state
*rs
= get_remote_state ();
10469 struct command_line
*cmd
;
10471 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10473 QUIT
; /* Allow user to bail out with ^C. */
10474 strcpy (rs
->buf
, "QTDPsrc:");
10475 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10476 rs
->buf
+ strlen (rs
->buf
),
10477 rs
->buf_size
- strlen (rs
->buf
));
10479 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10480 if (strcmp (target_buf
, "OK"))
10481 warning (_("Target does not support source download."));
10483 if (cmd
->control_type
== while_control
10484 || cmd
->control_type
== while_stepping_control
)
10486 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10488 QUIT
; /* Allow user to bail out with ^C. */
10489 strcpy (rs
->buf
, "QTDPsrc:");
10490 encode_source_string (num
, addr
, "cmd", "end",
10491 rs
->buf
+ strlen (rs
->buf
),
10492 rs
->buf_size
- strlen (rs
->buf
));
10494 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10495 if (strcmp (target_buf
, "OK"))
10496 warning (_("Target does not support source download."));
10502 remote_download_tracepoint (struct bp_location
*loc
)
10504 #define BUF_SIZE 2048
10508 char buf
[BUF_SIZE
];
10509 char **tdp_actions
;
10510 char **stepping_actions
;
10512 struct cleanup
*old_chain
= NULL
;
10513 struct agent_expr
*aexpr
;
10514 struct cleanup
*aexpr_chain
= NULL
;
10516 struct breakpoint
*b
= loc
->owner
;
10517 struct tracepoint
*t
= (struct tracepoint
*) b
;
10519 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
10520 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10522 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10525 tpaddr
= loc
->address
;
10526 sprintf_vma (addrbuf
, tpaddr
);
10527 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10528 addrbuf
, /* address */
10529 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10530 t
->step_count
, t
->pass_count
);
10531 /* Fast tracepoints are mostly handled by the target, but we can
10532 tell the target how big of an instruction block should be moved
10534 if (b
->type
== bp_fast_tracepoint
)
10536 /* Only test for support at download time; we may not know
10537 target capabilities at definition time. */
10538 if (remote_supports_fast_tracepoints ())
10542 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10543 tpaddr
, &isize
, NULL
))
10544 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10547 /* If it passed validation at definition but fails now,
10548 something is very wrong. */
10549 internal_error (__FILE__
, __LINE__
,
10550 _("Fast tracepoint not "
10551 "valid during download"));
10554 /* Fast tracepoints are functionally identical to regular
10555 tracepoints, so don't take lack of support as a reason to
10556 give up on the trace run. */
10557 warning (_("Target does not support fast tracepoints, "
10558 "downloading %d as regular tracepoint"), b
->number
);
10560 else if (b
->type
== bp_static_tracepoint
)
10562 /* Only test for support at download time; we may not know
10563 target capabilities at definition time. */
10564 if (remote_supports_static_tracepoints ())
10566 struct static_tracepoint_marker marker
;
10568 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10569 strcat (buf
, ":S");
10571 error (_("Static tracepoint not valid during download"));
10574 /* Fast tracepoints are functionally identical to regular
10575 tracepoints, so don't take lack of support as a reason
10576 to give up on the trace run. */
10577 error (_("Target does not support static tracepoints"));
10579 /* If the tracepoint has a conditional, make it into an agent
10580 expression and append to the definition. */
10583 /* Only test support at download time, we may not know target
10584 capabilities at definition time. */
10585 if (remote_supports_cond_tracepoints ())
10587 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10588 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10589 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10591 pkt
= buf
+ strlen (buf
);
10592 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10593 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10595 do_cleanups (aexpr_chain
);
10598 warning (_("Target does not support conditional tracepoints, "
10599 "ignoring tp %d cond"), b
->number
);
10602 if (b
->commands
|| *default_collect
)
10605 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10606 if (strcmp (target_buf
, "OK"))
10607 error (_("Target does not support tracepoints."));
10609 /* do_single_steps (t); */
10612 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10614 QUIT
; /* Allow user to bail out with ^C. */
10615 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10616 b
->number
, addrbuf
, /* address */
10618 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10621 remote_get_noisy_reply (&target_buf
,
10623 if (strcmp (target_buf
, "OK"))
10624 error (_("Error on target while setting tracepoints."));
10627 if (stepping_actions
)
10629 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10631 QUIT
; /* Allow user to bail out with ^C. */
10632 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10633 b
->number
, addrbuf
, /* address */
10634 ((ndx
== 0) ? "S" : ""),
10635 stepping_actions
[ndx
],
10636 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10638 remote_get_noisy_reply (&target_buf
,
10640 if (strcmp (target_buf
, "OK"))
10641 error (_("Error on target while setting tracepoints."));
10645 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10648 if (b
->addr_string
)
10650 strcpy (buf
, "QTDPsrc:");
10651 encode_source_string (b
->number
, loc
->address
,
10652 "at", b
->addr_string
, buf
+ strlen (buf
),
10653 2048 - strlen (buf
));
10656 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10657 if (strcmp (target_buf
, "OK"))
10658 warning (_("Target does not support source download."));
10660 if (b
->cond_string
)
10662 strcpy (buf
, "QTDPsrc:");
10663 encode_source_string (b
->number
, loc
->address
,
10664 "cond", b
->cond_string
, buf
+ strlen (buf
),
10665 2048 - strlen (buf
));
10667 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10668 if (strcmp (target_buf
, "OK"))
10669 warning (_("Target does not support source download."));
10671 remote_download_command_source (b
->number
, loc
->address
,
10672 breakpoint_commands (b
));
10675 do_cleanups (old_chain
);
10679 remote_can_download_tracepoint (void)
10681 struct remote_state
*rs
= get_remote_state ();
10682 struct trace_status
*ts
;
10685 /* Don't try to install tracepoints until we've relocated our
10686 symbols, and fetched and merged the target's tracepoint list with
10688 if (rs
->starting_up
)
10691 ts
= current_trace_status ();
10692 status
= remote_get_trace_status (ts
);
10694 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10697 /* If we are in a tracing experiment, but remote stub doesn't support
10698 installing tracepoint in trace, we have to return. */
10699 if (!remote_supports_install_in_trace ())
10707 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10709 struct remote_state
*rs
= get_remote_state ();
10712 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10713 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10715 p
= rs
->buf
+ strlen (rs
->buf
);
10716 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10717 error (_("Trace state variable name too long for tsv definition packet"));
10718 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10721 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10722 if (*target_buf
== '\0')
10723 error (_("Target does not support this command."));
10724 if (strcmp (target_buf
, "OK") != 0)
10725 error (_("Error on target while downloading trace state variable."));
10729 remote_enable_tracepoint (struct bp_location
*location
)
10731 struct remote_state
*rs
= get_remote_state ();
10734 sprintf_vma (addr_buf
, location
->address
);
10735 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10736 location
->owner
->number
, addr_buf
);
10738 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10739 if (*rs
->buf
== '\0')
10740 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10741 if (strcmp (rs
->buf
, "OK") != 0)
10742 error (_("Error on target while enabling tracepoint."));
10746 remote_disable_tracepoint (struct bp_location
*location
)
10748 struct remote_state
*rs
= get_remote_state ();
10751 sprintf_vma (addr_buf
, location
->address
);
10752 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10753 location
->owner
->number
, addr_buf
);
10755 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10756 if (*rs
->buf
== '\0')
10757 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10758 if (strcmp (rs
->buf
, "OK") != 0)
10759 error (_("Error on target while disabling tracepoint."));
10763 remote_trace_set_readonly_regions (void)
10767 bfd_size_type size
;
10773 return; /* No information to give. */
10775 strcpy (target_buf
, "QTro");
10776 offset
= strlen (target_buf
);
10777 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10779 char tmp1
[40], tmp2
[40];
10782 if ((s
->flags
& SEC_LOAD
) == 0 ||
10783 /* (s->flags & SEC_CODE) == 0 || */
10784 (s
->flags
& SEC_READONLY
) == 0)
10788 vma
= bfd_get_section_vma (abfd
, s
);
10789 size
= bfd_get_section_size (s
);
10790 sprintf_vma (tmp1
, vma
);
10791 sprintf_vma (tmp2
, vma
+ size
);
10792 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10793 if (offset
+ sec_length
+ 1 > target_buf_size
)
10795 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10798 Too many sections for read-only sections definition packet."));
10801 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10803 offset
+= sec_length
;
10807 putpkt (target_buf
);
10808 getpkt (&target_buf
, &target_buf_size
, 0);
10813 remote_trace_start (void)
10815 putpkt ("QTStart");
10816 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10817 if (*target_buf
== '\0')
10818 error (_("Target does not support this command."));
10819 if (strcmp (target_buf
, "OK") != 0)
10820 error (_("Bogus reply from target: %s"), target_buf
);
10824 remote_get_trace_status (struct trace_status
*ts
)
10826 /* Initialize it just to avoid a GCC false warning. */
10828 /* FIXME we need to get register block size some other way. */
10829 extern int trace_regblock_size
;
10830 volatile struct gdb_exception ex
;
10831 enum packet_result result
;
10833 if (remote_protocol_packets
[PACKET_qTStatus
].support
== PACKET_DISABLE
)
10836 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10838 putpkt ("qTStatus");
10840 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10842 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10846 if (ex
.error
!= TARGET_CLOSE_ERROR
)
10848 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10851 throw_exception (ex
);
10854 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
10856 /* If the remote target doesn't do tracing, flag it. */
10857 if (result
== PACKET_UNKNOWN
)
10860 /* We're working with a live target. */
10861 ts
->filename
= NULL
;
10864 error (_("Bogus trace status reply from target: %s"), target_buf
);
10866 /* Function 'parse_trace_status' sets default value of each field of
10867 'ts' at first, so we don't have to do it here. */
10868 parse_trace_status (p
, ts
);
10870 return ts
->running
;
10874 remote_get_tracepoint_status (struct breakpoint
*bp
,
10875 struct uploaded_tp
*utp
)
10877 struct remote_state
*rs
= get_remote_state ();
10879 struct bp_location
*loc
;
10880 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10881 size_t size
= get_remote_packet_size ();
10885 tp
->base
.hit_count
= 0;
10886 tp
->traceframe_usage
= 0;
10887 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10889 /* If the tracepoint was never downloaded, don't go asking for
10891 if (tp
->number_on_target
== 0)
10893 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10894 phex_nz (loc
->address
, 0));
10896 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10897 if (reply
&& *reply
)
10900 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10906 utp
->hit_count
= 0;
10907 utp
->traceframe_usage
= 0;
10908 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10909 phex_nz (utp
->addr
, 0));
10911 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10912 if (reply
&& *reply
)
10915 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10921 remote_trace_stop (void)
10924 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10925 if (*target_buf
== '\0')
10926 error (_("Target does not support this command."));
10927 if (strcmp (target_buf
, "OK") != 0)
10928 error (_("Bogus reply from target: %s"), target_buf
);
10932 remote_trace_find (enum trace_find_type type
, int num
,
10933 CORE_ADDR addr1
, CORE_ADDR addr2
,
10936 struct remote_state
*rs
= get_remote_state ();
10937 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10939 int target_frameno
= -1, target_tracept
= -1;
10941 /* Lookups other than by absolute frame number depend on the current
10942 trace selected, so make sure it is correct on the remote end
10944 if (type
!= tfind_number
)
10945 set_remote_traceframe ();
10948 strcpy (p
, "QTFrame:");
10949 p
= strchr (p
, '\0');
10953 xsnprintf (p
, endbuf
- p
, "%x", num
);
10956 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
10959 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
10962 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
10963 phex_nz (addr2
, 0));
10965 case tfind_outside
:
10966 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
10967 phex_nz (addr2
, 0));
10970 error (_("Unknown trace find type %d"), type
);
10974 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10975 if (*reply
== '\0')
10976 error (_("Target does not support this command."));
10978 while (reply
&& *reply
)
10983 target_frameno
= (int) strtol (p
, &reply
, 16);
10985 error (_("Unable to parse trace frame number"));
10986 /* Don't update our remote traceframe number cache on failure
10987 to select a remote traceframe. */
10988 if (target_frameno
== -1)
10993 target_tracept
= (int) strtol (p
, &reply
, 16);
10995 error (_("Unable to parse tracepoint number"));
10997 case 'O': /* "OK"? */
10998 if (reply
[1] == 'K' && reply
[2] == '\0')
11001 error (_("Bogus reply from target: %s"), reply
);
11004 error (_("Bogus reply from target: %s"), reply
);
11007 *tpp
= target_tracept
;
11009 rs
->remote_traceframe_number
= target_frameno
;
11010 return target_frameno
;
11014 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
11016 struct remote_state
*rs
= get_remote_state ();
11020 set_remote_traceframe ();
11022 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
11024 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11025 if (reply
&& *reply
)
11029 unpack_varlen_hex (reply
+ 1, &uval
);
11030 *val
= (LONGEST
) uval
;
11038 remote_save_trace_data (const char *filename
)
11040 struct remote_state
*rs
= get_remote_state ();
11044 strcpy (p
, "QTSave:");
11046 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
11047 error (_("Remote file name too long for trace save packet"));
11048 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
11051 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11052 if (*reply
== '\0')
11053 error (_("Target does not support this command."));
11054 if (strcmp (reply
, "OK") != 0)
11055 error (_("Bogus reply from target: %s"), reply
);
11059 /* This is basically a memory transfer, but needs to be its own packet
11060 because we don't know how the target actually organizes its trace
11061 memory, plus we want to be able to ask for as much as possible, but
11062 not be unhappy if we don't get as much as we ask for. */
11065 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11067 struct remote_state
*rs
= get_remote_state ();
11073 strcpy (p
, "qTBuffer:");
11075 p
+= hexnumstr (p
, offset
);
11077 p
+= hexnumstr (p
, len
);
11081 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11082 if (reply
&& *reply
)
11084 /* 'l' by itself means we're at the end of the buffer and
11085 there is nothing more to get. */
11089 /* Convert the reply into binary. Limit the number of bytes to
11090 convert according to our passed-in buffer size, rather than
11091 what was returned in the packet; if the target is
11092 unexpectedly generous and gives us a bigger reply than we
11093 asked for, we don't want to crash. */
11094 rslt
= hex2bin (target_buf
, buf
, len
);
11098 /* Something went wrong, flag as an error. */
11103 remote_set_disconnected_tracing (int val
)
11105 struct remote_state
*rs
= get_remote_state ();
11107 if (rs
->disconnected_tracing
)
11111 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11113 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11114 if (*reply
== '\0')
11115 error (_("Target does not support this command."));
11116 if (strcmp (reply
, "OK") != 0)
11117 error (_("Bogus reply from target: %s"), reply
);
11120 warning (_("Target does not support disconnected tracing."));
11124 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11126 struct thread_info
*info
= find_thread_ptid (ptid
);
11128 if (info
&& info
->private)
11129 return info
->private->core
;
11134 remote_set_circular_trace_buffer (int val
)
11136 struct remote_state
*rs
= get_remote_state ();
11139 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11141 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11142 if (*reply
== '\0')
11143 error (_("Target does not support this command."));
11144 if (strcmp (reply
, "OK") != 0)
11145 error (_("Bogus reply from target: %s"), reply
);
11148 static struct traceframe_info
*
11149 remote_traceframe_info (void)
11153 text
= target_read_stralloc (¤t_target
,
11154 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11157 struct traceframe_info
*info
;
11158 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11160 info
= parse_traceframe_info (text
);
11161 do_cleanups (back_to
);
11168 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11169 instruction on which a fast tracepoint may be placed. Returns -1
11170 if the packet is not supported, and 0 if the minimum instruction
11171 length is unknown. */
11174 remote_get_min_fast_tracepoint_insn_len (void)
11176 struct remote_state
*rs
= get_remote_state ();
11179 /* If we're not debugging a process yet, the IPA can't be
11181 if (!target_has_execution
)
11184 /* Make sure the remote is pointing at the right process. */
11185 set_general_process ();
11187 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11189 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11190 if (*reply
== '\0')
11194 ULONGEST min_insn_len
;
11196 unpack_varlen_hex (reply
, &min_insn_len
);
11198 return (int) min_insn_len
;
11203 remote_set_trace_buffer_size (LONGEST val
)
11205 if (remote_protocol_packets
[PACKET_QTBuffer_size
].support
11208 struct remote_state
*rs
= get_remote_state ();
11209 char *buf
= rs
->buf
;
11210 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11211 enum packet_result result
;
11213 gdb_assert (val
>= 0 || val
== -1);
11214 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11215 /* Send -1 as literal "-1" to avoid host size dependency. */
11219 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11222 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11225 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11226 result
= packet_ok (rs
->buf
,
11227 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11229 if (result
!= PACKET_OK
)
11230 warning (_("Bogus reply from target: %s"), rs
->buf
);
11235 remote_set_trace_notes (const char *user
, const char *notes
,
11236 const char *stop_notes
)
11238 struct remote_state
*rs
= get_remote_state ();
11240 char *buf
= rs
->buf
;
11241 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11244 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11247 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11248 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, 0);
11254 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11255 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, 0);
11261 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11262 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, 0);
11266 /* Ensure the buffer is terminated. */
11270 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11271 if (*reply
== '\0')
11274 if (strcmp (reply
, "OK") != 0)
11275 error (_("Bogus reply from target: %s"), reply
);
11281 remote_use_agent (int use
)
11283 if (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
)
11285 struct remote_state
*rs
= get_remote_state ();
11287 /* If the stub supports QAgent. */
11288 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11290 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11292 if (strcmp (rs
->buf
, "OK") == 0)
11303 remote_can_use_agent (void)
11305 return (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
);
11308 struct btrace_target_info
11310 /* The ptid of the traced thread. */
11314 /* Check whether the target supports branch tracing. */
11317 remote_supports_btrace (void)
11319 if (remote_protocol_packets
[PACKET_Qbtrace_off
].support
!= PACKET_ENABLE
)
11321 if (remote_protocol_packets
[PACKET_Qbtrace_bts
].support
!= PACKET_ENABLE
)
11323 if (remote_protocol_packets
[PACKET_qXfer_btrace
].support
!= PACKET_ENABLE
)
11329 /* Enable branch tracing. */
11331 static struct btrace_target_info
*
11332 remote_enable_btrace (ptid_t ptid
)
11334 struct btrace_target_info
*tinfo
= NULL
;
11335 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
11336 struct remote_state
*rs
= get_remote_state ();
11337 char *buf
= rs
->buf
;
11338 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11340 if (packet
->support
!= PACKET_ENABLE
)
11341 error (_("Target does not support branch tracing."));
11343 set_general_thread (ptid
);
11345 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11347 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11349 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11351 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11352 error (_("Could not enable branch tracing for %s: %s"),
11353 target_pid_to_str (ptid
), rs
->buf
+ 2);
11355 error (_("Could not enable branch tracing for %s."),
11356 target_pid_to_str (ptid
));
11359 tinfo
= xzalloc (sizeof (*tinfo
));
11360 tinfo
->ptid
= ptid
;
11365 /* Disable branch tracing. */
11368 remote_disable_btrace (struct btrace_target_info
*tinfo
)
11370 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
11371 struct remote_state
*rs
= get_remote_state ();
11372 char *buf
= rs
->buf
;
11373 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11375 if (packet
->support
!= PACKET_ENABLE
)
11376 error (_("Target does not support branch tracing."));
11378 set_general_thread (tinfo
->ptid
);
11380 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11382 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11384 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11386 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11387 error (_("Could not disable branch tracing for %s: %s"),
11388 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
11390 error (_("Could not disable branch tracing for %s."),
11391 target_pid_to_str (tinfo
->ptid
));
11397 /* Teardown branch tracing. */
11400 remote_teardown_btrace (struct btrace_target_info
*tinfo
)
11402 /* We must not talk to the target during teardown. */
11406 /* Read the branch trace. */
11408 static VEC (btrace_block_s
) *
11409 remote_read_btrace (struct btrace_target_info
*tinfo
,
11410 enum btrace_read_type type
)
11412 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
11413 struct remote_state
*rs
= get_remote_state ();
11414 VEC (btrace_block_s
) *btrace
= NULL
;
11418 if (packet
->support
!= PACKET_ENABLE
)
11419 error (_("Target does not support branch tracing."));
11421 #if !defined(HAVE_LIBEXPAT)
11422 error (_("Cannot process branch tracing result. XML parsing not supported."));
11427 case btrace_read_all
:
11430 case btrace_read_new
:
11434 internal_error (__FILE__
, __LINE__
,
11435 _("Bad branch tracing read type: %u."),
11436 (unsigned int) type
);
11439 xml
= target_read_stralloc (¤t_target
,
11440 TARGET_OBJECT_BTRACE
, annex
);
11443 struct cleanup
*cleanup
= make_cleanup (xfree
, xml
);
11445 btrace
= parse_xml_btrace (xml
);
11446 do_cleanups (cleanup
);
11453 remote_augmented_libraries_svr4_read (void)
11455 struct remote_state
*rs
= get_remote_state ();
11457 return rs
->augmented_libraries_svr4_read
;
11461 init_remote_ops (void)
11463 remote_ops
.to_shortname
= "remote";
11464 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11465 remote_ops
.to_doc
=
11466 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11467 Specify the serial device it is connected to\n\
11468 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11469 remote_ops
.to_open
= remote_open
;
11470 remote_ops
.to_close
= remote_close
;
11471 remote_ops
.to_detach
= remote_detach
;
11472 remote_ops
.to_disconnect
= remote_disconnect
;
11473 remote_ops
.to_resume
= remote_resume
;
11474 remote_ops
.to_wait
= remote_wait
;
11475 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11476 remote_ops
.to_store_registers
= remote_store_registers
;
11477 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11478 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
11479 remote_ops
.to_files_info
= remote_files_info
;
11480 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11481 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11482 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11483 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11484 remote_ops
.to_watchpoint_addr_within_range
=
11485 remote_watchpoint_addr_within_range
;
11486 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11487 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11488 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11489 remote_ops
.to_region_ok_for_hw_watchpoint
11490 = remote_region_ok_for_hw_watchpoint
;
11491 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11492 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11493 remote_ops
.to_kill
= remote_kill
;
11494 remote_ops
.to_load
= generic_load
;
11495 remote_ops
.to_mourn_inferior
= remote_mourn
;
11496 remote_ops
.to_pass_signals
= remote_pass_signals
;
11497 remote_ops
.to_program_signals
= remote_program_signals
;
11498 remote_ops
.to_thread_alive
= remote_thread_alive
;
11499 remote_ops
.to_find_new_threads
= remote_threads_info
;
11500 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11501 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11502 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11503 remote_ops
.to_stop
= remote_stop
;
11504 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11505 remote_ops
.to_rcmd
= remote_rcmd
;
11506 remote_ops
.to_log_command
= serial_log_command
;
11507 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11508 remote_ops
.to_stratum
= process_stratum
;
11509 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11510 remote_ops
.to_has_memory
= default_child_has_memory
;
11511 remote_ops
.to_has_stack
= default_child_has_stack
;
11512 remote_ops
.to_has_registers
= default_child_has_registers
;
11513 remote_ops
.to_has_execution
= default_child_has_execution
;
11514 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11515 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11516 remote_ops
.to_magic
= OPS_MAGIC
;
11517 remote_ops
.to_memory_map
= remote_memory_map
;
11518 remote_ops
.to_flash_erase
= remote_flash_erase
;
11519 remote_ops
.to_flash_done
= remote_flash_done
;
11520 remote_ops
.to_read_description
= remote_read_description
;
11521 remote_ops
.to_search_memory
= remote_search_memory
;
11522 remote_ops
.to_can_async_p
= remote_can_async_p
;
11523 remote_ops
.to_is_async_p
= remote_is_async_p
;
11524 remote_ops
.to_async
= remote_async
;
11525 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11526 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11527 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11528 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11529 remote_ops
.to_supports_disable_randomization
11530 = remote_supports_disable_randomization
;
11531 remote_ops
.to_fileio_open
= remote_hostio_open
;
11532 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11533 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11534 remote_ops
.to_fileio_close
= remote_hostio_close
;
11535 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11536 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11537 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11538 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11539 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11540 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11541 remote_ops
.to_trace_init
= remote_trace_init
;
11542 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11543 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11544 remote_ops
.to_download_trace_state_variable
11545 = remote_download_trace_state_variable
;
11546 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11547 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11548 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11549 remote_ops
.to_trace_start
= remote_trace_start
;
11550 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11551 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11552 remote_ops
.to_trace_stop
= remote_trace_stop
;
11553 remote_ops
.to_trace_find
= remote_trace_find
;
11554 remote_ops
.to_get_trace_state_variable_value
11555 = remote_get_trace_state_variable_value
;
11556 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11557 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11558 remote_ops
.to_upload_trace_state_variables
11559 = remote_upload_trace_state_variables
;
11560 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11561 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11562 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11563 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11564 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
11565 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11566 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11567 remote_ops
.to_verify_memory
= remote_verify_memory
;
11568 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11569 remote_ops
.to_set_permissions
= remote_set_permissions
;
11570 remote_ops
.to_static_tracepoint_marker_at
11571 = remote_static_tracepoint_marker_at
;
11572 remote_ops
.to_static_tracepoint_markers_by_strid
11573 = remote_static_tracepoint_markers_by_strid
;
11574 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11575 remote_ops
.to_use_agent
= remote_use_agent
;
11576 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11577 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
11578 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
11579 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
11580 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
11581 remote_ops
.to_read_btrace
= remote_read_btrace
;
11582 remote_ops
.to_augmented_libraries_svr4_read
=
11583 remote_augmented_libraries_svr4_read
;
11586 /* Set up the extended remote vector by making a copy of the standard
11587 remote vector and adding to it. */
11590 init_extended_remote_ops (void)
11592 extended_remote_ops
= remote_ops
;
11594 extended_remote_ops
.to_shortname
= "extended-remote";
11595 extended_remote_ops
.to_longname
=
11596 "Extended remote serial target in gdb-specific protocol";
11597 extended_remote_ops
.to_doc
=
11598 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11599 Specify the serial device it is connected to (e.g. /dev/ttya).";
11600 extended_remote_ops
.to_open
= extended_remote_open
;
11601 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11602 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11603 extended_remote_ops
.to_detach
= extended_remote_detach
;
11604 extended_remote_ops
.to_attach
= extended_remote_attach
;
11605 extended_remote_ops
.to_kill
= extended_remote_kill
;
11606 extended_remote_ops
.to_supports_disable_randomization
11607 = extended_remote_supports_disable_randomization
;
11611 remote_can_async_p (void)
11613 struct remote_state
*rs
= get_remote_state ();
11615 if (!target_async_permitted
)
11616 /* We only enable async when the user specifically asks for it. */
11619 /* We're async whenever the serial device is. */
11620 return serial_can_async_p (rs
->remote_desc
);
11624 remote_is_async_p (void)
11626 struct remote_state
*rs
= get_remote_state ();
11628 if (!target_async_permitted
)
11629 /* We only enable async when the user specifically asks for it. */
11632 /* We're async whenever the serial device is. */
11633 return serial_is_async_p (rs
->remote_desc
);
11636 /* Pass the SERIAL event on and up to the client. One day this code
11637 will be able to delay notifying the client of an event until the
11638 point where an entire packet has been received. */
11640 static void (*async_client_callback
) (enum inferior_event_type event_type
,
11642 static void *async_client_context
;
11643 static serial_event_ftype remote_async_serial_handler
;
11646 remote_async_serial_handler (struct serial
*scb
, void *context
)
11648 /* Don't propogate error information up to the client. Instead let
11649 the client find out about the error by querying the target. */
11650 async_client_callback (INF_REG_EVENT
, async_client_context
);
11654 remote_async_inferior_event_handler (gdb_client_data data
)
11656 inferior_event_handler (INF_REG_EVENT
, NULL
);
11660 remote_async (void (*callback
) (enum inferior_event_type event_type
,
11661 void *context
), void *context
)
11663 struct remote_state
*rs
= get_remote_state ();
11665 if (callback
!= NULL
)
11667 serial_async (rs
->remote_desc
, remote_async_serial_handler
, NULL
);
11668 async_client_callback
= callback
;
11669 async_client_context
= context
;
11672 serial_async (rs
->remote_desc
, NULL
, NULL
);
11676 set_remote_cmd (char *args
, int from_tty
)
11678 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
11682 show_remote_cmd (char *args
, int from_tty
)
11684 /* We can't just use cmd_show_list here, because we want to skip
11685 the redundant "show remote Z-packet" and the legacy aliases. */
11686 struct cleanup
*showlist_chain
;
11687 struct cmd_list_element
*list
= remote_show_cmdlist
;
11688 struct ui_out
*uiout
= current_uiout
;
11690 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11691 for (; list
!= NULL
; list
= list
->next
)
11692 if (strcmp (list
->name
, "Z-packet") == 0)
11694 else if (list
->type
== not_set_cmd
)
11695 /* Alias commands are exactly like the original, except they
11696 don't have the normal type. */
11700 struct cleanup
*option_chain
11701 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11703 ui_out_field_string (uiout
, "name", list
->name
);
11704 ui_out_text (uiout
, ": ");
11705 if (list
->type
== show_cmd
)
11706 do_show_command ((char *) NULL
, from_tty
, list
);
11708 cmd_func (list
, NULL
, from_tty
);
11709 /* Close the tuple. */
11710 do_cleanups (option_chain
);
11713 /* Close the tuple. */
11714 do_cleanups (showlist_chain
);
11718 /* Function to be called whenever a new objfile (shlib) is detected. */
11720 remote_new_objfile (struct objfile
*objfile
)
11722 struct remote_state
*rs
= get_remote_state ();
11724 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
11725 remote_check_symbols ();
11728 /* Pull all the tracepoints defined on the target and create local
11729 data structures representing them. We don't want to create real
11730 tracepoints yet, we don't want to mess up the user's existing
11734 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
11736 struct remote_state
*rs
= get_remote_state ();
11739 /* Ask for a first packet of tracepoint definition. */
11741 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11743 while (*p
&& *p
!= 'l')
11745 parse_tracepoint_definition (p
, utpp
);
11746 /* Ask for another packet of tracepoint definition. */
11748 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11755 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
11757 struct remote_state
*rs
= get_remote_state ();
11760 /* Ask for a first packet of variable definition. */
11762 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11764 while (*p
&& *p
!= 'l')
11766 parse_tsv_definition (p
, utsvp
);
11767 /* Ask for another packet of variable definition. */
11769 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11775 /* The "set/show range-stepping" show hook. */
11778 show_range_stepping (struct ui_file
*file
, int from_tty
,
11779 struct cmd_list_element
*c
,
11782 fprintf_filtered (file
,
11783 _("Debugger's willingness to use range stepping "
11784 "is %s.\n"), value
);
11787 /* The "set/show range-stepping" set hook. */
11790 set_range_stepping (char *ignore_args
, int from_tty
,
11791 struct cmd_list_element
*c
)
11793 struct remote_state
*rs
= get_remote_state ();
11795 /* Whene enabling, check whether range stepping is actually
11796 supported by the target, and warn if not. */
11797 if (use_range_stepping
)
11799 if (rs
->remote_desc
!= NULL
)
11801 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
11802 remote_vcont_probe (rs
);
11804 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_ENABLE
11805 && rs
->supports_vCont
.r
)
11809 warning (_("Range stepping is not supported by the current target"));
11814 _initialize_remote (void)
11816 struct remote_state
*rs
;
11817 struct cmd_list_element
*cmd
;
11818 const char *cmd_name
;
11820 /* architecture specific data */
11821 remote_gdbarch_data_handle
=
11822 gdbarch_data_register_post_init (init_remote_state
);
11823 remote_g_packet_data_handle
=
11824 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
11826 /* Initialize the per-target state. At the moment there is only one
11827 of these, not one per target. Only one target is active at a
11829 remote_state
= new_remote_state ();
11831 init_remote_ops ();
11832 add_target (&remote_ops
);
11834 init_extended_remote_ops ();
11835 add_target (&extended_remote_ops
);
11837 /* Hook into new objfile notification. */
11838 observer_attach_new_objfile (remote_new_objfile
);
11839 /* We're no longer interested in notification events of an inferior
11841 observer_attach_inferior_exit (discard_pending_stop_replies
);
11843 /* Set up signal handlers. */
11844 async_sigint_remote_token
=
11845 create_async_signal_handler (async_remote_interrupt
, NULL
);
11846 async_sigint_remote_twice_token
=
11847 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11850 init_remote_threadtests ();
11853 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
11854 /* set/show remote ... */
11856 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11857 Remote protocol specific variables\n\
11858 Configure various remote-protocol specific variables such as\n\
11859 the packets being used"),
11860 &remote_set_cmdlist
, "set remote ",
11861 0 /* allow-unknown */, &setlist
);
11862 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11863 Remote protocol specific variables\n\
11864 Configure various remote-protocol specific variables such as\n\
11865 the packets being used"),
11866 &remote_show_cmdlist
, "show remote ",
11867 0 /* allow-unknown */, &showlist
);
11869 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11870 Compare section data on target to the exec file.\n\
11871 Argument is a single section name (default: all loaded sections)."),
11874 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11875 Send an arbitrary packet to a remote target.\n\
11876 maintenance packet TEXT\n\
11877 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11878 this command sends the string TEXT to the inferior, and displays the\n\
11879 response packet. GDB supplies the initial `$' character, and the\n\
11880 terminating `#' character and checksum."),
11883 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11884 Set whether to send break if interrupted."), _("\
11885 Show whether to send break if interrupted."), _("\
11886 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11887 set_remotebreak
, show_remotebreak
,
11888 &setlist
, &showlist
);
11889 cmd_name
= "remotebreak";
11890 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11891 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11892 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11893 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11894 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11896 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11897 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11899 Set interrupt sequence to remote target."), _("\
11900 Show interrupt sequence to remote target."), _("\
11901 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11902 NULL
, show_interrupt_sequence
,
11903 &remote_set_cmdlist
,
11904 &remote_show_cmdlist
);
11906 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11907 &interrupt_on_connect
, _("\
11908 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11909 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11910 If set, interrupt sequence is sent to remote target."),
11912 &remote_set_cmdlist
, &remote_show_cmdlist
);
11914 /* Install commands for configuring memory read/write packets. */
11916 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11917 Set the maximum number of bytes per memory write packet (deprecated)."),
11919 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11920 Show the maximum number of bytes per memory write packet (deprecated)."),
11922 add_cmd ("memory-write-packet-size", no_class
,
11923 set_memory_write_packet_size
, _("\
11924 Set the maximum number of bytes per memory-write packet.\n\
11925 Specify the number of bytes in a packet or 0 (zero) for the\n\
11926 default packet size. The actual limit is further reduced\n\
11927 dependent on the target. Specify ``fixed'' to disable the\n\
11928 further restriction and ``limit'' to enable that restriction."),
11929 &remote_set_cmdlist
);
11930 add_cmd ("memory-read-packet-size", no_class
,
11931 set_memory_read_packet_size
, _("\
11932 Set the maximum number of bytes per memory-read packet.\n\
11933 Specify the number of bytes in a packet or 0 (zero) for the\n\
11934 default packet size. The actual limit is further reduced\n\
11935 dependent on the target. Specify ``fixed'' to disable the\n\
11936 further restriction and ``limit'' to enable that restriction."),
11937 &remote_set_cmdlist
);
11938 add_cmd ("memory-write-packet-size", no_class
,
11939 show_memory_write_packet_size
,
11940 _("Show the maximum number of bytes per memory-write packet."),
11941 &remote_show_cmdlist
);
11942 add_cmd ("memory-read-packet-size", no_class
,
11943 show_memory_read_packet_size
,
11944 _("Show the maximum number of bytes per memory-read packet."),
11945 &remote_show_cmdlist
);
11947 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11948 &remote_hw_watchpoint_limit
, _("\
11949 Set the maximum number of target hardware watchpoints."), _("\
11950 Show the maximum number of target hardware watchpoints."), _("\
11951 Specify a negative limit for unlimited."),
11952 NULL
, NULL
, /* FIXME: i18n: The maximum
11953 number of target hardware
11954 watchpoints is %s. */
11955 &remote_set_cmdlist
, &remote_show_cmdlist
);
11956 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11957 &remote_hw_watchpoint_length_limit
, _("\
11958 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11959 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11960 Specify a negative limit for unlimited."),
11961 NULL
, NULL
, /* FIXME: i18n: The maximum
11962 length (in bytes) of a target
11963 hardware watchpoint is %s. */
11964 &remote_set_cmdlist
, &remote_show_cmdlist
);
11965 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11966 &remote_hw_breakpoint_limit
, _("\
11967 Set the maximum number of target hardware breakpoints."), _("\
11968 Show the maximum number of target hardware breakpoints."), _("\
11969 Specify a negative limit for unlimited."),
11970 NULL
, NULL
, /* FIXME: i18n: The maximum
11971 number of target hardware
11972 breakpoints is %s. */
11973 &remote_set_cmdlist
, &remote_show_cmdlist
);
11975 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
11976 &remote_address_size
, _("\
11977 Set the maximum size of the address (in bits) in a memory packet."), _("\
11978 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11980 NULL
, /* FIXME: i18n: */
11981 &setlist
, &showlist
);
11983 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11984 "X", "binary-download", 1);
11986 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11987 "vCont", "verbose-resume", 0);
11989 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11990 "QPassSignals", "pass-signals", 0);
11992 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
11993 "QProgramSignals", "program-signals", 0);
11995 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11996 "qSymbol", "symbol-lookup", 0);
11998 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11999 "P", "set-register", 1);
12001 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
12002 "p", "fetch-register", 1);
12004 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
12005 "Z0", "software-breakpoint", 0);
12007 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
12008 "Z1", "hardware-breakpoint", 0);
12010 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
12011 "Z2", "write-watchpoint", 0);
12013 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
12014 "Z3", "read-watchpoint", 0);
12016 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
12017 "Z4", "access-watchpoint", 0);
12019 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
12020 "qXfer:auxv:read", "read-aux-vector", 0);
12022 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
12023 "qXfer:features:read", "target-features", 0);
12025 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
12026 "qXfer:libraries:read", "library-info", 0);
12028 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
12029 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
12031 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
12032 "qXfer:memory-map:read", "memory-map", 0);
12034 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
12035 "qXfer:spu:read", "read-spu-object", 0);
12037 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
12038 "qXfer:spu:write", "write-spu-object", 0);
12040 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
12041 "qXfer:osdata:read", "osdata", 0);
12043 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
12044 "qXfer:threads:read", "threads", 0);
12046 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
12047 "qXfer:siginfo:read", "read-siginfo-object", 0);
12049 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
12050 "qXfer:siginfo:write", "write-siginfo-object", 0);
12052 add_packet_config_cmd
12053 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
12054 "qXfer:traceframe-info:read", "traceframe-info", 0);
12056 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
12057 "qXfer:uib:read", "unwind-info-block", 0);
12059 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
12060 "qGetTLSAddr", "get-thread-local-storage-address",
12063 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
12064 "qGetTIBAddr", "get-thread-information-block-address",
12067 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
12068 "bc", "reverse-continue", 0);
12070 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
12071 "bs", "reverse-step", 0);
12073 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
12074 "qSupported", "supported-packets", 0);
12076 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
12077 "qSearch:memory", "search-memory", 0);
12079 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
12080 "qTStatus", "trace-status", 0);
12082 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
12083 "vFile:open", "hostio-open", 0);
12085 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
12086 "vFile:pread", "hostio-pread", 0);
12088 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
12089 "vFile:pwrite", "hostio-pwrite", 0);
12091 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
12092 "vFile:close", "hostio-close", 0);
12094 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
12095 "vFile:unlink", "hostio-unlink", 0);
12097 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
12098 "vFile:readlink", "hostio-readlink", 0);
12100 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
12101 "vAttach", "attach", 0);
12103 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
12106 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
12107 "QStartNoAckMode", "noack", 0);
12109 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
12110 "vKill", "kill", 0);
12112 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
12113 "qAttached", "query-attached", 0);
12115 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
12116 "ConditionalTracepoints",
12117 "conditional-tracepoints", 0);
12119 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
12120 "ConditionalBreakpoints",
12121 "conditional-breakpoints", 0);
12123 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
12124 "BreakpointCommands",
12125 "breakpoint-commands", 0);
12127 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
12128 "FastTracepoints", "fast-tracepoints", 0);
12130 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
12131 "TracepointSource", "TracepointSource", 0);
12133 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
12134 "QAllow", "allow", 0);
12136 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
12137 "StaticTracepoints", "static-tracepoints", 0);
12139 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
12140 "InstallInTrace", "install-in-trace", 0);
12142 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
12143 "qXfer:statictrace:read", "read-sdata-object", 0);
12145 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
12146 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12148 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
12149 "QDisableRandomization", "disable-randomization", 0);
12151 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
12152 "QAgent", "agent", 0);
12154 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
12155 "QTBuffer:size", "trace-buffer-size", 0);
12157 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
12158 "Qbtrace:off", "disable-btrace", 0);
12160 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12161 "Qbtrace:bts", "enable-btrace", 0);
12163 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12164 "qXfer:btrace", "read-btrace", 0);
12166 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12167 Z sub-packet has its own set and show commands, but users may
12168 have sets to this variable in their .gdbinit files (or in their
12170 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
12171 &remote_Z_packet_detect
, _("\
12172 Set use of remote protocol `Z' packets"), _("\
12173 Show use of remote protocol `Z' packets "), _("\
12174 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12176 set_remote_protocol_Z_packet_cmd
,
12177 show_remote_protocol_Z_packet_cmd
,
12178 /* FIXME: i18n: Use of remote protocol
12179 `Z' packets is %s. */
12180 &remote_set_cmdlist
, &remote_show_cmdlist
);
12182 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
12183 Manipulate files on the remote system\n\
12184 Transfer files to and from the remote target system."),
12185 &remote_cmdlist
, "remote ",
12186 0 /* allow-unknown */, &cmdlist
);
12188 add_cmd ("put", class_files
, remote_put_command
,
12189 _("Copy a local file to the remote system."),
12192 add_cmd ("get", class_files
, remote_get_command
,
12193 _("Copy a remote file to the local system."),
12196 add_cmd ("delete", class_files
, remote_delete_command
,
12197 _("Delete a remote file."),
12200 remote_exec_file
= xstrdup ("");
12201 add_setshow_string_noescape_cmd ("exec-file", class_files
,
12202 &remote_exec_file
, _("\
12203 Set the remote pathname for \"run\""), _("\
12204 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
12205 &remote_set_cmdlist
, &remote_show_cmdlist
);
12207 add_setshow_boolean_cmd ("range-stepping", class_run
,
12208 &use_range_stepping
, _("\
12209 Enable or disable range stepping."), _("\
12210 Show whether target-assisted range stepping is enabled."), _("\
12211 If on, and the target supports it, when stepping a source line, GDB\n\
12212 tells the target to step the corresponding range of addresses itself instead\n\
12213 of issuing multiple single-steps. This speeds up source level\n\
12214 stepping. If off, GDB always issues single-steps, even if range\n\
12215 stepping is supported by the target. The default is on."),
12216 set_range_stepping
,
12217 show_range_stepping
,
12221 /* Eventually initialize fileio. See fileio.c */
12222 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
12224 /* Take advantage of the fact that the LWP field is not used, to tag
12225 special ptids with it set to != 0. */
12226 magic_null_ptid
= ptid_build (42000, 1, -1);
12227 not_sent_ptid
= ptid_build (42000, 1, -2);
12228 any_thread_ptid
= ptid_build (42000, 1, 0);
12230 target_buf_size
= 2048;
12231 target_buf
= xmalloc (target_buf_size
);