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
;
387 enum gdb_signal last_sent_signal
;
391 char *finished_object
;
392 char *finished_annex
;
393 ULONGEST finished_offset
;
396 /* Private data that we'll store in (struct thread_info)->private. */
397 struct private_thread_info
404 free_private_thread_info (struct private_thread_info
*info
)
410 /* Returns true if the multi-process extensions are in effect. */
412 remote_multi_process_p (struct remote_state
*rs
)
414 return rs
->multi_process_aware
;
417 /* This data could be associated with a target, but we do not always
418 have access to the current target when we need it, so for now it is
419 static. This will be fine for as long as only one target is in use
421 static struct remote_state
*remote_state
;
423 static struct remote_state
*
424 get_remote_state_raw (void)
429 /* Allocate a new struct remote_state with xmalloc, initialize it, and
432 static struct remote_state
*
433 new_remote_state (void)
435 struct remote_state
*result
= XCNEW (struct remote_state
);
437 /* The default buffer size is unimportant; it will be expanded
438 whenever a larger buffer is needed. */
439 result
->buf_size
= 400;
440 result
->buf
= xmalloc (result
->buf_size
);
441 result
->remote_traceframe_number
= -1;
442 result
->last_sent_signal
= GDB_SIGNAL_0
;
447 /* Description of the remote protocol for a given architecture. */
451 long offset
; /* Offset into G packet. */
452 long regnum
; /* GDB's internal register number. */
453 LONGEST pnum
; /* Remote protocol register number. */
454 int in_g_packet
; /* Always part of G packet. */
455 /* long size in bytes; == register_size (target_gdbarch (), regnum);
457 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
461 struct remote_arch_state
463 /* Description of the remote protocol registers. */
464 long sizeof_g_packet
;
466 /* Description of the remote protocol registers indexed by REGNUM
467 (making an array gdbarch_num_regs in size). */
468 struct packet_reg
*regs
;
470 /* This is the size (in chars) of the first response to the ``g''
471 packet. It is used as a heuristic when determining the maximum
472 size of memory-read and memory-write packets. A target will
473 typically only reserve a buffer large enough to hold the ``g''
474 packet. The size does not include packet overhead (headers and
476 long actual_register_packet_size
;
478 /* This is the maximum size (in chars) of a non read/write packet.
479 It is also used as a cap on the size of read/write packets. */
480 long remote_packet_size
;
483 long sizeof_pkt
= 2000;
485 /* Utility: generate error from an incoming stub packet. */
487 trace_error (char *buf
)
490 return; /* not an error msg */
493 case '1': /* malformed packet error */
494 if (*++buf
== '0') /* general case: */
495 error (_("remote.c: error in outgoing packet."));
497 error (_("remote.c: error in outgoing packet at field #%ld."),
498 strtol (buf
, NULL
, 16));
500 error (_("Target returns error code '%s'."), buf
);
504 /* Utility: wait for reply from stub, while accepting "O" packets. */
506 remote_get_noisy_reply (char **buf_p
,
509 do /* Loop on reply from remote stub. */
513 QUIT
; /* Allow user to bail out with ^C. */
514 getpkt (buf_p
, sizeof_buf
, 0);
518 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
521 CORE_ADDR from
, to
, org_to
;
523 int adjusted_size
= 0;
524 volatile struct gdb_exception ex
;
526 p
= buf
+ strlen ("qRelocInsn:");
527 pp
= unpack_varlen_hex (p
, &ul
);
529 error (_("invalid qRelocInsn packet: %s"), buf
);
533 unpack_varlen_hex (p
, &ul
);
538 TRY_CATCH (ex
, RETURN_MASK_ALL
)
540 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
544 adjusted_size
= to
- org_to
;
546 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
549 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
551 /* Propagate memory errors silently back to the target.
552 The stub may have limited the range of addresses we
553 can write to, for example. */
558 /* Something unexpectedly bad happened. Be verbose so
559 we can tell what, and propagate the error back to the
560 stub, so it doesn't get stuck waiting for a
562 exception_fprintf (gdb_stderr
, ex
,
563 _("warning: relocating instruction: "));
567 else if (buf
[0] == 'O' && buf
[1] != 'K')
568 remote_console_output (buf
+ 1); /* 'O' message from stub */
570 return buf
; /* Here's the actual reply. */
575 /* Handle for retreving the remote protocol data from gdbarch. */
576 static struct gdbarch_data
*remote_gdbarch_data_handle
;
578 static struct remote_arch_state
*
579 get_remote_arch_state (void)
581 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
584 /* Fetch the global remote target state. */
586 static struct remote_state
*
587 get_remote_state (void)
589 /* Make sure that the remote architecture state has been
590 initialized, because doing so might reallocate rs->buf. Any
591 function which calls getpkt also needs to be mindful of changes
592 to rs->buf, but this call limits the number of places which run
594 get_remote_arch_state ();
596 return get_remote_state_raw ();
600 compare_pnums (const void *lhs_
, const void *rhs_
)
602 const struct packet_reg
* const *lhs
= lhs_
;
603 const struct packet_reg
* const *rhs
= rhs_
;
605 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
607 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
614 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
616 int regnum
, num_remote_regs
, offset
;
617 struct packet_reg
**remote_regs
;
619 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
621 struct packet_reg
*r
= ®s
[regnum
];
623 if (register_size (gdbarch
, regnum
) == 0)
624 /* Do not try to fetch zero-sized (placeholder) registers. */
627 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
632 /* Define the g/G packet format as the contents of each register
633 with a remote protocol number, in order of ascending protocol
636 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
637 * sizeof (struct packet_reg
*));
638 for (num_remote_regs
= 0, regnum
= 0;
639 regnum
< gdbarch_num_regs (gdbarch
);
641 if (regs
[regnum
].pnum
!= -1)
642 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
644 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
647 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
649 remote_regs
[regnum
]->in_g_packet
= 1;
650 remote_regs
[regnum
]->offset
= offset
;
651 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
657 /* Given the architecture described by GDBARCH, return the remote
658 protocol register's number and the register's offset in the g/G
659 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
660 If the target does not have a mapping for REGNUM, return false,
661 otherwise, return true. */
664 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
665 int *pnum
, int *poffset
)
668 struct packet_reg
*regs
;
669 struct cleanup
*old_chain
;
671 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
673 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
674 old_chain
= make_cleanup (xfree
, regs
);
676 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
678 *pnum
= regs
[regnum
].pnum
;
679 *poffset
= regs
[regnum
].offset
;
681 do_cleanups (old_chain
);
687 init_remote_state (struct gdbarch
*gdbarch
)
689 struct remote_state
*rs
= get_remote_state_raw ();
690 struct remote_arch_state
*rsa
;
692 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
694 /* Use the architecture to build a regnum<->pnum table, which will be
695 1:1 unless a feature set specifies otherwise. */
696 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
697 gdbarch_num_regs (gdbarch
),
700 /* Record the maximum possible size of the g packet - it may turn out
702 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
704 /* Default maximum number of characters in a packet body. Many
705 remote stubs have a hardwired buffer size of 400 bytes
706 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
707 as the maximum packet-size to ensure that the packet and an extra
708 NUL character can always fit in the buffer. This stops GDB
709 trashing stubs that try to squeeze an extra NUL into what is
710 already a full buffer (As of 1999-12-04 that was most stubs). */
711 rsa
->remote_packet_size
= 400 - 1;
713 /* This one is filled in when a ``g'' packet is received. */
714 rsa
->actual_register_packet_size
= 0;
716 /* Should rsa->sizeof_g_packet needs more space than the
717 default, adjust the size accordingly. Remember that each byte is
718 encoded as two characters. 32 is the overhead for the packet
719 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
720 (``$NN:G...#NN'') is a better guess, the below has been padded a
722 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
723 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
725 /* Make sure that the packet buffer is plenty big enough for
726 this architecture. */
727 if (rs
->buf_size
< rsa
->remote_packet_size
)
729 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
730 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
736 /* Return the current allowed size of a remote packet. This is
737 inferred from the current architecture, and should be used to
738 limit the length of outgoing packets. */
740 get_remote_packet_size (void)
742 struct remote_state
*rs
= get_remote_state ();
743 struct remote_arch_state
*rsa
= get_remote_arch_state ();
745 if (rs
->explicit_packet_size
)
746 return rs
->explicit_packet_size
;
748 return rsa
->remote_packet_size
;
751 static struct packet_reg
*
752 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
754 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
758 struct packet_reg
*r
= &rsa
->regs
[regnum
];
760 gdb_assert (r
->regnum
== regnum
);
765 static struct packet_reg
*
766 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
770 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
772 struct packet_reg
*r
= &rsa
->regs
[i
];
780 /* FIXME: graces/2002-08-08: These variables should eventually be
781 bound to an instance of the target object (as in gdbarch-tdep()),
782 when such a thing exists. */
784 /* This is set to the data address of the access causing the target
785 to stop for a watchpoint. */
786 static CORE_ADDR remote_watch_data_address
;
788 /* This is non-zero if target stopped for a watchpoint. */
789 static int remote_stopped_by_watchpoint_p
;
791 static struct target_ops remote_ops
;
793 static struct target_ops extended_remote_ops
;
795 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
796 ``forever'' still use the normal timeout mechanism. This is
797 currently used by the ASYNC code to guarentee that target reads
798 during the initial connect always time-out. Once getpkt has been
799 modified to return a timeout indication and, in turn
800 remote_wait()/wait_for_inferior() have gained a timeout parameter
802 static int wait_forever_enabled_p
= 1;
804 /* Allow the user to specify what sequence to send to the remote
805 when he requests a program interruption: Although ^C is usually
806 what remote systems expect (this is the default, here), it is
807 sometimes preferable to send a break. On other systems such
808 as the Linux kernel, a break followed by g, which is Magic SysRq g
809 is required in order to interrupt the execution. */
810 const char interrupt_sequence_control_c
[] = "Ctrl-C";
811 const char interrupt_sequence_break
[] = "BREAK";
812 const char interrupt_sequence_break_g
[] = "BREAK-g";
813 static const char *const interrupt_sequence_modes
[] =
815 interrupt_sequence_control_c
,
816 interrupt_sequence_break
,
817 interrupt_sequence_break_g
,
820 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
823 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
824 struct cmd_list_element
*c
,
827 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
828 fprintf_filtered (file
,
829 _("Send the ASCII ETX character (Ctrl-c) "
830 "to the remote target to interrupt the "
831 "execution of the program.\n"));
832 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
833 fprintf_filtered (file
,
834 _("send a break signal to the remote target "
835 "to interrupt the execution of the program.\n"));
836 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
837 fprintf_filtered (file
,
838 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
839 "the remote target to interrupt the execution "
840 "of Linux kernel.\n"));
842 internal_error (__FILE__
, __LINE__
,
843 _("Invalid value for interrupt_sequence_mode: %s."),
844 interrupt_sequence_mode
);
847 /* This boolean variable specifies whether interrupt_sequence is sent
848 to the remote target when gdb connects to it.
849 This is mostly needed when you debug the Linux kernel: The Linux kernel
850 expects BREAK g which is Magic SysRq g for connecting gdb. */
851 static int interrupt_on_connect
= 0;
853 /* This variable is used to implement the "set/show remotebreak" commands.
854 Since these commands are now deprecated in favor of "set/show remote
855 interrupt-sequence", it no longer has any effect on the code. */
856 static int remote_break
;
859 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
862 interrupt_sequence_mode
= interrupt_sequence_break
;
864 interrupt_sequence_mode
= interrupt_sequence_control_c
;
868 show_remotebreak (struct ui_file
*file
, int from_tty
,
869 struct cmd_list_element
*c
,
874 /* This variable sets the number of bits in an address that are to be
875 sent in a memory ("M" or "m") packet. Normally, after stripping
876 leading zeros, the entire address would be sent. This variable
877 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
878 initial implementation of remote.c restricted the address sent in
879 memory packets to ``host::sizeof long'' bytes - (typically 32
880 bits). Consequently, for 64 bit targets, the upper 32 bits of an
881 address was never sent. Since fixing this bug may cause a break in
882 some remote targets this variable is principly provided to
883 facilitate backward compatibility. */
885 static unsigned int remote_address_size
;
887 /* Temporary to track who currently owns the terminal. See
888 remote_terminal_* for more details. */
890 static int remote_async_terminal_ours_p
;
892 /* The executable file to use for "run" on the remote side. */
894 static char *remote_exec_file
= "";
897 /* User configurable variables for the number of characters in a
898 memory read/write packet. MIN (rsa->remote_packet_size,
899 rsa->sizeof_g_packet) is the default. Some targets need smaller
900 values (fifo overruns, et.al.) and some users need larger values
901 (speed up transfers). The variables ``preferred_*'' (the user
902 request), ``current_*'' (what was actually set) and ``forced_*''
903 (Positive - a soft limit, negative - a hard limit). */
905 struct memory_packet_config
912 /* Compute the current size of a read/write packet. Since this makes
913 use of ``actual_register_packet_size'' the computation is dynamic. */
916 get_memory_packet_size (struct memory_packet_config
*config
)
918 struct remote_state
*rs
= get_remote_state ();
919 struct remote_arch_state
*rsa
= get_remote_arch_state ();
921 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
922 law?) that some hosts don't cope very well with large alloca()
923 calls. Eventually the alloca() code will be replaced by calls to
924 xmalloc() and make_cleanups() allowing this restriction to either
925 be lifted or removed. */
926 #ifndef MAX_REMOTE_PACKET_SIZE
927 #define MAX_REMOTE_PACKET_SIZE 16384
929 /* NOTE: 20 ensures we can write at least one byte. */
930 #ifndef MIN_REMOTE_PACKET_SIZE
931 #define MIN_REMOTE_PACKET_SIZE 20
936 if (config
->size
<= 0)
937 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
939 what_they_get
= config
->size
;
943 what_they_get
= get_remote_packet_size ();
944 /* Limit the packet to the size specified by the user. */
946 && what_they_get
> config
->size
)
947 what_they_get
= config
->size
;
949 /* Limit it to the size of the targets ``g'' response unless we have
950 permission from the stub to use a larger packet size. */
951 if (rs
->explicit_packet_size
== 0
952 && rsa
->actual_register_packet_size
> 0
953 && what_they_get
> rsa
->actual_register_packet_size
)
954 what_they_get
= rsa
->actual_register_packet_size
;
956 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
957 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
958 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
959 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
961 /* Make sure there is room in the global buffer for this packet
962 (including its trailing NUL byte). */
963 if (rs
->buf_size
< what_they_get
+ 1)
965 rs
->buf_size
= 2 * what_they_get
;
966 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
969 return what_they_get
;
972 /* Update the size of a read/write packet. If they user wants
973 something really big then do a sanity check. */
976 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
978 int fixed_p
= config
->fixed_p
;
979 long size
= config
->size
;
982 error (_("Argument required (integer, `fixed' or `limited')."));
983 else if (strcmp (args
, "hard") == 0
984 || strcmp (args
, "fixed") == 0)
986 else if (strcmp (args
, "soft") == 0
987 || strcmp (args
, "limit") == 0)
993 size
= strtoul (args
, &end
, 0);
995 error (_("Invalid %s (bad syntax)."), config
->name
);
997 /* Instead of explicitly capping the size of a packet to
998 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
999 instead allowed to set the size to something arbitrarily
1001 if (size
> MAX_REMOTE_PACKET_SIZE
)
1002 error (_("Invalid %s (too large)."), config
->name
);
1006 if (fixed_p
&& !config
->fixed_p
)
1008 if (! query (_("The target may not be able to correctly handle a %s\n"
1009 "of %ld bytes. Change the packet size? "),
1010 config
->name
, size
))
1011 error (_("Packet size not changed."));
1013 /* Update the config. */
1014 config
->fixed_p
= fixed_p
;
1015 config
->size
= size
;
1019 show_memory_packet_size (struct memory_packet_config
*config
)
1021 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1022 if (config
->fixed_p
)
1023 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1024 get_memory_packet_size (config
));
1026 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1027 get_memory_packet_size (config
));
1030 static struct memory_packet_config memory_write_packet_config
=
1032 "memory-write-packet-size",
1036 set_memory_write_packet_size (char *args
, int from_tty
)
1038 set_memory_packet_size (args
, &memory_write_packet_config
);
1042 show_memory_write_packet_size (char *args
, int from_tty
)
1044 show_memory_packet_size (&memory_write_packet_config
);
1048 get_memory_write_packet_size (void)
1050 return get_memory_packet_size (&memory_write_packet_config
);
1053 static struct memory_packet_config memory_read_packet_config
=
1055 "memory-read-packet-size",
1059 set_memory_read_packet_size (char *args
, int from_tty
)
1061 set_memory_packet_size (args
, &memory_read_packet_config
);
1065 show_memory_read_packet_size (char *args
, int from_tty
)
1067 show_memory_packet_size (&memory_read_packet_config
);
1071 get_memory_read_packet_size (void)
1073 long size
= get_memory_packet_size (&memory_read_packet_config
);
1075 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1076 extra buffer size argument before the memory read size can be
1077 increased beyond this. */
1078 if (size
> get_remote_packet_size ())
1079 size
= get_remote_packet_size ();
1084 /* Generic configuration support for packets the stub optionally
1085 supports. Allows the user to specify the use of the packet as well
1086 as allowing GDB to auto-detect support in the remote stub. */
1090 PACKET_SUPPORT_UNKNOWN
= 0,
1095 struct packet_config
1099 enum auto_boolean detect
;
1100 enum packet_support support
;
1103 /* Analyze a packet's return value and update the packet config
1114 update_packet_config (struct packet_config
*config
)
1116 switch (config
->detect
)
1118 case AUTO_BOOLEAN_TRUE
:
1119 config
->support
= PACKET_ENABLE
;
1121 case AUTO_BOOLEAN_FALSE
:
1122 config
->support
= PACKET_DISABLE
;
1124 case AUTO_BOOLEAN_AUTO
:
1125 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1131 show_packet_config_cmd (struct packet_config
*config
)
1133 char *support
= "internal-error";
1135 switch (config
->support
)
1138 support
= "enabled";
1140 case PACKET_DISABLE
:
1141 support
= "disabled";
1143 case PACKET_SUPPORT_UNKNOWN
:
1144 support
= "unknown";
1147 switch (config
->detect
)
1149 case AUTO_BOOLEAN_AUTO
:
1150 printf_filtered (_("Support for the `%s' packet "
1151 "is auto-detected, currently %s.\n"),
1152 config
->name
, support
);
1154 case AUTO_BOOLEAN_TRUE
:
1155 case AUTO_BOOLEAN_FALSE
:
1156 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1157 config
->name
, support
);
1163 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1164 const char *title
, int legacy
)
1170 config
->name
= name
;
1171 config
->title
= title
;
1172 config
->detect
= AUTO_BOOLEAN_AUTO
;
1173 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1174 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1176 show_doc
= xstrprintf ("Show current use of remote "
1177 "protocol `%s' (%s) packet",
1179 /* set/show TITLE-packet {auto,on,off} */
1180 cmd_name
= xstrprintf ("%s-packet", title
);
1181 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1182 &config
->detect
, set_doc
,
1183 show_doc
, NULL
, /* help_doc */
1184 set_remote_protocol_packet_cmd
,
1185 show_remote_protocol_packet_cmd
,
1186 &remote_set_cmdlist
, &remote_show_cmdlist
);
1187 /* The command code copies the documentation strings. */
1190 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1195 legacy_name
= xstrprintf ("%s-packet", name
);
1196 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1197 &remote_set_cmdlist
);
1198 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1199 &remote_show_cmdlist
);
1203 static enum packet_result
1204 packet_check_result (const char *buf
)
1208 /* The stub recognized the packet request. Check that the
1209 operation succeeded. */
1211 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1213 /* "Enn" - definitly an error. */
1214 return PACKET_ERROR
;
1216 /* Always treat "E." as an error. This will be used for
1217 more verbose error messages, such as E.memtypes. */
1218 if (buf
[0] == 'E' && buf
[1] == '.')
1219 return PACKET_ERROR
;
1221 /* The packet may or may not be OK. Just assume it is. */
1225 /* The stub does not support the packet. */
1226 return PACKET_UNKNOWN
;
1229 static enum packet_result
1230 packet_ok (const char *buf
, struct packet_config
*config
)
1232 enum packet_result result
;
1234 result
= packet_check_result (buf
);
1239 /* The stub recognized the packet request. */
1240 switch (config
->support
)
1242 case PACKET_SUPPORT_UNKNOWN
:
1244 fprintf_unfiltered (gdb_stdlog
,
1245 "Packet %s (%s) is supported\n",
1246 config
->name
, config
->title
);
1247 config
->support
= PACKET_ENABLE
;
1249 case PACKET_DISABLE
:
1250 internal_error (__FILE__
, __LINE__
,
1251 _("packet_ok: attempt to use a disabled packet"));
1257 case PACKET_UNKNOWN
:
1258 /* The stub does not support the packet. */
1259 switch (config
->support
)
1262 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1263 /* If the stub previously indicated that the packet was
1264 supported then there is a protocol error.. */
1265 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1266 config
->name
, config
->title
);
1268 /* The user set it wrong. */
1269 error (_("Enabled packet %s (%s) not recognized by stub"),
1270 config
->name
, config
->title
);
1272 case PACKET_SUPPORT_UNKNOWN
:
1274 fprintf_unfiltered (gdb_stdlog
,
1275 "Packet %s (%s) is NOT supported\n",
1276 config
->name
, config
->title
);
1277 config
->support
= PACKET_DISABLE
;
1279 case PACKET_DISABLE
:
1301 PACKET_vFile_pwrite
,
1303 PACKET_vFile_unlink
,
1304 PACKET_vFile_readlink
,
1306 PACKET_qXfer_features
,
1307 PACKET_qXfer_libraries
,
1308 PACKET_qXfer_libraries_svr4
,
1309 PACKET_qXfer_memory_map
,
1310 PACKET_qXfer_spu_read
,
1311 PACKET_qXfer_spu_write
,
1312 PACKET_qXfer_osdata
,
1313 PACKET_qXfer_threads
,
1314 PACKET_qXfer_statictrace_read
,
1315 PACKET_qXfer_traceframe_info
,
1321 PACKET_QPassSignals
,
1322 PACKET_QProgramSignals
,
1323 PACKET_qSearch_memory
,
1326 PACKET_QStartNoAckMode
,
1328 PACKET_qXfer_siginfo_read
,
1329 PACKET_qXfer_siginfo_write
,
1331 PACKET_ConditionalTracepoints
,
1332 PACKET_ConditionalBreakpoints
,
1333 PACKET_BreakpointCommands
,
1334 PACKET_FastTracepoints
,
1335 PACKET_StaticTracepoints
,
1336 PACKET_InstallInTrace
,
1339 PACKET_TracepointSource
,
1342 PACKET_QDisableRandomization
,
1344 PACKET_QTBuffer_size
,
1347 PACKET_qXfer_btrace
,
1351 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1354 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1355 struct cmd_list_element
*c
)
1357 struct packet_config
*packet
;
1359 for (packet
= remote_protocol_packets
;
1360 packet
< &remote_protocol_packets
[PACKET_MAX
];
1363 if (&packet
->detect
== c
->var
)
1365 update_packet_config (packet
);
1369 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1374 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1375 struct cmd_list_element
*c
,
1378 struct packet_config
*packet
;
1380 for (packet
= remote_protocol_packets
;
1381 packet
< &remote_protocol_packets
[PACKET_MAX
];
1384 if (&packet
->detect
== c
->var
)
1386 show_packet_config_cmd (packet
);
1390 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1394 /* Should we try one of the 'Z' requests? */
1398 Z_PACKET_SOFTWARE_BP
,
1399 Z_PACKET_HARDWARE_BP
,
1406 /* For compatibility with older distributions. Provide a ``set remote
1407 Z-packet ...'' command that updates all the Z packet types. */
1409 static enum auto_boolean remote_Z_packet_detect
;
1412 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1413 struct cmd_list_element
*c
)
1417 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1419 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1420 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1425 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1426 struct cmd_list_element
*c
,
1431 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1433 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1437 /* Should we try the 'ThreadInfo' query packet?
1439 This variable (NOT available to the user: auto-detect only!)
1440 determines whether GDB will use the new, simpler "ThreadInfo"
1441 query or the older, more complex syntax for thread queries.
1442 This is an auto-detect variable (set to true at each connect,
1443 and set to false when the target fails to recognize it). */
1445 static int use_threadinfo_query
;
1446 static int use_threadextra_query
;
1448 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1449 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1450 static struct async_signal_handler
*async_sigint_remote_token
;
1453 /* Asynchronous signal handle registered as event loop source for
1454 when we have pending events ready to be passed to the core. */
1456 static struct async_event_handler
*remote_async_inferior_event_token
;
1460 static ptid_t magic_null_ptid
;
1461 static ptid_t not_sent_ptid
;
1462 static ptid_t any_thread_ptid
;
1464 /* Find out if the stub attached to PID (and hence GDB should offer to
1465 detach instead of killing it when bailing out). */
1468 remote_query_attached (int pid
)
1470 struct remote_state
*rs
= get_remote_state ();
1471 size_t size
= get_remote_packet_size ();
1473 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1476 if (remote_multi_process_p (rs
))
1477 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1479 xsnprintf (rs
->buf
, size
, "qAttached");
1482 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1484 switch (packet_ok (rs
->buf
,
1485 &remote_protocol_packets
[PACKET_qAttached
]))
1488 if (strcmp (rs
->buf
, "1") == 0)
1492 warning (_("Remote failure reply: %s"), rs
->buf
);
1494 case PACKET_UNKNOWN
:
1501 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1502 has been invented by GDB, instead of reported by the target. Since
1503 we can be connected to a remote system before before knowing about
1504 any inferior, mark the target with execution when we find the first
1505 inferior. If ATTACHED is 1, then we had just attached to this
1506 inferior. If it is 0, then we just created this inferior. If it
1507 is -1, then try querying the remote stub to find out if it had
1508 attached to the inferior or not. */
1510 static struct inferior
*
1511 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1513 struct inferior
*inf
;
1515 /* Check whether this process we're learning about is to be
1516 considered attached, or if is to be considered to have been
1517 spawned by the stub. */
1519 attached
= remote_query_attached (pid
);
1521 if (gdbarch_has_global_solist (target_gdbarch ()))
1523 /* If the target shares code across all inferiors, then every
1524 attach adds a new inferior. */
1525 inf
= add_inferior (pid
);
1527 /* ... and every inferior is bound to the same program space.
1528 However, each inferior may still have its own address
1530 inf
->aspace
= maybe_new_address_space ();
1531 inf
->pspace
= current_program_space
;
1535 /* In the traditional debugging scenario, there's a 1-1 match
1536 between program/address spaces. We simply bind the inferior
1537 to the program space's address space. */
1538 inf
= current_inferior ();
1539 inferior_appeared (inf
, pid
);
1542 inf
->attach_flag
= attached
;
1543 inf
->fake_pid_p
= fake_pid_p
;
1548 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1549 according to RUNNING. */
1552 remote_add_thread (ptid_t ptid
, int running
)
1556 set_executing (ptid
, running
);
1557 set_running (ptid
, running
);
1560 /* Come here when we learn about a thread id from the remote target.
1561 It may be the first time we hear about such thread, so take the
1562 opportunity to add it to GDB's thread list. In case this is the
1563 first time we're noticing its corresponding inferior, add it to
1564 GDB's inferior list as well. */
1567 remote_notice_new_inferior (ptid_t currthread
, int running
)
1569 /* If this is a new thread, add it to GDB's thread list.
1570 If we leave it up to WFI to do this, bad things will happen. */
1572 if (in_thread_list (currthread
) && is_exited (currthread
))
1574 /* We're seeing an event on a thread id we knew had exited.
1575 This has to be a new thread reusing the old id. Add it. */
1576 remote_add_thread (currthread
, running
);
1580 if (!in_thread_list (currthread
))
1582 struct inferior
*inf
= NULL
;
1583 int pid
= ptid_get_pid (currthread
);
1585 if (ptid_is_pid (inferior_ptid
)
1586 && pid
== ptid_get_pid (inferior_ptid
))
1588 /* inferior_ptid has no thread member yet. This can happen
1589 with the vAttach -> remote_wait,"TAAthread:" path if the
1590 stub doesn't support qC. This is the first stop reported
1591 after an attach, so this is the main thread. Update the
1592 ptid in the thread list. */
1593 if (in_thread_list (pid_to_ptid (pid
)))
1594 thread_change_ptid (inferior_ptid
, currthread
);
1597 remote_add_thread (currthread
, running
);
1598 inferior_ptid
= currthread
;
1603 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1605 /* inferior_ptid is not set yet. This can happen with the
1606 vRun -> remote_wait,"TAAthread:" path if the stub
1607 doesn't support qC. This is the first stop reported
1608 after an attach, so this is the main thread. Update the
1609 ptid in the thread list. */
1610 thread_change_ptid (inferior_ptid
, currthread
);
1614 /* When connecting to a target remote, or to a target
1615 extended-remote which already was debugging an inferior, we
1616 may not know about it yet. Add it before adding its child
1617 thread, so notifications are emitted in a sensible order. */
1618 if (!in_inferior_list (ptid_get_pid (currthread
)))
1620 struct remote_state
*rs
= get_remote_state ();
1621 int fake_pid_p
= !remote_multi_process_p (rs
);
1623 inf
= remote_add_inferior (fake_pid_p
,
1624 ptid_get_pid (currthread
), -1);
1627 /* This is really a new thread. Add it. */
1628 remote_add_thread (currthread
, running
);
1630 /* If we found a new inferior, let the common code do whatever
1631 it needs to with it (e.g., read shared libraries, insert
1634 notice_new_inferior (currthread
, running
, 0);
1638 /* Return the private thread data, creating it if necessary. */
1640 static struct private_thread_info
*
1641 demand_private_info (ptid_t ptid
)
1643 struct thread_info
*info
= find_thread_ptid (ptid
);
1649 info
->private = xmalloc (sizeof (*(info
->private)));
1650 info
->private_dtor
= free_private_thread_info
;
1651 info
->private->core
= -1;
1652 info
->private->extra
= 0;
1655 return info
->private;
1658 /* Call this function as a result of
1659 1) A halt indication (T packet) containing a thread id
1660 2) A direct query of currthread
1661 3) Successful execution of set thread */
1664 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1666 rs
->general_thread
= currthread
;
1669 /* If 'QPassSignals' is supported, tell the remote stub what signals
1670 it can simply pass through to the inferior without reporting. */
1673 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1675 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1677 char *pass_packet
, *p
;
1679 struct remote_state
*rs
= get_remote_state ();
1681 gdb_assert (numsigs
< 256);
1682 for (i
= 0; i
< numsigs
; i
++)
1684 if (pass_signals
[i
])
1687 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1688 strcpy (pass_packet
, "QPassSignals:");
1689 p
= pass_packet
+ strlen (pass_packet
);
1690 for (i
= 0; i
< numsigs
; i
++)
1692 if (pass_signals
[i
])
1695 *p
++ = tohex (i
>> 4);
1696 *p
++ = tohex (i
& 15);
1705 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1707 char *buf
= rs
->buf
;
1709 putpkt (pass_packet
);
1710 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1711 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1712 if (rs
->last_pass_packet
)
1713 xfree (rs
->last_pass_packet
);
1714 rs
->last_pass_packet
= pass_packet
;
1717 xfree (pass_packet
);
1721 /* If 'QProgramSignals' is supported, tell the remote stub what
1722 signals it should pass through to the inferior when detaching. */
1725 remote_program_signals (int numsigs
, unsigned char *signals
)
1727 if (remote_protocol_packets
[PACKET_QProgramSignals
].support
!= PACKET_DISABLE
)
1731 struct remote_state
*rs
= get_remote_state ();
1733 gdb_assert (numsigs
< 256);
1734 for (i
= 0; i
< numsigs
; i
++)
1739 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1740 strcpy (packet
, "QProgramSignals:");
1741 p
= packet
+ strlen (packet
);
1742 for (i
= 0; i
< numsigs
; i
++)
1744 if (signal_pass_state (i
))
1747 *p
++ = tohex (i
>> 4);
1748 *p
++ = tohex (i
& 15);
1757 if (!rs
->last_program_signals_packet
1758 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1760 char *buf
= rs
->buf
;
1763 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1764 packet_ok (buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1765 xfree (rs
->last_program_signals_packet
);
1766 rs
->last_program_signals_packet
= packet
;
1773 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1774 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1775 thread. If GEN is set, set the general thread, if not, then set
1776 the step/continue thread. */
1778 set_thread (struct ptid ptid
, int gen
)
1780 struct remote_state
*rs
= get_remote_state ();
1781 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1782 char *buf
= rs
->buf
;
1783 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1785 if (ptid_equal (state
, ptid
))
1789 *buf
++ = gen
? 'g' : 'c';
1790 if (ptid_equal (ptid
, magic_null_ptid
))
1791 xsnprintf (buf
, endbuf
- buf
, "0");
1792 else if (ptid_equal (ptid
, any_thread_ptid
))
1793 xsnprintf (buf
, endbuf
- buf
, "0");
1794 else if (ptid_equal (ptid
, minus_one_ptid
))
1795 xsnprintf (buf
, endbuf
- buf
, "-1");
1797 write_ptid (buf
, endbuf
, ptid
);
1799 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1801 rs
->general_thread
= ptid
;
1803 rs
->continue_thread
= ptid
;
1807 set_general_thread (struct ptid ptid
)
1809 set_thread (ptid
, 1);
1813 set_continue_thread (struct ptid ptid
)
1815 set_thread (ptid
, 0);
1818 /* Change the remote current process. Which thread within the process
1819 ends up selected isn't important, as long as it is the same process
1820 as what INFERIOR_PTID points to.
1822 This comes from that fact that there is no explicit notion of
1823 "selected process" in the protocol. The selected process for
1824 general operations is the process the selected general thread
1828 set_general_process (void)
1830 struct remote_state
*rs
= get_remote_state ();
1832 /* If the remote can't handle multiple processes, don't bother. */
1833 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1836 /* We only need to change the remote current thread if it's pointing
1837 at some other process. */
1838 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1839 set_general_thread (inferior_ptid
);
1843 /* Return nonzero if the thread PTID is still alive on the remote
1847 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1849 struct remote_state
*rs
= get_remote_state ();
1852 if (ptid_equal (ptid
, magic_null_ptid
))
1853 /* The main thread is always alive. */
1856 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1857 /* The main thread is always alive. This can happen after a
1858 vAttach, if the remote side doesn't support
1863 endp
= rs
->buf
+ get_remote_packet_size ();
1866 write_ptid (p
, endp
, ptid
);
1869 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1870 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1873 /* About these extended threadlist and threadinfo packets. They are
1874 variable length packets but, the fields within them are often fixed
1875 length. They are redundent enough to send over UDP as is the
1876 remote protocol in general. There is a matching unit test module
1879 #define OPAQUETHREADBYTES 8
1881 /* a 64 bit opaque identifier */
1882 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1884 /* WARNING: This threadref data structure comes from the remote O.S.,
1885 libstub protocol encoding, and remote.c. It is not particularly
1888 /* Right now, the internal structure is int. We want it to be bigger.
1889 Plan to fix this. */
1891 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1893 /* gdb_ext_thread_info is an internal GDB data structure which is
1894 equivalent to the reply of the remote threadinfo packet. */
1896 struct gdb_ext_thread_info
1898 threadref threadid
; /* External form of thread reference. */
1899 int active
; /* Has state interesting to GDB?
1901 char display
[256]; /* Brief state display, name,
1902 blocked/suspended. */
1903 char shortname
[32]; /* To be used to name threads. */
1904 char more_display
[256]; /* Long info, statistics, queue depth,
1908 /* The volume of remote transfers can be limited by submitting
1909 a mask containing bits specifying the desired information.
1910 Use a union of these values as the 'selection' parameter to
1911 get_thread_info. FIXME: Make these TAG names more thread specific. */
1913 #define TAG_THREADID 1
1914 #define TAG_EXISTS 2
1915 #define TAG_DISPLAY 4
1916 #define TAG_THREADNAME 8
1917 #define TAG_MOREDISPLAY 16
1919 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1921 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1923 static char *unpack_nibble (char *buf
, int *val
);
1925 static char *pack_nibble (char *buf
, int nibble
);
1927 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1929 static char *unpack_byte (char *buf
, int *value
);
1931 static char *pack_int (char *buf
, int value
);
1933 static char *unpack_int (char *buf
, int *value
);
1935 static char *unpack_string (char *src
, char *dest
, int length
);
1937 static char *pack_threadid (char *pkt
, threadref
*id
);
1939 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1941 void int_to_threadref (threadref
*id
, int value
);
1943 static int threadref_to_int (threadref
*ref
);
1945 static void copy_threadref (threadref
*dest
, threadref
*src
);
1947 static int threadmatch (threadref
*dest
, threadref
*src
);
1949 static char *pack_threadinfo_request (char *pkt
, int mode
,
1952 static int remote_unpack_thread_info_response (char *pkt
,
1953 threadref
*expectedref
,
1954 struct gdb_ext_thread_info
1958 static int remote_get_threadinfo (threadref
*threadid
,
1959 int fieldset
, /*TAG mask */
1960 struct gdb_ext_thread_info
*info
);
1962 static char *pack_threadlist_request (char *pkt
, int startflag
,
1964 threadref
*nextthread
);
1966 static int parse_threadlist_response (char *pkt
,
1968 threadref
*original_echo
,
1969 threadref
*resultlist
,
1972 static int remote_get_threadlist (int startflag
,
1973 threadref
*nextthread
,
1977 threadref
*threadlist
);
1979 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1981 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1982 void *context
, int looplimit
);
1984 static int remote_newthread_step (threadref
*ref
, void *context
);
1987 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1988 buffer we're allowed to write to. Returns
1989 BUF+CHARACTERS_WRITTEN. */
1992 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1995 struct remote_state
*rs
= get_remote_state ();
1997 if (remote_multi_process_p (rs
))
1999 pid
= ptid_get_pid (ptid
);
2001 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2003 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2005 tid
= ptid_get_tid (ptid
);
2007 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2009 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2014 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2015 passed the last parsed char. Returns null_ptid on error. */
2018 read_ptid (char *buf
, char **obuf
)
2022 ULONGEST pid
= 0, tid
= 0;
2026 /* Multi-process ptid. */
2027 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2029 error (_("invalid remote ptid: %s"), p
);
2032 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2035 return ptid_build (pid
, 0, tid
);
2038 /* No multi-process. Just a tid. */
2039 pp
= unpack_varlen_hex (p
, &tid
);
2041 /* Since the stub is not sending a process id, then default to
2042 what's in inferior_ptid, unless it's null at this point. If so,
2043 then since there's no way to know the pid of the reported
2044 threads, use the magic number. */
2045 if (ptid_equal (inferior_ptid
, null_ptid
))
2046 pid
= ptid_get_pid (magic_null_ptid
);
2048 pid
= ptid_get_pid (inferior_ptid
);
2052 return ptid_build (pid
, 0, tid
);
2055 /* Encode 64 bits in 16 chars of hex. */
2057 static const char hexchars
[] = "0123456789abcdef";
2060 ishex (int ch
, int *val
)
2062 if ((ch
>= 'a') && (ch
<= 'f'))
2064 *val
= ch
- 'a' + 10;
2067 if ((ch
>= 'A') && (ch
<= 'F'))
2069 *val
= ch
- 'A' + 10;
2072 if ((ch
>= '0') && (ch
<= '9'))
2083 if (ch
>= 'a' && ch
<= 'f')
2084 return ch
- 'a' + 10;
2085 if (ch
>= '0' && ch
<= '9')
2087 if (ch
>= 'A' && ch
<= 'F')
2088 return ch
- 'A' + 10;
2093 stub_unpack_int (char *buff
, int fieldlength
)
2100 nibble
= stubhex (*buff
++);
2104 retval
= retval
<< 4;
2110 unpack_varlen_hex (char *buff
, /* packet to parse */
2114 ULONGEST retval
= 0;
2116 while (ishex (*buff
, &nibble
))
2119 retval
= retval
<< 4;
2120 retval
|= nibble
& 0x0f;
2127 unpack_nibble (char *buf
, int *val
)
2129 *val
= fromhex (*buf
++);
2134 pack_nibble (char *buf
, int nibble
)
2136 *buf
++ = hexchars
[(nibble
& 0x0f)];
2141 pack_hex_byte (char *pkt
, int byte
)
2143 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2144 *pkt
++ = hexchars
[(byte
& 0xf)];
2149 unpack_byte (char *buf
, int *value
)
2151 *value
= stub_unpack_int (buf
, 2);
2156 pack_int (char *buf
, int value
)
2158 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2159 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2160 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2161 buf
= pack_hex_byte (buf
, (value
& 0xff));
2166 unpack_int (char *buf
, int *value
)
2168 *value
= stub_unpack_int (buf
, 8);
2172 #if 0 /* Currently unused, uncomment when needed. */
2173 static char *pack_string (char *pkt
, char *string
);
2176 pack_string (char *pkt
, char *string
)
2181 len
= strlen (string
);
2183 len
= 200; /* Bigger than most GDB packets, junk??? */
2184 pkt
= pack_hex_byte (pkt
, len
);
2188 if ((ch
== '\0') || (ch
== '#'))
2189 ch
= '*'; /* Protect encapsulation. */
2194 #endif /* 0 (unused) */
2197 unpack_string (char *src
, char *dest
, int length
)
2206 pack_threadid (char *pkt
, threadref
*id
)
2209 unsigned char *altid
;
2211 altid
= (unsigned char *) id
;
2212 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2214 pkt
= pack_hex_byte (pkt
, *altid
++);
2220 unpack_threadid (char *inbuf
, threadref
*id
)
2223 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2226 altref
= (char *) id
;
2228 while (inbuf
< limit
)
2230 x
= stubhex (*inbuf
++);
2231 y
= stubhex (*inbuf
++);
2232 *altref
++ = (x
<< 4) | y
;
2237 /* Externally, threadrefs are 64 bits but internally, they are still
2238 ints. This is due to a mismatch of specifications. We would like
2239 to use 64bit thread references internally. This is an adapter
2243 int_to_threadref (threadref
*id
, int value
)
2245 unsigned char *scan
;
2247 scan
= (unsigned char *) id
;
2253 *scan
++ = (value
>> 24) & 0xff;
2254 *scan
++ = (value
>> 16) & 0xff;
2255 *scan
++ = (value
>> 8) & 0xff;
2256 *scan
++ = (value
& 0xff);
2260 threadref_to_int (threadref
*ref
)
2263 unsigned char *scan
;
2269 value
= (value
<< 8) | ((*scan
++) & 0xff);
2274 copy_threadref (threadref
*dest
, threadref
*src
)
2277 unsigned char *csrc
, *cdest
;
2279 csrc
= (unsigned char *) src
;
2280 cdest
= (unsigned char *) dest
;
2287 threadmatch (threadref
*dest
, threadref
*src
)
2289 /* Things are broken right now, so just assume we got a match. */
2291 unsigned char *srcp
, *destp
;
2293 srcp
= (char *) src
;
2294 destp
= (char *) dest
;
2298 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2305 threadid:1, # always request threadid
2312 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2315 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2317 *pkt
++ = 'q'; /* Info Query */
2318 *pkt
++ = 'P'; /* process or thread info */
2319 pkt
= pack_int (pkt
, mode
); /* mode */
2320 pkt
= pack_threadid (pkt
, id
); /* threadid */
2321 *pkt
= '\0'; /* terminate */
2325 /* These values tag the fields in a thread info response packet. */
2326 /* Tagging the fields allows us to request specific fields and to
2327 add more fields as time goes by. */
2329 #define TAG_THREADID 1 /* Echo the thread identifier. */
2330 #define TAG_EXISTS 2 /* Is this process defined enough to
2331 fetch registers and its stack? */
2332 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2333 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2334 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2338 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2339 struct gdb_ext_thread_info
*info
)
2341 struct remote_state
*rs
= get_remote_state ();
2345 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2348 /* info->threadid = 0; FIXME: implement zero_threadref. */
2350 info
->display
[0] = '\0';
2351 info
->shortname
[0] = '\0';
2352 info
->more_display
[0] = '\0';
2354 /* Assume the characters indicating the packet type have been
2356 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2357 pkt
= unpack_threadid (pkt
, &ref
);
2360 warning (_("Incomplete response to threadinfo request."));
2361 if (!threadmatch (&ref
, expectedref
))
2362 { /* This is an answer to a different request. */
2363 warning (_("ERROR RMT Thread info mismatch."));
2366 copy_threadref (&info
->threadid
, &ref
);
2368 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2370 /* Packets are terminated with nulls. */
2371 while ((pkt
< limit
) && mask
&& *pkt
)
2373 pkt
= unpack_int (pkt
, &tag
); /* tag */
2374 pkt
= unpack_byte (pkt
, &length
); /* length */
2375 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2377 warning (_("ERROR RMT: threadinfo tag mismatch."));
2381 if (tag
== TAG_THREADID
)
2385 warning (_("ERROR RMT: length of threadid is not 16."));
2389 pkt
= unpack_threadid (pkt
, &ref
);
2390 mask
= mask
& ~TAG_THREADID
;
2393 if (tag
== TAG_EXISTS
)
2395 info
->active
= stub_unpack_int (pkt
, length
);
2397 mask
= mask
& ~(TAG_EXISTS
);
2400 warning (_("ERROR RMT: 'exists' length too long."));
2406 if (tag
== TAG_THREADNAME
)
2408 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2409 mask
= mask
& ~TAG_THREADNAME
;
2412 if (tag
== TAG_DISPLAY
)
2414 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2415 mask
= mask
& ~TAG_DISPLAY
;
2418 if (tag
== TAG_MOREDISPLAY
)
2420 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2421 mask
= mask
& ~TAG_MOREDISPLAY
;
2424 warning (_("ERROR RMT: unknown thread info tag."));
2425 break; /* Not a tag we know about. */
2431 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2432 struct gdb_ext_thread_info
*info
)
2434 struct remote_state
*rs
= get_remote_state ();
2437 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2439 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2441 if (rs
->buf
[0] == '\0')
2444 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2449 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2452 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2453 threadref
*nextthread
)
2455 *pkt
++ = 'q'; /* info query packet */
2456 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2457 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2458 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2459 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2464 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2467 parse_threadlist_response (char *pkt
, int result_limit
,
2468 threadref
*original_echo
, threadref
*resultlist
,
2471 struct remote_state
*rs
= get_remote_state ();
2473 int count
, resultcount
, done
;
2476 /* Assume the 'q' and 'M chars have been stripped. */
2477 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2478 /* done parse past here */
2479 pkt
= unpack_byte (pkt
, &count
); /* count field */
2480 pkt
= unpack_nibble (pkt
, &done
);
2481 /* The first threadid is the argument threadid. */
2482 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2483 while ((count
-- > 0) && (pkt
< limit
))
2485 pkt
= unpack_threadid (pkt
, resultlist
++);
2486 if (resultcount
++ >= result_limit
)
2495 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2496 int *done
, int *result_count
, threadref
*threadlist
)
2498 struct remote_state
*rs
= get_remote_state ();
2499 static threadref echo_nextthread
;
2502 /* Trancate result limit to be smaller than the packet size. */
2503 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2504 >= get_remote_packet_size ())
2505 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2507 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2509 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2511 if (*rs
->buf
== '\0')
2515 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2518 if (!threadmatch (&echo_nextthread
, nextthread
))
2520 /* FIXME: This is a good reason to drop the packet. */
2521 /* Possably, there is a duplicate response. */
2523 retransmit immediatly - race conditions
2524 retransmit after timeout - yes
2526 wait for packet, then exit
2528 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2529 return 0; /* I choose simply exiting. */
2531 if (*result_count
<= 0)
2535 warning (_("RMT ERROR : failed to get remote thread list."));
2538 return result
; /* break; */
2540 if (*result_count
> result_limit
)
2543 warning (_("RMT ERROR: threadlist response longer than requested."));
2549 /* This is the interface between remote and threads, remotes upper
2552 /* remote_find_new_threads retrieves the thread list and for each
2553 thread in the list, looks up the thread in GDB's internal list,
2554 adding the thread if it does not already exist. This involves
2555 getting partial thread lists from the remote target so, polling the
2556 quit_flag is required. */
2559 /* About this many threadisds fit in a packet. */
2561 #define MAXTHREADLISTRESULTS 32
2564 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2567 int done
, i
, result_count
;
2571 static threadref nextthread
;
2572 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2577 if (loopcount
++ > looplimit
)
2580 warning (_("Remote fetch threadlist -infinite loop-."));
2583 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2584 &done
, &result_count
, resultthreadlist
))
2589 /* Clear for later iterations. */
2591 /* Setup to resume next batch of thread references, set nextthread. */
2592 if (result_count
>= 1)
2593 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2595 while (result_count
--)
2596 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2603 remote_newthread_step (threadref
*ref
, void *context
)
2605 int pid
= ptid_get_pid (inferior_ptid
);
2606 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2608 if (!in_thread_list (ptid
))
2610 return 1; /* continue iterator */
2613 #define CRAZY_MAX_THREADS 1000
2616 remote_current_thread (ptid_t oldpid
)
2618 struct remote_state
*rs
= get_remote_state ();
2621 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2622 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2623 return read_ptid (&rs
->buf
[2], NULL
);
2628 /* Find new threads for info threads command.
2629 * Original version, using John Metzler's thread protocol.
2633 remote_find_new_threads (void)
2635 remote_threadlist_iterator (remote_newthread_step
, 0,
2639 #if defined(HAVE_LIBEXPAT)
2641 typedef struct thread_item
2647 DEF_VEC_O(thread_item_t
);
2649 struct threads_parsing_context
2651 VEC (thread_item_t
) *items
;
2655 start_thread (struct gdb_xml_parser
*parser
,
2656 const struct gdb_xml_element
*element
,
2657 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2659 struct threads_parsing_context
*data
= user_data
;
2661 struct thread_item item
;
2663 struct gdb_xml_value
*attr
;
2665 id
= xml_find_attribute (attributes
, "id")->value
;
2666 item
.ptid
= read_ptid (id
, NULL
);
2668 attr
= xml_find_attribute (attributes
, "core");
2670 item
.core
= *(ULONGEST
*) attr
->value
;
2676 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2680 end_thread (struct gdb_xml_parser
*parser
,
2681 const struct gdb_xml_element
*element
,
2682 void *user_data
, const char *body_text
)
2684 struct threads_parsing_context
*data
= user_data
;
2686 if (body_text
&& *body_text
)
2687 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2690 const struct gdb_xml_attribute thread_attributes
[] = {
2691 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2692 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2693 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2696 const struct gdb_xml_element thread_children
[] = {
2697 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2700 const struct gdb_xml_element threads_children
[] = {
2701 { "thread", thread_attributes
, thread_children
,
2702 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2703 start_thread
, end_thread
},
2704 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2707 const struct gdb_xml_element threads_elements
[] = {
2708 { "threads", NULL
, threads_children
,
2709 GDB_XML_EF_NONE
, NULL
, NULL
},
2710 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2713 /* Discard the contents of the constructed thread info context. */
2716 clear_threads_parsing_context (void *p
)
2718 struct threads_parsing_context
*context
= p
;
2720 struct thread_item
*item
;
2722 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2723 xfree (item
->extra
);
2725 VEC_free (thread_item_t
, context
->items
);
2731 * Find all threads for info threads command.
2732 * Uses new thread protocol contributed by Cisco.
2733 * Falls back and attempts to use the older method (above)
2734 * if the target doesn't respond to the new method.
2738 remote_threads_info (struct target_ops
*ops
)
2740 struct remote_state
*rs
= get_remote_state ();
2744 if (rs
->remote_desc
== 0) /* paranoia */
2745 error (_("Command can only be used when connected to the remote target."));
2747 #if defined(HAVE_LIBEXPAT)
2748 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2750 char *xml
= target_read_stralloc (¤t_target
,
2751 TARGET_OBJECT_THREADS
, NULL
);
2753 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2757 struct threads_parsing_context context
;
2759 context
.items
= NULL
;
2760 make_cleanup (clear_threads_parsing_context
, &context
);
2762 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2763 threads_elements
, xml
, &context
) == 0)
2766 struct thread_item
*item
;
2769 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2772 if (!ptid_equal (item
->ptid
, null_ptid
))
2774 struct private_thread_info
*info
;
2775 /* In non-stop mode, we assume new found threads
2776 are running until proven otherwise with a
2777 stop reply. In all-stop, we can only get
2778 here if all threads are stopped. */
2779 int running
= non_stop
? 1 : 0;
2781 remote_notice_new_inferior (item
->ptid
, running
);
2783 info
= demand_private_info (item
->ptid
);
2784 info
->core
= item
->core
;
2785 info
->extra
= item
->extra
;
2792 do_cleanups (back_to
);
2797 if (use_threadinfo_query
)
2799 putpkt ("qfThreadInfo");
2800 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2802 if (bufp
[0] != '\0') /* q packet recognized */
2804 struct cleanup
*old_chain
;
2807 /* remote_notice_new_inferior (in the loop below) may make
2808 new RSP calls, which clobber rs->buf. Work with a
2810 bufp
= saved_reply
= xstrdup (rs
->buf
);
2811 old_chain
= make_cleanup (free_current_contents
, &saved_reply
);
2813 while (*bufp
++ == 'm') /* reply contains one or more TID */
2817 new_thread
= read_ptid (bufp
, &bufp
);
2818 if (!ptid_equal (new_thread
, null_ptid
))
2820 /* In non-stop mode, we assume new found threads
2821 are running until proven otherwise with a
2822 stop reply. In all-stop, we can only get
2823 here if all threads are stopped. */
2824 int running
= non_stop
? 1 : 0;
2826 remote_notice_new_inferior (new_thread
, running
);
2829 while (*bufp
++ == ','); /* comma-separated list */
2830 free_current_contents (&saved_reply
);
2831 putpkt ("qsThreadInfo");
2832 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2833 bufp
= saved_reply
= xstrdup (rs
->buf
);
2835 do_cleanups (old_chain
);
2840 /* Only qfThreadInfo is supported in non-stop mode. */
2844 /* Else fall back to old method based on jmetzler protocol. */
2845 use_threadinfo_query
= 0;
2846 remote_find_new_threads ();
2851 * Collect a descriptive string about the given thread.
2852 * The target may say anything it wants to about the thread
2853 * (typically info about its blocked / runnable state, name, etc.).
2854 * This string will appear in the info threads display.
2856 * Optional: targets are not required to implement this function.
2860 remote_threads_extra_info (struct thread_info
*tp
)
2862 struct remote_state
*rs
= get_remote_state ();
2866 struct gdb_ext_thread_info threadinfo
;
2867 static char display_buf
[100]; /* arbitrary... */
2868 int n
= 0; /* position in display_buf */
2870 if (rs
->remote_desc
== 0) /* paranoia */
2871 internal_error (__FILE__
, __LINE__
,
2872 _("remote_threads_extra_info"));
2874 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2875 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2876 /* This is the main thread which was added by GDB. The remote
2877 server doesn't know about it. */
2880 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2882 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2884 if (info
&& info
->private)
2885 return info
->private->extra
;
2890 if (use_threadextra_query
)
2893 char *endb
= rs
->buf
+ get_remote_packet_size ();
2895 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2897 write_ptid (b
, endb
, tp
->ptid
);
2900 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2901 if (rs
->buf
[0] != 0)
2903 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2904 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2905 display_buf
[result
] = '\0';
2910 /* If the above query fails, fall back to the old method. */
2911 use_threadextra_query
= 0;
2912 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2913 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2914 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2915 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2916 if (threadinfo
.active
)
2918 if (*threadinfo
.shortname
)
2919 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2920 " Name: %s,", threadinfo
.shortname
);
2921 if (*threadinfo
.display
)
2922 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2923 " State: %s,", threadinfo
.display
);
2924 if (*threadinfo
.more_display
)
2925 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2926 " Priority: %s", threadinfo
.more_display
);
2930 /* For purely cosmetic reasons, clear up trailing commas. */
2931 if (',' == display_buf
[n
-1])
2932 display_buf
[n
-1] = ' ';
2941 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2942 struct static_tracepoint_marker
*marker
)
2944 struct remote_state
*rs
= get_remote_state ();
2947 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2949 p
+= hexnumstr (p
, addr
);
2951 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2955 error (_("Remote failure reply: %s"), p
);
2959 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2966 static VEC(static_tracepoint_marker_p
) *
2967 remote_static_tracepoint_markers_by_strid (const char *strid
)
2969 struct remote_state
*rs
= get_remote_state ();
2970 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2971 struct static_tracepoint_marker
*marker
= NULL
;
2972 struct cleanup
*old_chain
;
2975 /* Ask for a first packet of static tracepoint marker
2978 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2981 error (_("Remote failure reply: %s"), p
);
2983 old_chain
= make_cleanup (free_current_marker
, &marker
);
2988 marker
= XCNEW (struct static_tracepoint_marker
);
2992 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2994 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2996 VEC_safe_push (static_tracepoint_marker_p
,
3002 release_static_tracepoint_marker (marker
);
3003 memset (marker
, 0, sizeof (*marker
));
3006 while (*p
++ == ','); /* comma-separated list */
3007 /* Ask for another packet of static tracepoint definition. */
3009 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3013 do_cleanups (old_chain
);
3018 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3021 remote_get_ada_task_ptid (long lwp
, long thread
)
3023 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
3027 /* Restart the remote side; this is an extended protocol operation. */
3030 extended_remote_restart (void)
3032 struct remote_state
*rs
= get_remote_state ();
3034 /* Send the restart command; for reasons I don't understand the
3035 remote side really expects a number after the "R". */
3036 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3039 remote_fileio_reset ();
3042 /* Clean up connection to a remote debugger. */
3047 struct remote_state
*rs
= get_remote_state ();
3049 if (rs
->remote_desc
== NULL
)
3050 return; /* already closed */
3052 /* Make sure we leave stdin registered in the event loop, and we
3053 don't leave the async SIGINT signal handler installed. */
3054 remote_terminal_ours ();
3056 serial_close (rs
->remote_desc
);
3057 rs
->remote_desc
= NULL
;
3059 /* We don't have a connection to the remote stub anymore. Get rid
3060 of all the inferiors and their threads we were controlling.
3061 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3062 will be unable to find the thread corresponding to (pid, 0, 0). */
3063 inferior_ptid
= null_ptid
;
3064 discard_all_inferiors ();
3066 /* Stop replies may from inferiors which are still unknown to GDB.
3067 We are closing the remote target, so we should discard
3068 everything, including the stop replies from GDB-unknown
3070 discard_pending_stop_replies (NULL
);
3072 if (remote_async_inferior_event_token
)
3073 delete_async_event_handler (&remote_async_inferior_event_token
);
3075 remote_notif_unregister_async_event_handler ();
3077 trace_reset_local_state ();
3080 /* Query the remote side for the text, data and bss offsets. */
3085 struct remote_state
*rs
= get_remote_state ();
3088 int lose
, num_segments
= 0, do_sections
, do_segments
;
3089 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3090 struct section_offsets
*offs
;
3091 struct symfile_segment_data
*data
;
3093 if (symfile_objfile
== NULL
)
3096 putpkt ("qOffsets");
3097 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3100 if (buf
[0] == '\000')
3101 return; /* Return silently. Stub doesn't support
3105 warning (_("Remote failure reply: %s"), buf
);
3109 /* Pick up each field in turn. This used to be done with scanf, but
3110 scanf will make trouble if CORE_ADDR size doesn't match
3111 conversion directives correctly. The following code will work
3112 with any size of CORE_ADDR. */
3113 text_addr
= data_addr
= bss_addr
= 0;
3117 if (strncmp (ptr
, "Text=", 5) == 0)
3120 /* Don't use strtol, could lose on big values. */
3121 while (*ptr
&& *ptr
!= ';')
3122 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3124 if (strncmp (ptr
, ";Data=", 6) == 0)
3127 while (*ptr
&& *ptr
!= ';')
3128 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3133 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3136 while (*ptr
&& *ptr
!= ';')
3137 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3139 if (bss_addr
!= data_addr
)
3140 warning (_("Target reported unsupported offsets: %s"), buf
);
3145 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3148 /* Don't use strtol, could lose on big values. */
3149 while (*ptr
&& *ptr
!= ';')
3150 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3153 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3156 while (*ptr
&& *ptr
!= ';')
3157 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3165 error (_("Malformed response to offset query, %s"), buf
);
3166 else if (*ptr
!= '\0')
3167 warning (_("Target reported unsupported offsets: %s"), buf
);
3169 offs
= ((struct section_offsets
*)
3170 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3171 memcpy (offs
, symfile_objfile
->section_offsets
,
3172 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3174 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3175 do_segments
= (data
!= NULL
);
3176 do_sections
= num_segments
== 0;
3178 if (num_segments
> 0)
3180 segments
[0] = text_addr
;
3181 segments
[1] = data_addr
;
3183 /* If we have two segments, we can still try to relocate everything
3184 by assuming that the .text and .data offsets apply to the whole
3185 text and data segments. Convert the offsets given in the packet
3186 to base addresses for symfile_map_offsets_to_segments. */
3187 else if (data
&& data
->num_segments
== 2)
3189 segments
[0] = data
->segment_bases
[0] + text_addr
;
3190 segments
[1] = data
->segment_bases
[1] + data_addr
;
3193 /* If the object file has only one segment, assume that it is text
3194 rather than data; main programs with no writable data are rare,
3195 but programs with no code are useless. Of course the code might
3196 have ended up in the data segment... to detect that we would need
3197 the permissions here. */
3198 else if (data
&& data
->num_segments
== 1)
3200 segments
[0] = data
->segment_bases
[0] + text_addr
;
3203 /* There's no way to relocate by segment. */
3209 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3210 offs
, num_segments
, segments
);
3212 if (ret
== 0 && !do_sections
)
3213 error (_("Can not handle qOffsets TextSeg "
3214 "response with this symbol file"));
3221 free_symfile_segment_data (data
);
3225 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3227 /* This is a temporary kludge to force data and bss to use the
3228 same offsets because that's what nlmconv does now. The real
3229 solution requires changes to the stub and remote.c that I
3230 don't have time to do right now. */
3232 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3233 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3236 objfile_relocate (symfile_objfile
, offs
);
3239 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3240 threads we know are stopped already. This is used during the
3241 initial remote connection in non-stop mode --- threads that are
3242 reported as already being stopped are left stopped. */
3245 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3247 /* If we have a stop reply for this thread, it must be stopped. */
3248 if (peek_stop_reply (thread
->ptid
))
3249 set_stop_requested (thread
->ptid
, 1);
3254 /* Send interrupt_sequence to remote target. */
3256 send_interrupt_sequence (void)
3258 struct remote_state
*rs
= get_remote_state ();
3260 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3261 remote_serial_write ("\x03", 1);
3262 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3263 serial_send_break (rs
->remote_desc
);
3264 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3266 serial_send_break (rs
->remote_desc
);
3267 remote_serial_write ("g", 1);
3270 internal_error (__FILE__
, __LINE__
,
3271 _("Invalid value for interrupt_sequence_mode: %s."),
3272 interrupt_sequence_mode
);
3276 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3277 and extract the PTID. Returns NULL_PTID if not found. */
3280 stop_reply_extract_thread (char *stop_reply
)
3282 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3286 /* Txx r:val ; r:val (...) */
3289 /* Look for "register" named "thread". */
3294 p1
= strchr (p
, ':');
3298 if (strncmp (p
, "thread", p1
- p
) == 0)
3299 return read_ptid (++p1
, &p
);
3301 p1
= strchr (p
, ';');
3313 /* Query the remote target for which is the current thread/process,
3314 add it to our tables, and update INFERIOR_PTID. The caller is
3315 responsible for setting the state such that the remote end is ready
3316 to return the current thread.
3318 This function is called after handling the '?' or 'vRun' packets,
3319 whose response is a stop reply from which we can also try
3320 extracting the thread. If the target doesn't support the explicit
3321 qC query, we infer the current thread from that stop reply, passed
3322 in in WAIT_STATUS, which may be NULL. */
3325 add_current_inferior_and_thread (char *wait_status
)
3327 struct remote_state
*rs
= get_remote_state ();
3329 ptid_t ptid
= null_ptid
;
3331 inferior_ptid
= null_ptid
;
3333 /* Now, if we have thread information, update inferior_ptid. First
3334 if we have a stop reply handy, maybe it's a T stop reply with a
3335 "thread" register we can extract the current thread from. If
3336 not, ask the remote which is the current thread, with qC. The
3337 former method avoids a roundtrip. Note we don't use
3338 remote_parse_stop_reply as that makes use of the target
3339 architecture, which we haven't yet fully determined at this
3341 if (wait_status
!= NULL
)
3342 ptid
= stop_reply_extract_thread (wait_status
);
3343 if (ptid_equal (ptid
, null_ptid
))
3344 ptid
= remote_current_thread (inferior_ptid
);
3346 if (!ptid_equal (ptid
, null_ptid
))
3348 if (!remote_multi_process_p (rs
))
3351 inferior_ptid
= ptid
;
3355 /* Without this, some commands which require an active target
3356 (such as kill) won't work. This variable serves (at least)
3357 double duty as both the pid of the target process (if it has
3358 such), and as a flag indicating that a target is active. */
3359 inferior_ptid
= magic_null_ptid
;
3363 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3365 /* Add the main thread. */
3366 add_thread_silent (inferior_ptid
);
3370 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3372 struct remote_state
*rs
= get_remote_state ();
3373 struct packet_config
*noack_config
;
3374 char *wait_status
= NULL
;
3376 immediate_quit
++; /* Allow user to interrupt it. */
3379 if (interrupt_on_connect
)
3380 send_interrupt_sequence ();
3382 /* Ack any packet which the remote side has already sent. */
3383 serial_write (rs
->remote_desc
, "+", 1);
3385 /* Signal other parts that we're going through the initial setup,
3386 and so things may not be stable yet. */
3387 rs
->starting_up
= 1;
3389 /* The first packet we send to the target is the optional "supported
3390 packets" request. If the target can answer this, it will tell us
3391 which later probes to skip. */
3392 remote_query_supported ();
3394 /* If the stub wants to get a QAllow, compose one and send it. */
3395 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3396 remote_set_permissions ();
3398 /* Next, we possibly activate noack mode.
3400 If the QStartNoAckMode packet configuration is set to AUTO,
3401 enable noack mode if the stub reported a wish for it with
3404 If set to TRUE, then enable noack mode even if the stub didn't
3405 report it in qSupported. If the stub doesn't reply OK, the
3406 session ends with an error.
3408 If FALSE, then don't activate noack mode, regardless of what the
3409 stub claimed should be the default with qSupported. */
3411 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3413 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3414 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3415 && noack_config
->support
== PACKET_ENABLE
))
3417 putpkt ("QStartNoAckMode");
3418 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3419 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3425 /* Tell the remote that we are using the extended protocol. */
3427 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3430 /* Let the target know which signals it is allowed to pass down to
3432 update_signals_program_target ();
3434 /* Next, if the target can specify a description, read it. We do
3435 this before anything involving memory or registers. */
3436 target_find_description ();
3438 /* Next, now that we know something about the target, update the
3439 address spaces in the program spaces. */
3440 update_address_spaces ();
3442 /* On OSs where the list of libraries is global to all
3443 processes, we fetch them early. */
3444 if (gdbarch_has_global_solist (target_gdbarch ()))
3445 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3449 if (!rs
->non_stop_aware
)
3450 error (_("Non-stop mode requested, but remote "
3451 "does not support non-stop"));
3453 putpkt ("QNonStop:1");
3454 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3456 if (strcmp (rs
->buf
, "OK") != 0)
3457 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3459 /* Find about threads and processes the stub is already
3460 controlling. We default to adding them in the running state.
3461 The '?' query below will then tell us about which threads are
3463 remote_threads_info (target
);
3465 else if (rs
->non_stop_aware
)
3467 /* Don't assume that the stub can operate in all-stop mode.
3468 Request it explicitly. */
3469 putpkt ("QNonStop:0");
3470 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3472 if (strcmp (rs
->buf
, "OK") != 0)
3473 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3476 /* Upload TSVs regardless of whether the target is running or not. The
3477 remote stub, such as GDBserver, may have some predefined or builtin
3478 TSVs, even if the target is not running. */
3479 if (remote_get_trace_status (current_trace_status ()) != -1)
3481 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3483 remote_upload_trace_state_variables (&uploaded_tsvs
);
3484 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3487 /* Check whether the target is running now. */
3489 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3495 struct inferior
*inf
;
3497 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3500 error (_("The target is not running (try extended-remote?)"));
3502 /* We're connected, but not running. Drop out before we
3503 call start_remote. */
3504 rs
->starting_up
= 0;
3509 /* Save the reply for later. */
3510 wait_status
= alloca (strlen (rs
->buf
) + 1);
3511 strcpy (wait_status
, rs
->buf
);
3514 /* Let the stub know that we want it to return the thread. */
3515 set_continue_thread (minus_one_ptid
);
3517 add_current_inferior_and_thread (wait_status
);
3519 /* init_wait_for_inferior should be called before get_offsets in order
3520 to manage `inserted' flag in bp loc in a correct state.
3521 breakpoint_init_inferior, called from init_wait_for_inferior, set
3522 `inserted' flag to 0, while before breakpoint_re_set, called from
3523 start_remote, set `inserted' flag to 1. In the initialization of
3524 inferior, breakpoint_init_inferior should be called first, and then
3525 breakpoint_re_set can be called. If this order is broken, state of
3526 `inserted' flag is wrong, and cause some problems on breakpoint
3528 init_wait_for_inferior ();
3530 get_offsets (); /* Get text, data & bss offsets. */
3532 /* If we could not find a description using qXfer, and we know
3533 how to do it some other way, try again. This is not
3534 supported for non-stop; it could be, but it is tricky if
3535 there are no stopped threads when we connect. */
3536 if (remote_read_description_p (target
)
3537 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3539 target_clear_description ();
3540 target_find_description ();
3543 /* Use the previously fetched status. */
3544 gdb_assert (wait_status
!= NULL
);
3545 strcpy (rs
->buf
, wait_status
);
3546 rs
->cached_wait_status
= 1;
3549 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3553 /* Clear WFI global state. Do this before finding about new
3554 threads and inferiors, and setting the current inferior.
3555 Otherwise we would clear the proceed status of the current
3556 inferior when we want its stop_soon state to be preserved
3557 (see notice_new_inferior). */
3558 init_wait_for_inferior ();
3560 /* In non-stop, we will either get an "OK", meaning that there
3561 are no stopped threads at this time; or, a regular stop
3562 reply. In the latter case, there may be more than one thread
3563 stopped --- we pull them all out using the vStopped
3565 if (strcmp (rs
->buf
, "OK") != 0)
3567 struct notif_client
*notif
= ¬if_client_stop
;
3569 /* remote_notif_get_pending_replies acks this one, and gets
3571 notif_client_stop
.pending_event
3572 = remote_notif_parse (notif
, rs
->buf
);
3573 remote_notif_get_pending_events (notif
);
3575 /* Make sure that threads that were stopped remain
3577 iterate_over_threads (set_stop_requested_callback
, NULL
);
3580 if (target_can_async_p ())
3581 target_async (inferior_event_handler
, 0);
3583 if (thread_count () == 0)
3586 error (_("The target is not running (try extended-remote?)"));
3588 /* We're connected, but not running. Drop out before we
3589 call start_remote. */
3590 rs
->starting_up
= 0;
3594 /* Let the stub know that we want it to return the thread. */
3596 /* Force the stub to choose a thread. */
3597 set_general_thread (null_ptid
);
3600 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3601 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3602 error (_("remote didn't report the current thread in non-stop mode"));
3604 get_offsets (); /* Get text, data & bss offsets. */
3606 /* In non-stop mode, any cached wait status will be stored in
3607 the stop reply queue. */
3608 gdb_assert (wait_status
== NULL
);
3610 /* Report all signals during attach/startup. */
3611 remote_pass_signals (0, NULL
);
3614 /* If we connected to a live target, do some additional setup. */
3615 if (target_has_execution
)
3617 if (exec_bfd
) /* No use without an exec file. */
3618 remote_check_symbols ();
3621 /* Possibly the target has been engaged in a trace run started
3622 previously; find out where things are at. */
3623 if (remote_get_trace_status (current_trace_status ()) != -1)
3625 struct uploaded_tp
*uploaded_tps
= NULL
;
3627 if (current_trace_status ()->running
)
3628 printf_filtered (_("Trace is already running on the target.\n"));
3630 remote_upload_tracepoints (&uploaded_tps
);
3632 merge_uploaded_tracepoints (&uploaded_tps
);
3635 /* The thread and inferior lists are now synchronized with the
3636 target, our symbols have been relocated, and we're merged the
3637 target's tracepoints with ours. We're done with basic start
3639 rs
->starting_up
= 0;
3641 /* If breakpoints are global, insert them now. */
3642 if (gdbarch_has_global_breakpoints (target_gdbarch ())
3643 && breakpoints_always_inserted_mode ())
3644 insert_breakpoints ();
3647 /* Open a connection to a remote debugger.
3648 NAME is the filename used for communication. */
3651 remote_open (char *name
, int from_tty
)
3653 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3656 /* Open a connection to a remote debugger using the extended
3657 remote gdb protocol. NAME is the filename used for communication. */
3660 extended_remote_open (char *name
, int from_tty
)
3662 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3665 /* Generic code for opening a connection to a remote target. */
3668 init_all_packet_configs (void)
3672 for (i
= 0; i
< PACKET_MAX
; i
++)
3673 update_packet_config (&remote_protocol_packets
[i
]);
3676 /* Symbol look-up. */
3679 remote_check_symbols (void)
3681 struct remote_state
*rs
= get_remote_state ();
3682 char *msg
, *reply
, *tmp
;
3683 struct minimal_symbol
*sym
;
3686 /* The remote side has no concept of inferiors that aren't running
3687 yet, it only knows about running processes. If we're connected
3688 but our current inferior is not running, we should not invite the
3689 remote target to request symbol lookups related to its
3690 (unrelated) current process. */
3691 if (!target_has_execution
)
3694 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3697 /* Make sure the remote is pointing at the right process. Note
3698 there's no way to select "no process". */
3699 set_general_process ();
3701 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3702 because we need both at the same time. */
3703 msg
= alloca (get_remote_packet_size ());
3705 /* Invite target to request symbol lookups. */
3707 putpkt ("qSymbol::");
3708 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3709 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3712 while (strncmp (reply
, "qSymbol:", 8) == 0)
3715 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3717 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3719 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3722 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3723 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3725 /* If this is a function address, return the start of code
3726 instead of any data function descriptor. */
3727 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3731 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3732 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3736 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3741 static struct serial
*
3742 remote_serial_open (char *name
)
3744 static int udp_warning
= 0;
3746 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3747 of in ser-tcp.c, because it is the remote protocol assuming that the
3748 serial connection is reliable and not the serial connection promising
3750 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3752 warning (_("The remote protocol may be unreliable over UDP.\n"
3753 "Some events may be lost, rendering further debugging "
3758 return serial_open (name
);
3761 /* Inform the target of our permission settings. The permission flags
3762 work without this, but if the target knows the settings, it can do
3763 a couple things. First, it can add its own check, to catch cases
3764 that somehow manage to get by the permissions checks in target
3765 methods. Second, if the target is wired to disallow particular
3766 settings (for instance, a system in the field that is not set up to
3767 be able to stop at a breakpoint), it can object to any unavailable
3771 remote_set_permissions (void)
3773 struct remote_state
*rs
= get_remote_state ();
3775 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3776 "WriteReg:%x;WriteMem:%x;"
3777 "InsertBreak:%x;InsertTrace:%x;"
3778 "InsertFastTrace:%x;Stop:%x",
3779 may_write_registers
, may_write_memory
,
3780 may_insert_breakpoints
, may_insert_tracepoints
,
3781 may_insert_fast_tracepoints
, may_stop
);
3783 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3785 /* If the target didn't like the packet, warn the user. Do not try
3786 to undo the user's settings, that would just be maddening. */
3787 if (strcmp (rs
->buf
, "OK") != 0)
3788 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3791 /* This type describes each known response to the qSupported
3793 struct protocol_feature
3795 /* The name of this protocol feature. */
3798 /* The default for this protocol feature. */
3799 enum packet_support default_support
;
3801 /* The function to call when this feature is reported, or after
3802 qSupported processing if the feature is not supported.
3803 The first argument points to this structure. The second
3804 argument indicates whether the packet requested support be
3805 enabled, disabled, or probed (or the default, if this function
3806 is being called at the end of processing and this feature was
3807 not reported). The third argument may be NULL; if not NULL, it
3808 is a NUL-terminated string taken from the packet following
3809 this feature's name and an equals sign. */
3810 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3813 /* The corresponding packet for this feature. Only used if
3814 FUNC is remote_supported_packet. */
3819 remote_supported_packet (const struct protocol_feature
*feature
,
3820 enum packet_support support
,
3821 const char *argument
)
3825 warning (_("Remote qSupported response supplied an unexpected value for"
3826 " \"%s\"."), feature
->name
);
3830 if (remote_protocol_packets
[feature
->packet
].support
3831 == PACKET_SUPPORT_UNKNOWN
)
3832 remote_protocol_packets
[feature
->packet
].support
= support
;
3836 remote_packet_size (const struct protocol_feature
*feature
,
3837 enum packet_support support
, const char *value
)
3839 struct remote_state
*rs
= get_remote_state ();
3844 if (support
!= PACKET_ENABLE
)
3847 if (value
== NULL
|| *value
== '\0')
3849 warning (_("Remote target reported \"%s\" without a size."),
3855 packet_size
= strtol (value
, &value_end
, 16);
3856 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3858 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3859 feature
->name
, value
);
3863 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3865 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3866 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3867 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3870 /* Record the new maximum packet size. */
3871 rs
->explicit_packet_size
= packet_size
;
3875 remote_multi_process_feature (const struct protocol_feature
*feature
,
3876 enum packet_support support
, const char *value
)
3878 struct remote_state
*rs
= get_remote_state ();
3880 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3884 remote_non_stop_feature (const struct protocol_feature
*feature
,
3885 enum packet_support support
, const char *value
)
3887 struct remote_state
*rs
= get_remote_state ();
3889 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3893 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3894 enum packet_support support
,
3897 struct remote_state
*rs
= get_remote_state ();
3899 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3903 remote_cond_breakpoint_feature (const struct protocol_feature
*feature
,
3904 enum packet_support support
,
3907 struct remote_state
*rs
= get_remote_state ();
3909 rs
->cond_breakpoints
= (support
== PACKET_ENABLE
);
3913 remote_breakpoint_commands_feature (const struct protocol_feature
*feature
,
3914 enum packet_support support
,
3917 struct remote_state
*rs
= get_remote_state ();
3919 rs
->breakpoint_commands
= (support
== PACKET_ENABLE
);
3923 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3924 enum packet_support support
,
3927 struct remote_state
*rs
= get_remote_state ();
3929 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3933 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3934 enum packet_support support
,
3937 struct remote_state
*rs
= get_remote_state ();
3939 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3943 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3944 enum packet_support support
,
3947 struct remote_state
*rs
= get_remote_state ();
3949 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3953 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3954 enum packet_support support
,
3957 struct remote_state
*rs
= get_remote_state ();
3959 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3963 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3964 enum packet_support support
,
3967 struct remote_state
*rs
= get_remote_state ();
3969 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3973 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3974 enum packet_support support
,
3977 struct remote_state
*rs
= get_remote_state ();
3979 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3983 remote_augmented_libraries_svr4_read_feature
3984 (const struct protocol_feature
*feature
,
3985 enum packet_support support
, const char *value
)
3987 struct remote_state
*rs
= get_remote_state ();
3989 rs
->augmented_libraries_svr4_read
= (support
== PACKET_ENABLE
);
3992 static const struct protocol_feature remote_protocol_features
[] = {
3993 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3994 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3995 PACKET_qXfer_auxv
},
3996 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3997 PACKET_qXfer_features
},
3998 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3999 PACKET_qXfer_libraries
},
4000 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4001 PACKET_qXfer_libraries_svr4
},
4002 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4003 remote_augmented_libraries_svr4_read_feature
, -1 },
4004 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4005 PACKET_qXfer_memory_map
},
4006 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4007 PACKET_qXfer_spu_read
},
4008 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4009 PACKET_qXfer_spu_write
},
4010 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4011 PACKET_qXfer_osdata
},
4012 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4013 PACKET_qXfer_threads
},
4014 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4015 PACKET_qXfer_traceframe_info
},
4016 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4017 PACKET_QPassSignals
},
4018 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4019 PACKET_QProgramSignals
},
4020 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4021 PACKET_QStartNoAckMode
},
4022 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
4023 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
4024 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4025 PACKET_qXfer_siginfo_read
},
4026 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4027 PACKET_qXfer_siginfo_write
},
4028 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
4029 PACKET_ConditionalTracepoints
},
4030 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_cond_breakpoint_feature
,
4031 PACKET_ConditionalBreakpoints
},
4032 { "BreakpointCommands", PACKET_DISABLE
, remote_breakpoint_commands_feature
,
4033 PACKET_BreakpointCommands
},
4034 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
4035 PACKET_FastTracepoints
},
4036 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
4037 PACKET_StaticTracepoints
},
4038 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
4039 PACKET_InstallInTrace
},
4040 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
4042 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4044 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4046 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4047 PACKET_TracepointSource
},
4048 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4050 { "EnableDisableTracepoints", PACKET_DISABLE
,
4051 remote_enable_disable_tracepoint_feature
, -1 },
4052 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4053 PACKET_qXfer_fdpic
},
4054 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4056 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4057 PACKET_QDisableRandomization
},
4058 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4059 { "QTBuffer:size", PACKET_DISABLE
,
4060 remote_supported_packet
, PACKET_QTBuffer_size
},
4061 { "tracenz", PACKET_DISABLE
,
4062 remote_string_tracing_feature
, -1 },
4063 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4064 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4065 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4066 PACKET_qXfer_btrace
}
4069 static char *remote_support_xml
;
4071 /* Register string appended to "xmlRegisters=" in qSupported query. */
4074 register_remote_support_xml (const char *xml
)
4076 #if defined(HAVE_LIBEXPAT)
4077 if (remote_support_xml
== NULL
)
4078 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4081 char *copy
= xstrdup (remote_support_xml
+ 13);
4082 char *p
= strtok (copy
, ",");
4086 if (strcmp (p
, xml
) == 0)
4093 while ((p
= strtok (NULL
, ",")) != NULL
);
4096 remote_support_xml
= reconcat (remote_support_xml
,
4097 remote_support_xml
, ",", xml
,
4104 remote_query_supported_append (char *msg
, const char *append
)
4107 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4109 return xstrdup (append
);
4113 remote_query_supported (void)
4115 struct remote_state
*rs
= get_remote_state ();
4118 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4120 /* The packet support flags are handled differently for this packet
4121 than for most others. We treat an error, a disabled packet, and
4122 an empty response identically: any features which must be reported
4123 to be used will be automatically disabled. An empty buffer
4124 accomplishes this, since that is also the representation for a list
4125 containing no features. */
4128 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
4131 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4133 q
= remote_query_supported_append (q
, "multiprocess+");
4135 if (remote_support_xml
)
4136 q
= remote_query_supported_append (q
, remote_support_xml
);
4138 q
= remote_query_supported_append (q
, "qRelocInsn+");
4140 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4143 do_cleanups (old_chain
);
4145 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4147 /* If an error occured, warn, but do not return - just reset the
4148 buffer to empty and go on to disable features. */
4149 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4152 warning (_("Remote failure reply: %s"), rs
->buf
);
4157 memset (seen
, 0, sizeof (seen
));
4162 enum packet_support is_supported
;
4163 char *p
, *end
, *name_end
, *value
;
4165 /* First separate out this item from the rest of the packet. If
4166 there's another item after this, we overwrite the separator
4167 (terminated strings are much easier to work with). */
4169 end
= strchr (p
, ';');
4172 end
= p
+ strlen (p
);
4182 warning (_("empty item in \"qSupported\" response"));
4187 name_end
= strchr (p
, '=');
4190 /* This is a name=value entry. */
4191 is_supported
= PACKET_ENABLE
;
4192 value
= name_end
+ 1;
4201 is_supported
= PACKET_ENABLE
;
4205 is_supported
= PACKET_DISABLE
;
4209 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4213 warning (_("unrecognized item \"%s\" "
4214 "in \"qSupported\" response"), p
);
4220 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4221 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4223 const struct protocol_feature
*feature
;
4226 feature
= &remote_protocol_features
[i
];
4227 feature
->func (feature
, is_supported
, value
);
4232 /* If we increased the packet size, make sure to increase the global
4233 buffer size also. We delay this until after parsing the entire
4234 qSupported packet, because this is the same buffer we were
4236 if (rs
->buf_size
< rs
->explicit_packet_size
)
4238 rs
->buf_size
= rs
->explicit_packet_size
;
4239 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4242 /* Handle the defaults for unmentioned features. */
4243 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4246 const struct protocol_feature
*feature
;
4248 feature
= &remote_protocol_features
[i
];
4249 feature
->func (feature
, feature
->default_support
, NULL
);
4253 /* Remove any of the remote.c targets from target stack. Upper targets depend
4254 on it so remove them first. */
4257 remote_unpush_target (void)
4259 pop_all_targets_above (process_stratum
- 1);
4263 remote_open_1 (char *name
, int from_tty
,
4264 struct target_ops
*target
, int extended_p
)
4266 struct remote_state
*rs
= get_remote_state ();
4269 error (_("To open a remote debug connection, you need to specify what\n"
4270 "serial device is attached to the remote system\n"
4271 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4273 /* See FIXME above. */
4274 if (!target_async_permitted
)
4275 wait_forever_enabled_p
= 1;
4277 /* If we're connected to a running target, target_preopen will kill it.
4278 Ask this question first, before target_preopen has a chance to kill
4280 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4283 && !query (_("Already connected to a remote target. Disconnect? ")))
4284 error (_("Still connected."));
4287 /* Here the possibly existing remote target gets unpushed. */
4288 target_preopen (from_tty
);
4290 /* Make sure we send the passed signals list the next time we resume. */
4291 xfree (rs
->last_pass_packet
);
4292 rs
->last_pass_packet
= NULL
;
4294 /* Make sure we send the program signals list the next time we
4296 xfree (rs
->last_program_signals_packet
);
4297 rs
->last_program_signals_packet
= NULL
;
4299 remote_fileio_reset ();
4300 reopen_exec_file ();
4303 rs
->remote_desc
= remote_serial_open (name
);
4304 if (!rs
->remote_desc
)
4305 perror_with_name (name
);
4307 if (baud_rate
!= -1)
4309 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4311 /* The requested speed could not be set. Error out to
4312 top level after closing remote_desc. Take care to
4313 set remote_desc to NULL to avoid closing remote_desc
4315 serial_close (rs
->remote_desc
);
4316 rs
->remote_desc
= NULL
;
4317 perror_with_name (name
);
4321 serial_raw (rs
->remote_desc
);
4323 /* If there is something sitting in the buffer we might take it as a
4324 response to a command, which would be bad. */
4325 serial_flush_input (rs
->remote_desc
);
4329 puts_filtered ("Remote debugging using ");
4330 puts_filtered (name
);
4331 puts_filtered ("\n");
4333 push_target (target
); /* Switch to using remote target now. */
4335 /* Register extra event sources in the event loop. */
4336 remote_async_inferior_event_token
4337 = create_async_event_handler (remote_async_inferior_event_handler
,
4339 remote_notif_register_async_event_handler ();
4341 /* Reset the target state; these things will be queried either by
4342 remote_query_supported or as they are needed. */
4343 init_all_packet_configs ();
4344 rs
->cached_wait_status
= 0;
4345 rs
->explicit_packet_size
= 0;
4347 rs
->multi_process_aware
= 0;
4348 rs
->extended
= extended_p
;
4349 rs
->non_stop_aware
= 0;
4350 rs
->waiting_for_stop_reply
= 0;
4351 rs
->ctrlc_pending_p
= 0;
4353 rs
->general_thread
= not_sent_ptid
;
4354 rs
->continue_thread
= not_sent_ptid
;
4355 rs
->remote_traceframe_number
= -1;
4357 /* Probe for ability to use "ThreadInfo" query, as required. */
4358 use_threadinfo_query
= 1;
4359 use_threadextra_query
= 1;
4361 if (target_async_permitted
)
4363 /* With this target we start out by owning the terminal. */
4364 remote_async_terminal_ours_p
= 1;
4366 /* FIXME: cagney/1999-09-23: During the initial connection it is
4367 assumed that the target is already ready and able to respond to
4368 requests. Unfortunately remote_start_remote() eventually calls
4369 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4370 around this. Eventually a mechanism that allows
4371 wait_for_inferior() to expect/get timeouts will be
4373 wait_forever_enabled_p
= 0;
4376 /* First delete any symbols previously loaded from shared libraries. */
4377 no_shared_libraries (NULL
, 0);
4380 init_thread_list ();
4382 /* Start the remote connection. If error() or QUIT, discard this
4383 target (we'd otherwise be in an inconsistent state) and then
4384 propogate the error on up the exception chain. This ensures that
4385 the caller doesn't stumble along blindly assuming that the
4386 function succeeded. The CLI doesn't have this problem but other
4387 UI's, such as MI do.
4389 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4390 this function should return an error indication letting the
4391 caller restore the previous state. Unfortunately the command
4392 ``target remote'' is directly wired to this function making that
4393 impossible. On a positive note, the CLI side of this problem has
4394 been fixed - the function set_cmd_context() makes it possible for
4395 all the ``target ....'' commands to share a common callback
4396 function. See cli-dump.c. */
4398 volatile struct gdb_exception ex
;
4400 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4402 remote_start_remote (from_tty
, target
, extended_p
);
4406 /* Pop the partially set up target - unless something else did
4407 already before throwing the exception. */
4408 if (rs
->remote_desc
!= NULL
)
4409 remote_unpush_target ();
4410 if (target_async_permitted
)
4411 wait_forever_enabled_p
= 1;
4412 throw_exception (ex
);
4416 if (target_async_permitted
)
4417 wait_forever_enabled_p
= 1;
4420 /* This takes a program previously attached to and detaches it. After
4421 this is done, GDB can be used to debug some other program. We
4422 better not have left any breakpoints in the target program or it'll
4423 die when it hits one. */
4426 remote_detach_1 (char *args
, int from_tty
, int extended
)
4428 int pid
= ptid_get_pid (inferior_ptid
);
4429 struct remote_state
*rs
= get_remote_state ();
4432 error (_("Argument given to \"detach\" when remotely debugging."));
4434 if (!target_has_execution
)
4435 error (_("No process to detach from."));
4439 char *exec_file
= get_exec_file (0);
4440 if (exec_file
== NULL
)
4442 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4443 target_pid_to_str (pid_to_ptid (pid
)));
4444 gdb_flush (gdb_stdout
);
4447 /* Tell the remote target to detach. */
4448 if (remote_multi_process_p (rs
))
4449 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4451 strcpy (rs
->buf
, "D");
4454 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4456 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4458 else if (rs
->buf
[0] == '\0')
4459 error (_("Remote doesn't know how to detach"));
4461 error (_("Can't detach process."));
4463 if (from_tty
&& !extended
)
4464 puts_filtered (_("Ending remote debugging.\n"));
4466 target_mourn_inferior ();
4470 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4472 remote_detach_1 (args
, from_tty
, 0);
4476 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4478 remote_detach_1 (args
, from_tty
, 1);
4481 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4484 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4487 error (_("Argument given to \"disconnect\" when remotely debugging."));
4489 /* Make sure we unpush even the extended remote targets; mourn
4490 won't do it. So call remote_mourn_1 directly instead of
4491 target_mourn_inferior. */
4492 remote_mourn_1 (target
);
4495 puts_filtered ("Ending remote debugging.\n");
4498 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4499 be chatty about it. */
4502 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4504 struct remote_state
*rs
= get_remote_state ();
4506 char *wait_status
= NULL
;
4508 pid
= parse_pid_to_attach (args
);
4510 /* Remote PID can be freely equal to getpid, do not check it here the same
4511 way as in other targets. */
4513 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4514 error (_("This target does not support attaching to a process"));
4518 char *exec_file
= get_exec_file (0);
4521 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4522 target_pid_to_str (pid_to_ptid (pid
)));
4524 printf_unfiltered (_("Attaching to %s\n"),
4525 target_pid_to_str (pid_to_ptid (pid
)));
4527 gdb_flush (gdb_stdout
);
4530 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4532 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4534 if (packet_ok (rs
->buf
,
4535 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4539 /* Save the reply for later. */
4540 wait_status
= alloca (strlen (rs
->buf
) + 1);
4541 strcpy (wait_status
, rs
->buf
);
4543 else if (strcmp (rs
->buf
, "OK") != 0)
4544 error (_("Attaching to %s failed with: %s"),
4545 target_pid_to_str (pid_to_ptid (pid
)),
4548 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4549 error (_("This target does not support attaching to a process"));
4551 error (_("Attaching to %s failed"),
4552 target_pid_to_str (pid_to_ptid (pid
)));
4554 set_current_inferior (remote_add_inferior (0, pid
, 1));
4556 inferior_ptid
= pid_to_ptid (pid
);
4560 struct thread_info
*thread
;
4562 /* Get list of threads. */
4563 remote_threads_info (target
);
4565 thread
= first_thread_of_process (pid
);
4567 inferior_ptid
= thread
->ptid
;
4569 inferior_ptid
= pid_to_ptid (pid
);
4571 /* Invalidate our notion of the remote current thread. */
4572 record_currthread (rs
, minus_one_ptid
);
4576 /* Now, if we have thread information, update inferior_ptid. */
4577 inferior_ptid
= remote_current_thread (inferior_ptid
);
4579 /* Add the main thread to the thread list. */
4580 add_thread_silent (inferior_ptid
);
4583 /* Next, if the target can specify a description, read it. We do
4584 this before anything involving memory or registers. */
4585 target_find_description ();
4589 /* Use the previously fetched status. */
4590 gdb_assert (wait_status
!= NULL
);
4592 if (target_can_async_p ())
4594 struct notif_event
*reply
4595 = remote_notif_parse (¬if_client_stop
, wait_status
);
4597 push_stop_reply ((struct stop_reply
*) reply
);
4599 target_async (inferior_event_handler
, 0);
4603 gdb_assert (wait_status
!= NULL
);
4604 strcpy (rs
->buf
, wait_status
);
4605 rs
->cached_wait_status
= 1;
4609 gdb_assert (wait_status
== NULL
);
4613 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4615 extended_remote_attach_1 (ops
, args
, from_tty
);
4618 /* Convert hex digit A to a number. */
4623 if (a
>= '0' && a
<= '9')
4625 else if (a
>= 'a' && a
<= 'f')
4626 return a
- 'a' + 10;
4627 else if (a
>= 'A' && a
<= 'F')
4628 return a
- 'A' + 10;
4630 error (_("Reply contains invalid hex digit %d"), a
);
4634 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4638 for (i
= 0; i
< count
; i
++)
4640 if (hex
[0] == 0 || hex
[1] == 0)
4642 /* Hex string is short, or of uneven length.
4643 Return the count that has been converted so far. */
4646 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4652 /* Convert number NIB to a hex digit. */
4660 return 'a' + nib
- 10;
4664 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4668 /* May use a length, or a nul-terminated string as input. */
4670 count
= strlen ((char *) bin
);
4672 for (i
= 0; i
< count
; i
++)
4674 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4675 *hex
++ = tohex (*bin
++ & 0xf);
4681 /* Check for the availability of vCont. This function should also check
4685 remote_vcont_probe (struct remote_state
*rs
)
4689 strcpy (rs
->buf
, "vCont?");
4691 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4694 /* Make sure that the features we assume are supported. */
4695 if (strncmp (buf
, "vCont", 5) == 0)
4698 int support_s
, support_S
, support_c
, support_C
;
4704 rs
->supports_vCont
.t
= 0;
4705 rs
->supports_vCont
.r
= 0;
4706 while (p
&& *p
== ';')
4709 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4711 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4713 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4715 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4717 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4718 rs
->supports_vCont
.t
= 1;
4719 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4720 rs
->supports_vCont
.r
= 1;
4722 p
= strchr (p
, ';');
4725 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4726 BUF will make packet_ok disable the packet. */
4727 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4731 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4734 /* Helper function for building "vCont" resumptions. Write a
4735 resumption to P. ENDP points to one-passed-the-end of the buffer
4736 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4737 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4738 resumed thread should be single-stepped and/or signalled. If PTID
4739 equals minus_one_ptid, then all threads are resumed; if PTID
4740 represents a process, then all threads of the process are resumed;
4741 the thread to be stepped and/or signalled is given in the global
4745 append_resumption (char *p
, char *endp
,
4746 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4748 struct remote_state
*rs
= get_remote_state ();
4750 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4751 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4753 /* GDB is willing to range step. */
4754 && use_range_stepping
4755 /* Target supports range stepping. */
4756 && rs
->supports_vCont
.r
4757 /* We don't currently support range stepping multiple
4758 threads with a wildcard (though the protocol allows it,
4759 so stubs shouldn't make an active effort to forbid
4761 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4763 struct thread_info
*tp
;
4765 if (ptid_equal (ptid
, minus_one_ptid
))
4767 /* If we don't know about the target thread's tid, then
4768 we're resuming magic_null_ptid (see caller). */
4769 tp
= find_thread_ptid (magic_null_ptid
);
4772 tp
= find_thread_ptid (ptid
);
4773 gdb_assert (tp
!= NULL
);
4775 if (tp
->control
.may_range_step
)
4777 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4779 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
4780 phex_nz (tp
->control
.step_range_start
,
4782 phex_nz (tp
->control
.step_range_end
,
4786 p
+= xsnprintf (p
, endp
- p
, ";s");
4789 p
+= xsnprintf (p
, endp
- p
, ";s");
4790 else if (siggnal
!= GDB_SIGNAL_0
)
4791 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4793 p
+= xsnprintf (p
, endp
- p
, ";c");
4795 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4799 /* All (-1) threads of process. */
4800 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4802 p
+= xsnprintf (p
, endp
- p
, ":");
4803 p
= write_ptid (p
, endp
, nptid
);
4805 else if (!ptid_equal (ptid
, minus_one_ptid
))
4807 p
+= xsnprintf (p
, endp
- p
, ":");
4808 p
= write_ptid (p
, endp
, ptid
);
4814 /* Append a vCont continue-with-signal action for threads that have a
4815 non-zero stop signal. */
4818 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4820 struct thread_info
*thread
;
4822 ALL_THREADS (thread
)
4823 if (ptid_match (thread
->ptid
, ptid
)
4824 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4825 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4826 && signal_pass_state (thread
->suspend
.stop_signal
))
4828 p
= append_resumption (p
, endp
, thread
->ptid
,
4829 0, thread
->suspend
.stop_signal
);
4830 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4836 /* Resume the remote inferior by using a "vCont" packet. The thread
4837 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4838 resumed thread should be single-stepped and/or signalled. If PTID
4839 equals minus_one_ptid, then all threads are resumed; the thread to
4840 be stepped and/or signalled is given in the global INFERIOR_PTID.
4841 This function returns non-zero iff it resumes the inferior.
4843 This function issues a strict subset of all possible vCont commands at the
4847 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4849 struct remote_state
*rs
= get_remote_state ();
4853 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4854 remote_vcont_probe (rs
);
4856 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4860 endp
= rs
->buf
+ get_remote_packet_size ();
4862 /* If we could generate a wider range of packets, we'd have to worry
4863 about overflowing BUF. Should there be a generic
4864 "multi-part-packet" packet? */
4866 p
+= xsnprintf (p
, endp
- p
, "vCont");
4868 if (ptid_equal (ptid
, magic_null_ptid
))
4870 /* MAGIC_NULL_PTID means that we don't have any active threads,
4871 so we don't have any TID numbers the inferior will
4872 understand. Make sure to only send forms that do not specify
4874 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4876 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4878 /* Resume all threads (of all processes, or of a single
4879 process), with preference for INFERIOR_PTID. This assumes
4880 inferior_ptid belongs to the set of all threads we are about
4882 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4884 /* Step inferior_ptid, with or without signal. */
4885 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4888 /* Also pass down any pending signaled resumption for other
4889 threads not the current. */
4890 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4892 /* And continue others without a signal. */
4893 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4897 /* Scheduler locking; resume only PTID. */
4898 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4901 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4906 /* In non-stop, the stub replies to vCont with "OK". The stop
4907 reply will be reported asynchronously by means of a `%Stop'
4909 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4910 if (strcmp (rs
->buf
, "OK") != 0)
4911 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4917 /* Tell the remote machine to resume. */
4920 remote_resume (struct target_ops
*ops
,
4921 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4923 struct remote_state
*rs
= get_remote_state ();
4926 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4927 (explained in remote-notif.c:handle_notification) so
4928 remote_notif_process is not called. We need find a place where
4929 it is safe to start a 'vNotif' sequence. It is good to do it
4930 before resuming inferior, because inferior was stopped and no RSP
4931 traffic at that moment. */
4933 remote_notif_process (¬if_client_stop
);
4935 rs
->last_sent_signal
= siggnal
;
4936 rs
->last_sent_step
= step
;
4938 /* The vCont packet doesn't need to specify threads via Hc. */
4939 /* No reverse support (yet) for vCont. */
4940 if (execution_direction
!= EXEC_REVERSE
)
4941 if (remote_vcont_resume (ptid
, step
, siggnal
))
4944 /* All other supported resume packets do use Hc, so set the continue
4946 if (ptid_equal (ptid
, minus_one_ptid
))
4947 set_continue_thread (any_thread_ptid
);
4949 set_continue_thread (ptid
);
4952 if (execution_direction
== EXEC_REVERSE
)
4954 /* We don't pass signals to the target in reverse exec mode. */
4955 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4956 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4960 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4961 error (_("Remote reverse-step not supported."));
4963 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4964 error (_("Remote reverse-continue not supported."));
4966 strcpy (buf
, step
? "bs" : "bc");
4968 else if (siggnal
!= GDB_SIGNAL_0
)
4970 buf
[0] = step
? 'S' : 'C';
4971 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4972 buf
[2] = tohex (((int) siggnal
) & 0xf);
4976 strcpy (buf
, step
? "s" : "c");
4981 /* We are about to start executing the inferior, let's register it
4982 with the event loop. NOTE: this is the one place where all the
4983 execution commands end up. We could alternatively do this in each
4984 of the execution commands in infcmd.c. */
4985 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4986 into infcmd.c in order to allow inferior function calls to work
4987 NOT asynchronously. */
4988 if (target_can_async_p ())
4989 target_async (inferior_event_handler
, 0);
4991 /* We've just told the target to resume. The remote server will
4992 wait for the inferior to stop, and then send a stop reply. In
4993 the mean time, we can't start another command/query ourselves
4994 because the stub wouldn't be ready to process it. This applies
4995 only to the base all-stop protocol, however. In non-stop (which
4996 only supports vCont), the stub replies with an "OK", and is
4997 immediate able to process further serial input. */
4999 rs
->waiting_for_stop_reply
= 1;
5003 /* Set up the signal handler for SIGINT, while the target is
5004 executing, ovewriting the 'regular' SIGINT signal handler. */
5006 async_initialize_sigint_signal_handler (void)
5008 signal (SIGINT
, async_handle_remote_sigint
);
5011 /* Signal handler for SIGINT, while the target is executing. */
5013 async_handle_remote_sigint (int sig
)
5015 signal (sig
, async_handle_remote_sigint_twice
);
5016 mark_async_signal_handler (async_sigint_remote_token
);
5019 /* Signal handler for SIGINT, installed after SIGINT has already been
5020 sent once. It will take effect the second time that the user sends
5023 async_handle_remote_sigint_twice (int sig
)
5025 signal (sig
, async_handle_remote_sigint
);
5026 mark_async_signal_handler (async_sigint_remote_twice_token
);
5029 /* Perform the real interruption of the target execution, in response
5032 async_remote_interrupt (gdb_client_data arg
)
5035 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5037 target_stop (inferior_ptid
);
5040 /* Perform interrupt, if the first attempt did not succeed. Just give
5041 up on the target alltogether. */
5043 async_remote_interrupt_twice (gdb_client_data arg
)
5046 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5051 /* Reinstall the usual SIGINT handlers, after the target has
5054 async_cleanup_sigint_signal_handler (void *dummy
)
5056 signal (SIGINT
, handle_sigint
);
5059 /* Send ^C to target to halt it. Target will respond, and send us a
5061 static void (*ofunc
) (int);
5063 /* The command line interface's stop routine. This function is installed
5064 as a signal handler for SIGINT. The first time a user requests a
5065 stop, we call remote_stop to send a break or ^C. If there is no
5066 response from the target (it didn't stop when the user requested it),
5067 we ask the user if he'd like to detach from the target. */
5069 sync_remote_interrupt (int signo
)
5071 /* If this doesn't work, try more severe steps. */
5072 signal (signo
, sync_remote_interrupt_twice
);
5074 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5077 /* The user typed ^C twice. */
5080 sync_remote_interrupt_twice (int signo
)
5082 signal (signo
, ofunc
);
5083 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5084 signal (signo
, sync_remote_interrupt
);
5087 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5088 thread, all threads of a remote process, or all threads of all
5092 remote_stop_ns (ptid_t ptid
)
5094 struct remote_state
*rs
= get_remote_state ();
5096 char *endp
= rs
->buf
+ get_remote_packet_size ();
5098 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
5099 remote_vcont_probe (rs
);
5101 if (!rs
->supports_vCont
.t
)
5102 error (_("Remote server does not support stopping threads"));
5104 if (ptid_equal (ptid
, minus_one_ptid
)
5105 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5106 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5111 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5113 if (ptid_is_pid (ptid
))
5114 /* All (-1) threads of process. */
5115 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
5118 /* Small optimization: if we already have a stop reply for
5119 this thread, no use in telling the stub we want this
5121 if (peek_stop_reply (ptid
))
5127 write_ptid (p
, endp
, nptid
);
5130 /* In non-stop, we get an immediate OK reply. The stop reply will
5131 come in asynchronously by notification. */
5133 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5134 if (strcmp (rs
->buf
, "OK") != 0)
5135 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5138 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5139 remote target. It is undefined which thread of which process
5140 reports the stop. */
5143 remote_stop_as (ptid_t ptid
)
5145 struct remote_state
*rs
= get_remote_state ();
5147 rs
->ctrlc_pending_p
= 1;
5149 /* If the inferior is stopped already, but the core didn't know
5150 about it yet, just ignore the request. The cached wait status
5151 will be collected in remote_wait. */
5152 if (rs
->cached_wait_status
)
5155 /* Send interrupt_sequence to remote target. */
5156 send_interrupt_sequence ();
5159 /* This is the generic stop called via the target vector. When a target
5160 interrupt is requested, either by the command line or the GUI, we
5161 will eventually end up here. */
5164 remote_stop (ptid_t ptid
)
5167 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5170 remote_stop_ns (ptid
);
5172 remote_stop_as (ptid
);
5175 /* Ask the user what to do when an interrupt is received. */
5178 interrupt_query (void)
5180 target_terminal_ours ();
5182 if (target_can_async_p ())
5184 signal (SIGINT
, handle_sigint
);
5189 if (query (_("Interrupted while waiting for the program.\n\
5190 Give up (and stop debugging it)? ")))
5192 remote_unpush_target ();
5197 target_terminal_inferior ();
5200 /* Enable/disable target terminal ownership. Most targets can use
5201 terminal groups to control terminal ownership. Remote targets are
5202 different in that explicit transfer of ownership to/from GDB/target
5206 remote_terminal_inferior (void)
5208 if (!target_async_permitted
)
5209 /* Nothing to do. */
5212 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5213 idempotent. The event-loop GDB talking to an asynchronous target
5214 with a synchronous command calls this function from both
5215 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5216 transfer the terminal to the target when it shouldn't this guard
5218 if (!remote_async_terminal_ours_p
)
5220 delete_file_handler (input_fd
);
5221 remote_async_terminal_ours_p
= 0;
5222 async_initialize_sigint_signal_handler ();
5223 /* NOTE: At this point we could also register our selves as the
5224 recipient of all input. Any characters typed could then be
5225 passed on down to the target. */
5229 remote_terminal_ours (void)
5231 if (!target_async_permitted
)
5232 /* Nothing to do. */
5235 /* See FIXME in remote_terminal_inferior. */
5236 if (remote_async_terminal_ours_p
)
5238 async_cleanup_sigint_signal_handler (NULL
);
5239 add_file_handler (input_fd
, stdin_event_handler
, 0);
5240 remote_async_terminal_ours_p
= 1;
5244 remote_console_output (char *msg
)
5248 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5251 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5255 fputs_unfiltered (tb
, gdb_stdtarg
);
5257 gdb_flush (gdb_stdtarg
);
5260 typedef struct cached_reg
5263 gdb_byte data
[MAX_REGISTER_SIZE
];
5266 DEF_VEC_O(cached_reg_t
);
5268 typedef struct stop_reply
5270 struct notif_event base
;
5272 /* The identifier of the thread about this event */
5275 struct target_waitstatus ws
;
5277 /* Expedited registers. This makes remote debugging a bit more
5278 efficient for those targets that provide critical registers as
5279 part of their normal status mechanism (as another roundtrip to
5280 fetch them is avoided). */
5281 VEC(cached_reg_t
) *regcache
;
5283 int stopped_by_watchpoint_p
;
5284 CORE_ADDR watch_data_address
;
5292 DECLARE_QUEUE_P (stop_reply_p
);
5293 DEFINE_QUEUE_P (stop_reply_p
);
5294 /* The list of already fetched and acknowledged stop events. This
5295 queue is used for notification Stop, and other notifications
5296 don't need queue for their events, because the notification events
5297 of Stop can't be consumed immediately, so that events should be
5298 queued first, and be consumed by remote_wait_{ns,as} one per
5299 time. Other notifications can consume their events immediately,
5300 so queue is not needed for them. */
5301 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5304 stop_reply_xfree (struct stop_reply
*r
)
5308 VEC_free (cached_reg_t
, r
->regcache
);
5314 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5315 struct notif_event
*event
)
5317 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5321 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5322 struct notif_event
*event
)
5324 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5327 putpkt ((char *) self
->ack_command
);
5329 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5330 /* We got an unknown stop reply. */
5331 error (_("Unknown stop reply"));
5333 push_stop_reply (stop_reply
);
5337 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5339 /* We can't get pending events in remote_notif_process for
5340 notification stop, and we have to do this in remote_wait_ns
5341 instead. If we fetch all queued events from stub, remote stub
5342 may exit and we have no chance to process them back in
5344 mark_async_event_handler (remote_async_inferior_event_token
);
5349 stop_reply_dtr (struct notif_event
*event
)
5351 struct stop_reply
*r
= (struct stop_reply
*) event
;
5353 VEC_free (cached_reg_t
, r
->regcache
);
5356 static struct notif_event
*
5357 remote_notif_stop_alloc_reply (void)
5359 struct notif_event
*r
5360 = (struct notif_event
*) XMALLOC (struct stop_reply
);
5362 r
->dtr
= stop_reply_dtr
;
5367 /* A client of notification Stop. */
5369 struct notif_client notif_client_stop
=
5373 remote_notif_stop_parse
,
5374 remote_notif_stop_ack
,
5375 remote_notif_stop_can_get_pending_events
,
5376 remote_notif_stop_alloc_reply
,
5380 /* A parameter to pass data in and out. */
5382 struct queue_iter_param
5385 struct stop_reply
*output
;
5388 /* Remove all queue elements meet the condition it checks. */
5391 remote_notif_remove_all (QUEUE (stop_reply_p
) *q
,
5392 QUEUE_ITER (stop_reply_p
) *iter
,
5396 struct queue_iter_param
*param
= data
;
5397 struct inferior
*inf
= param
->input
;
5399 if (inf
== NULL
|| ptid_get_pid (event
->ptid
) == inf
->pid
)
5401 stop_reply_xfree (event
);
5402 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5408 /* Discard all pending stop replies of inferior INF. If INF is NULL,
5409 discard everything. */
5412 discard_pending_stop_replies (struct inferior
*inf
)
5415 struct queue_iter_param param
;
5416 struct stop_reply
*reply
5417 = (struct stop_reply
*) notif_client_stop
.pending_event
;
5419 /* Discard the in-flight notification. */
5422 || ptid_get_pid (reply
->ptid
) == inf
->pid
))
5424 stop_reply_xfree (reply
);
5425 notif_client_stop
.pending_event
= NULL
;
5429 param
.output
= NULL
;
5430 /* Discard the stop replies we have already pulled with
5432 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5433 remote_notif_remove_all
, ¶m
);
5436 /* A parameter to pass data in and out. */
5439 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5440 QUEUE_ITER (stop_reply_p
) *iter
,
5444 struct queue_iter_param
*param
= data
;
5445 ptid_t
*ptid
= param
->input
;
5447 if (ptid_match (event
->ptid
, *ptid
))
5449 param
->output
= event
;
5450 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5457 /* Remove the first reply in 'stop_reply_queue' which matches
5460 static struct stop_reply
*
5461 remote_notif_remove_queued_reply (ptid_t ptid
)
5463 struct queue_iter_param param
;
5465 param
.input
= &ptid
;
5466 param
.output
= NULL
;
5468 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5469 remote_notif_remove_once_on_match
, ¶m
);
5471 fprintf_unfiltered (gdb_stdlog
,
5472 "notif: discard queued event: 'Stop' in %s\n",
5473 target_pid_to_str (ptid
));
5475 return param
.output
;
5478 /* Look for a queued stop reply belonging to PTID. If one is found,
5479 remove it from the queue, and return it. Returns NULL if none is
5480 found. If there are still queued events left to process, tell the
5481 event loop to get back to target_wait soon. */
5483 static struct stop_reply
*
5484 queued_stop_reply (ptid_t ptid
)
5486 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5488 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5489 /* There's still at least an event left. */
5490 mark_async_event_handler (remote_async_inferior_event_token
);
5495 /* Push a fully parsed stop reply in the stop reply queue. Since we
5496 know that we now have at least one queued event left to pass to the
5497 core side, tell the event loop to get back to target_wait soon. */
5500 push_stop_reply (struct stop_reply
*new_event
)
5502 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5505 fprintf_unfiltered (gdb_stdlog
,
5506 "notif: push 'Stop' %s to queue %d\n",
5507 target_pid_to_str (new_event
->ptid
),
5508 QUEUE_length (stop_reply_p
,
5511 mark_async_event_handler (remote_async_inferior_event_token
);
5515 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5516 QUEUE_ITER (stop_reply_p
) *iter
,
5517 struct stop_reply
*event
,
5520 ptid_t
*ptid
= data
;
5522 return !(ptid_equal (*ptid
, event
->ptid
)
5523 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5526 /* Returns true if we have a stop reply for PTID. */
5529 peek_stop_reply (ptid_t ptid
)
5531 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5532 stop_reply_match_ptid_and_ws
, &ptid
);
5535 /* Parse the stop reply in BUF. Either the function succeeds, and the
5536 result is stored in EVENT, or throws an error. */
5539 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5541 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5545 event
->ptid
= null_ptid
;
5546 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5547 event
->ws
.value
.integer
= 0;
5548 event
->solibs_changed
= 0;
5549 event
->replay_event
= 0;
5550 event
->stopped_by_watchpoint_p
= 0;
5551 event
->regcache
= NULL
;
5556 case 'T': /* Status with PC, SP, FP, ... */
5557 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5558 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5560 n... = register number
5561 r... = register contents
5564 p
= &buf
[3]; /* after Txx */
5572 /* If the packet contains a register number, save it in
5573 pnum and set p1 to point to the character following it.
5574 Otherwise p1 points to p. */
5576 /* If this packet is an awatch packet, don't parse the 'a'
5577 as a register number. */
5579 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5580 && strncmp (p
, "core", strlen ("core") != 0))
5582 /* Read the ``P'' register number. */
5583 pnum
= strtol (p
, &p_temp
, 16);
5589 if (p1
== p
) /* No register number present here. */
5591 p1
= strchr (p
, ':');
5593 error (_("Malformed packet(a) (missing colon): %s\n\
5596 if (strncmp (p
, "thread", p1
- p
) == 0)
5597 event
->ptid
= read_ptid (++p1
, &p
);
5598 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5599 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5600 || (strncmp (p
, "awatch", p1
- p
) == 0))
5602 event
->stopped_by_watchpoint_p
= 1;
5603 p
= unpack_varlen_hex (++p1
, &addr
);
5604 event
->watch_data_address
= (CORE_ADDR
) addr
;
5606 else if (strncmp (p
, "library", p1
- p
) == 0)
5610 while (*p_temp
&& *p_temp
!= ';')
5613 event
->solibs_changed
= 1;
5616 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5618 /* NO_HISTORY event.
5619 p1 will indicate "begin" or "end", but
5620 it makes no difference for now, so ignore it. */
5621 event
->replay_event
= 1;
5622 p_temp
= strchr (p1
+ 1, ';');
5626 else if (strncmp (p
, "core", p1
- p
) == 0)
5630 p
= unpack_varlen_hex (++p1
, &c
);
5635 /* Silently skip unknown optional info. */
5636 p_temp
= strchr (p1
+ 1, ';');
5643 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5644 cached_reg_t cached_reg
;
5649 error (_("Malformed packet(b) (missing colon): %s\n\
5655 error (_("Remote sent bad register number %s: %s\n\
5657 hex_string (pnum
), p
, buf
);
5659 cached_reg
.num
= reg
->regnum
;
5661 fieldsize
= hex2bin (p
, cached_reg
.data
,
5662 register_size (target_gdbarch (),
5665 if (fieldsize
< register_size (target_gdbarch (),
5667 warning (_("Remote reply is too short: %s"), buf
);
5669 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5673 error (_("Remote register badly formatted: %s\nhere: %s"),
5678 case 'S': /* Old style status, just signal only. */
5679 if (event
->solibs_changed
)
5680 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5681 else if (event
->replay_event
)
5682 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5685 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5686 event
->ws
.value
.sig
= (enum gdb_signal
)
5687 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5690 case 'W': /* Target exited. */
5697 /* GDB used to accept only 2 hex chars here. Stubs should
5698 only send more if they detect GDB supports multi-process
5700 p
= unpack_varlen_hex (&buf
[1], &value
);
5704 /* The remote process exited. */
5705 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5706 event
->ws
.value
.integer
= value
;
5710 /* The remote process exited with a signal. */
5711 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5712 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5715 /* If no process is specified, assume inferior_ptid. */
5716 pid
= ptid_get_pid (inferior_ptid
);
5725 else if (strncmp (p
,
5726 "process:", sizeof ("process:") - 1) == 0)
5730 p
+= sizeof ("process:") - 1;
5731 unpack_varlen_hex (p
, &upid
);
5735 error (_("unknown stop reply packet: %s"), buf
);
5738 error (_("unknown stop reply packet: %s"), buf
);
5739 event
->ptid
= pid_to_ptid (pid
);
5744 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5745 error (_("No process or thread specified in stop reply: %s"), buf
);
5748 /* When the stub wants to tell GDB about a new notification reply, it
5749 sends a notification (%Stop, for example). Those can come it at
5750 any time, hence, we have to make sure that any pending
5751 putpkt/getpkt sequence we're making is finished, before querying
5752 the stub for more events with the corresponding ack command
5753 (vStopped, for example). E.g., if we started a vStopped sequence
5754 immediately upon receiving the notification, something like this
5762 1.6) <-- (registers reply to step #1.3)
5764 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5767 To solve this, whenever we parse a %Stop notification successfully,
5768 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5769 doing whatever we were doing:
5775 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5776 2.5) <-- (registers reply to step #2.3)
5778 Eventualy after step #2.5, we return to the event loop, which
5779 notices there's an event on the
5780 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5781 associated callback --- the function below. At this point, we're
5782 always safe to start a vStopped sequence. :
5785 2.7) <-- T05 thread:2
5791 remote_notif_get_pending_events (struct notif_client
*nc
)
5793 struct remote_state
*rs
= get_remote_state ();
5795 if (nc
->pending_event
)
5798 fprintf_unfiltered (gdb_stdlog
,
5799 "notif: process: '%s' ack pending event\n",
5803 nc
->ack (nc
, rs
->buf
, nc
->pending_event
);
5804 nc
->pending_event
= NULL
;
5808 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5809 if (strcmp (rs
->buf
, "OK") == 0)
5812 remote_notif_ack (nc
, rs
->buf
);
5818 fprintf_unfiltered (gdb_stdlog
,
5819 "notif: process: '%s' no pending reply\n",
5824 /* Called when it is decided that STOP_REPLY holds the info of the
5825 event that is to be returned to the core. This function always
5826 destroys STOP_REPLY. */
5829 process_stop_reply (struct stop_reply
*stop_reply
,
5830 struct target_waitstatus
*status
)
5834 *status
= stop_reply
->ws
;
5835 ptid
= stop_reply
->ptid
;
5837 /* If no thread/process was reported by the stub, assume the current
5839 if (ptid_equal (ptid
, null_ptid
))
5840 ptid
= inferior_ptid
;
5842 if (status
->kind
!= TARGET_WAITKIND_EXITED
5843 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5845 /* Expedited registers. */
5846 if (stop_reply
->regcache
)
5848 struct regcache
*regcache
5849 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5854 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5856 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5857 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5860 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5861 remote_watch_data_address
= stop_reply
->watch_data_address
;
5863 remote_notice_new_inferior (ptid
, 0);
5864 demand_private_info (ptid
)->core
= stop_reply
->core
;
5867 stop_reply_xfree (stop_reply
);
5871 /* The non-stop mode version of target_wait. */
5874 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5876 struct remote_state
*rs
= get_remote_state ();
5877 struct stop_reply
*stop_reply
;
5881 /* If in non-stop mode, get out of getpkt even if a
5882 notification is received. */
5884 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5885 0 /* forever */, &is_notif
);
5888 if (ret
!= -1 && !is_notif
)
5891 case 'E': /* Error of some sort. */
5892 /* We're out of sync with the target now. Did it continue
5893 or not? We can't tell which thread it was in non-stop,
5894 so just ignore this. */
5895 warning (_("Remote failure reply: %s"), rs
->buf
);
5897 case 'O': /* Console output. */
5898 remote_console_output (rs
->buf
+ 1);
5901 warning (_("Invalid remote reply: %s"), rs
->buf
);
5905 /* Acknowledge a pending stop reply that may have arrived in the
5907 if (notif_client_stop
.pending_event
!= NULL
)
5908 remote_notif_get_pending_events (¬if_client_stop
);
5910 /* If indeed we noticed a stop reply, we're done. */
5911 stop_reply
= queued_stop_reply (ptid
);
5912 if (stop_reply
!= NULL
)
5913 return process_stop_reply (stop_reply
, status
);
5915 /* Still no event. If we're just polling for an event, then
5916 return to the event loop. */
5917 if (options
& TARGET_WNOHANG
)
5919 status
->kind
= TARGET_WAITKIND_IGNORE
;
5920 return minus_one_ptid
;
5923 /* Otherwise do a blocking wait. */
5924 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5925 1 /* forever */, &is_notif
);
5929 /* Wait until the remote machine stops, then return, storing status in
5930 STATUS just as `wait' would. */
5933 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5935 struct remote_state
*rs
= get_remote_state ();
5936 ptid_t event_ptid
= null_ptid
;
5938 struct stop_reply
*stop_reply
;
5942 status
->kind
= TARGET_WAITKIND_IGNORE
;
5943 status
->value
.integer
= 0;
5945 stop_reply
= queued_stop_reply (ptid
);
5946 if (stop_reply
!= NULL
)
5947 return process_stop_reply (stop_reply
, status
);
5949 if (rs
->cached_wait_status
)
5950 /* Use the cached wait status, but only once. */
5951 rs
->cached_wait_status
= 0;
5957 if (!target_is_async_p ())
5959 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
5960 /* If the user hit C-c before this packet, or between packets,
5961 pretend that it was hit right here. */
5962 if (check_quit_flag ())
5965 sync_remote_interrupt (SIGINT
);
5969 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5970 _never_ wait for ever -> test on target_is_async_p().
5971 However, before we do that we need to ensure that the caller
5972 knows how to take the target into/out of async mode. */
5973 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5974 wait_forever_enabled_p
, &is_notif
);
5976 if (!target_is_async_p ())
5977 signal (SIGINT
, ofunc
);
5979 /* GDB gets a notification. Return to core as this event is
5981 if (ret
!= -1 && is_notif
)
5982 return minus_one_ptid
;
5987 remote_stopped_by_watchpoint_p
= 0;
5989 /* We got something. */
5990 rs
->waiting_for_stop_reply
= 0;
5992 /* Assume that the target has acknowledged Ctrl-C unless we receive
5993 an 'F' or 'O' packet. */
5994 if (buf
[0] != 'F' && buf
[0] != 'O')
5995 rs
->ctrlc_pending_p
= 0;
5999 case 'E': /* Error of some sort. */
6000 /* We're out of sync with the target now. Did it continue or
6001 not? Not is more likely, so report a stop. */
6002 warning (_("Remote failure reply: %s"), buf
);
6003 status
->kind
= TARGET_WAITKIND_STOPPED
;
6004 status
->value
.sig
= GDB_SIGNAL_0
;
6006 case 'F': /* File-I/O request. */
6007 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6008 rs
->ctrlc_pending_p
= 0;
6010 case 'T': case 'S': case 'X': case 'W':
6012 struct stop_reply
*stop_reply
6013 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6016 event_ptid
= process_stop_reply (stop_reply
, status
);
6019 case 'O': /* Console output. */
6020 remote_console_output (buf
+ 1);
6022 /* The target didn't really stop; keep waiting. */
6023 rs
->waiting_for_stop_reply
= 1;
6027 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6029 /* Zero length reply means that we tried 'S' or 'C' and the
6030 remote system doesn't support it. */
6031 target_terminal_ours_for_output ();
6033 ("Can't send signals to this remote system. %s not sent.\n",
6034 gdb_signal_to_name (rs
->last_sent_signal
));
6035 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6036 target_terminal_inferior ();
6038 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6039 putpkt ((char *) buf
);
6041 /* We just told the target to resume, so a stop reply is in
6043 rs
->waiting_for_stop_reply
= 1;
6046 /* else fallthrough */
6048 warning (_("Invalid remote reply: %s"), buf
);
6050 rs
->waiting_for_stop_reply
= 1;
6054 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6056 /* Nothing interesting happened. If we're doing a non-blocking
6057 poll, we're done. Otherwise, go back to waiting. */
6058 if (options
& TARGET_WNOHANG
)
6059 return minus_one_ptid
;
6063 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6064 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6066 if (!ptid_equal (event_ptid
, null_ptid
))
6067 record_currthread (rs
, event_ptid
);
6069 event_ptid
= inferior_ptid
;
6072 /* A process exit. Invalidate our notion of current thread. */
6073 record_currthread (rs
, minus_one_ptid
);
6078 /* Wait until the remote machine stops, then return, storing status in
6079 STATUS just as `wait' would. */
6082 remote_wait (struct target_ops
*ops
,
6083 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6088 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6090 event_ptid
= remote_wait_as (ptid
, status
, options
);
6092 if (target_can_async_p ())
6094 /* If there are are events left in the queue tell the event loop
6096 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6097 mark_async_event_handler (remote_async_inferior_event_token
);
6103 /* Fetch a single register using a 'p' packet. */
6106 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6108 struct remote_state
*rs
= get_remote_state ();
6110 char regp
[MAX_REGISTER_SIZE
];
6113 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
6116 if (reg
->pnum
== -1)
6121 p
+= hexnumstr (p
, reg
->pnum
);
6124 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6128 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6132 case PACKET_UNKNOWN
:
6135 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6136 gdbarch_register_name (get_regcache_arch (regcache
),
6141 /* If this register is unfetchable, tell the regcache. */
6144 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6148 /* Otherwise, parse and supply the value. */
6154 error (_("fetch_register_using_p: early buf termination"));
6156 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6159 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6163 /* Fetch the registers included in the target's 'g' packet. */
6166 send_g_packet (void)
6168 struct remote_state
*rs
= get_remote_state ();
6171 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6172 remote_send (&rs
->buf
, &rs
->buf_size
);
6174 /* We can get out of synch in various cases. If the first character
6175 in the buffer is not a hex character, assume that has happened
6176 and try to fetch another packet to read. */
6177 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6178 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6179 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6180 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6183 fprintf_unfiltered (gdb_stdlog
,
6184 "Bad register packet; fetching a new packet\n");
6185 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6188 buf_len
= strlen (rs
->buf
);
6190 /* Sanity check the received packet. */
6191 if (buf_len
% 2 != 0)
6192 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6198 process_g_packet (struct regcache
*regcache
)
6200 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6201 struct remote_state
*rs
= get_remote_state ();
6202 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6207 buf_len
= strlen (rs
->buf
);
6209 /* Further sanity checks, with knowledge of the architecture. */
6210 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6211 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6213 /* Save the size of the packet sent to us by the target. It is used
6214 as a heuristic when determining the max size of packets that the
6215 target can safely receive. */
6216 if (rsa
->actual_register_packet_size
== 0)
6217 rsa
->actual_register_packet_size
= buf_len
;
6219 /* If this is smaller than we guessed the 'g' packet would be,
6220 update our records. A 'g' reply that doesn't include a register's
6221 value implies either that the register is not available, or that
6222 the 'p' packet must be used. */
6223 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6225 rsa
->sizeof_g_packet
= buf_len
/ 2;
6227 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6229 if (rsa
->regs
[i
].pnum
== -1)
6232 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6233 rsa
->regs
[i
].in_g_packet
= 0;
6235 rsa
->regs
[i
].in_g_packet
= 1;
6239 regs
= alloca (rsa
->sizeof_g_packet
);
6241 /* Unimplemented registers read as all bits zero. */
6242 memset (regs
, 0, rsa
->sizeof_g_packet
);
6244 /* Reply describes registers byte by byte, each byte encoded as two
6245 hex characters. Suck them all up, then supply them to the
6246 register cacheing/storage mechanism. */
6249 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6251 if (p
[0] == 0 || p
[1] == 0)
6252 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6253 internal_error (__FILE__
, __LINE__
,
6254 _("unexpected end of 'g' packet reply"));
6256 if (p
[0] == 'x' && p
[1] == 'x')
6257 regs
[i
] = 0; /* 'x' */
6259 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6263 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6265 struct packet_reg
*r
= &rsa
->regs
[i
];
6269 if (r
->offset
* 2 >= strlen (rs
->buf
))
6270 /* This shouldn't happen - we adjusted in_g_packet above. */
6271 internal_error (__FILE__
, __LINE__
,
6272 _("unexpected end of 'g' packet reply"));
6273 else if (rs
->buf
[r
->offset
* 2] == 'x')
6275 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6276 /* The register isn't available, mark it as such (at
6277 the same time setting the value to zero). */
6278 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6281 regcache_raw_supply (regcache
, r
->regnum
,
6288 fetch_registers_using_g (struct regcache
*regcache
)
6291 process_g_packet (regcache
);
6294 /* Make the remote selected traceframe match GDB's selected
6298 set_remote_traceframe (void)
6301 struct remote_state
*rs
= get_remote_state ();
6303 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6306 /* Avoid recursion, remote_trace_find calls us again. */
6307 rs
->remote_traceframe_number
= get_traceframe_number ();
6309 newnum
= target_trace_find (tfind_number
,
6310 get_traceframe_number (), 0, 0, NULL
);
6312 /* Should not happen. If it does, all bets are off. */
6313 if (newnum
!= get_traceframe_number ())
6314 warning (_("could not set remote traceframe"));
6318 remote_fetch_registers (struct target_ops
*ops
,
6319 struct regcache
*regcache
, int regnum
)
6321 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6324 set_remote_traceframe ();
6325 set_general_thread (inferior_ptid
);
6329 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6331 gdb_assert (reg
!= NULL
);
6333 /* If this register might be in the 'g' packet, try that first -
6334 we are likely to read more than one register. If this is the
6335 first 'g' packet, we might be overly optimistic about its
6336 contents, so fall back to 'p'. */
6337 if (reg
->in_g_packet
)
6339 fetch_registers_using_g (regcache
);
6340 if (reg
->in_g_packet
)
6344 if (fetch_register_using_p (regcache
, reg
))
6347 /* This register is not available. */
6348 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6353 fetch_registers_using_g (regcache
);
6355 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6356 if (!rsa
->regs
[i
].in_g_packet
)
6357 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6359 /* This register is not available. */
6360 regcache_raw_supply (regcache
, i
, NULL
);
6364 /* Prepare to store registers. Since we may send them all (using a
6365 'G' request), we have to read out the ones we don't want to change
6369 remote_prepare_to_store (struct regcache
*regcache
)
6371 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6373 gdb_byte buf
[MAX_REGISTER_SIZE
];
6375 /* Make sure the entire registers array is valid. */
6376 switch (remote_protocol_packets
[PACKET_P
].support
)
6378 case PACKET_DISABLE
:
6379 case PACKET_SUPPORT_UNKNOWN
:
6380 /* Make sure all the necessary registers are cached. */
6381 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6382 if (rsa
->regs
[i
].in_g_packet
)
6383 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6390 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6391 packet was not recognized. */
6394 store_register_using_P (const struct regcache
*regcache
,
6395 struct packet_reg
*reg
)
6397 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6398 struct remote_state
*rs
= get_remote_state ();
6399 /* Try storing a single register. */
6400 char *buf
= rs
->buf
;
6401 gdb_byte regp
[MAX_REGISTER_SIZE
];
6404 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
6407 if (reg
->pnum
== -1)
6410 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6411 p
= buf
+ strlen (buf
);
6412 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6413 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6415 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6417 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6422 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6423 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6424 case PACKET_UNKNOWN
:
6427 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6431 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6432 contents of the register cache buffer. FIXME: ignores errors. */
6435 store_registers_using_G (const struct regcache
*regcache
)
6437 struct remote_state
*rs
= get_remote_state ();
6438 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6442 /* Extract all the registers in the regcache copying them into a
6447 regs
= alloca (rsa
->sizeof_g_packet
);
6448 memset (regs
, 0, rsa
->sizeof_g_packet
);
6449 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6451 struct packet_reg
*r
= &rsa
->regs
[i
];
6454 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6458 /* Command describes registers byte by byte,
6459 each byte encoded as two hex characters. */
6462 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6464 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6466 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6467 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6468 error (_("Could not write registers; remote failure reply '%s'"),
6472 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6473 of the register cache buffer. FIXME: ignores errors. */
6476 remote_store_registers (struct target_ops
*ops
,
6477 struct regcache
*regcache
, int regnum
)
6479 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6482 set_remote_traceframe ();
6483 set_general_thread (inferior_ptid
);
6487 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6489 gdb_assert (reg
!= NULL
);
6491 /* Always prefer to store registers using the 'P' packet if
6492 possible; we often change only a small number of registers.
6493 Sometimes we change a larger number; we'd need help from a
6494 higher layer to know to use 'G'. */
6495 if (store_register_using_P (regcache
, reg
))
6498 /* For now, don't complain if we have no way to write the
6499 register. GDB loses track of unavailable registers too
6500 easily. Some day, this may be an error. We don't have
6501 any way to read the register, either... */
6502 if (!reg
->in_g_packet
)
6505 store_registers_using_G (regcache
);
6509 store_registers_using_G (regcache
);
6511 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6512 if (!rsa
->regs
[i
].in_g_packet
)
6513 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6514 /* See above for why we do not issue an error here. */
6519 /* Return the number of hex digits in num. */
6522 hexnumlen (ULONGEST num
)
6526 for (i
= 0; num
!= 0; i
++)
6532 /* Set BUF to the minimum number of hex digits representing NUM. */
6535 hexnumstr (char *buf
, ULONGEST num
)
6537 int len
= hexnumlen (num
);
6539 return hexnumnstr (buf
, num
, len
);
6543 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6546 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6552 for (i
= width
- 1; i
>= 0; i
--)
6554 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6561 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6564 remote_address_masked (CORE_ADDR addr
)
6566 unsigned int address_size
= remote_address_size
;
6568 /* If "remoteaddresssize" was not set, default to target address size. */
6570 address_size
= gdbarch_addr_bit (target_gdbarch ());
6572 if (address_size
> 0
6573 && address_size
< (sizeof (ULONGEST
) * 8))
6575 /* Only create a mask when that mask can safely be constructed
6576 in a ULONGEST variable. */
6579 mask
= (mask
<< address_size
) - 1;
6585 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6586 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6587 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6588 (which may be more than *OUT_LEN due to escape characters). The
6589 total number of bytes in the output buffer will be at most
6593 remote_escape_output (const gdb_byte
*buffer
, int len
,
6594 gdb_byte
*out_buf
, int *out_len
,
6597 int input_index
, output_index
;
6600 for (input_index
= 0; input_index
< len
; input_index
++)
6602 gdb_byte b
= buffer
[input_index
];
6604 if (b
== '$' || b
== '#' || b
== '}')
6606 /* These must be escaped. */
6607 if (output_index
+ 2 > out_maxlen
)
6609 out_buf
[output_index
++] = '}';
6610 out_buf
[output_index
++] = b
^ 0x20;
6614 if (output_index
+ 1 > out_maxlen
)
6616 out_buf
[output_index
++] = b
;
6620 *out_len
= input_index
;
6621 return output_index
;
6624 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6625 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6626 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6628 This function reverses remote_escape_output. It allows more
6629 escaped characters than that function does, in particular because
6630 '*' must be escaped to avoid the run-length encoding processing
6631 in reading packets. */
6634 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6635 gdb_byte
*out_buf
, int out_maxlen
)
6637 int input_index
, output_index
;
6642 for (input_index
= 0; input_index
< len
; input_index
++)
6644 gdb_byte b
= buffer
[input_index
];
6646 if (output_index
+ 1 > out_maxlen
)
6648 warning (_("Received too much data from remote target;"
6649 " ignoring overflow."));
6650 return output_index
;
6655 out_buf
[output_index
++] = b
^ 0x20;
6661 out_buf
[output_index
++] = b
;
6665 error (_("Unmatched escape character in target response."));
6667 return output_index
;
6670 /* Determine whether the remote target supports binary downloading.
6671 This is accomplished by sending a no-op memory write of zero length
6672 to the target at the specified address. It does not suffice to send
6673 the whole packet, since many stubs strip the eighth bit and
6674 subsequently compute a wrong checksum, which causes real havoc with
6677 NOTE: This can still lose if the serial line is not eight-bit
6678 clean. In cases like this, the user should clear "remote
6682 check_binary_download (CORE_ADDR addr
)
6684 struct remote_state
*rs
= get_remote_state ();
6686 switch (remote_protocol_packets
[PACKET_X
].support
)
6688 case PACKET_DISABLE
:
6692 case PACKET_SUPPORT_UNKNOWN
:
6698 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6700 p
+= hexnumstr (p
, (ULONGEST
) 0);
6704 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6705 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6707 if (rs
->buf
[0] == '\0')
6710 fprintf_unfiltered (gdb_stdlog
,
6711 "binary downloading NOT "
6712 "supported by target\n");
6713 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6718 fprintf_unfiltered (gdb_stdlog
,
6719 "binary downloading supported by target\n");
6720 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6727 /* Write memory data directly to the remote machine.
6728 This does not inform the data cache; the data cache uses this.
6729 HEADER is the starting part of the packet.
6730 MEMADDR is the address in the remote memory space.
6731 MYADDR is the address of the buffer in our space.
6732 LEN is the number of bytes.
6733 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6734 should send data as binary ('X'), or hex-encoded ('M').
6736 The function creates packet of the form
6737 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6739 where encoding of <DATA> is termined by PACKET_FORMAT.
6741 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6744 Returns the number of bytes transferred, or 0 (setting errno) for
6745 error. Only transfer a single packet. */
6748 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6749 const gdb_byte
*myaddr
, ssize_t len
,
6750 char packet_format
, int use_length
)
6752 struct remote_state
*rs
= get_remote_state ();
6762 if (packet_format
!= 'X' && packet_format
!= 'M')
6763 internal_error (__FILE__
, __LINE__
,
6764 _("remote_write_bytes_aux: bad packet format"));
6769 payload_size
= get_memory_write_packet_size ();
6771 /* The packet buffer will be large enough for the payload;
6772 get_memory_packet_size ensures this. */
6775 /* Compute the size of the actual payload by subtracting out the
6776 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6778 payload_size
-= strlen ("$,:#NN");
6780 /* The comma won't be used. */
6782 header_length
= strlen (header
);
6783 payload_size
-= header_length
;
6784 payload_size
-= hexnumlen (memaddr
);
6786 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6788 strcat (rs
->buf
, header
);
6789 p
= rs
->buf
+ strlen (header
);
6791 /* Compute a best guess of the number of bytes actually transfered. */
6792 if (packet_format
== 'X')
6794 /* Best guess at number of bytes that will fit. */
6795 todo
= min (len
, payload_size
);
6797 payload_size
-= hexnumlen (todo
);
6798 todo
= min (todo
, payload_size
);
6802 /* Num bytes that will fit. */
6803 todo
= min (len
, payload_size
/ 2);
6805 payload_size
-= hexnumlen (todo
);
6806 todo
= min (todo
, payload_size
/ 2);
6810 internal_error (__FILE__
, __LINE__
,
6811 _("minimum packet size too small to write data"));
6813 /* If we already need another packet, then try to align the end
6814 of this packet to a useful boundary. */
6815 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6816 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6818 /* Append "<memaddr>". */
6819 memaddr
= remote_address_masked (memaddr
);
6820 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6827 /* Append <len>. Retain the location/size of <len>. It may need to
6828 be adjusted once the packet body has been created. */
6830 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6838 /* Append the packet body. */
6839 if (packet_format
== 'X')
6841 /* Binary mode. Send target system values byte by byte, in
6842 increasing byte addresses. Only escape certain critical
6844 payload_length
= remote_escape_output (myaddr
, todo
, (gdb_byte
*) p
,
6845 &nr_bytes
, payload_size
);
6847 /* If not all TODO bytes fit, then we'll need another packet. Make
6848 a second try to keep the end of the packet aligned. Don't do
6849 this if the packet is tiny. */
6850 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6854 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6856 if (new_nr_bytes
!= nr_bytes
)
6857 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6858 (gdb_byte
*) p
, &nr_bytes
,
6862 p
+= payload_length
;
6863 if (use_length
&& nr_bytes
< todo
)
6865 /* Escape chars have filled up the buffer prematurely,
6866 and we have actually sent fewer bytes than planned.
6867 Fix-up the length field of the packet. Use the same
6868 number of characters as before. */
6869 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6870 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6875 /* Normal mode: Send target system values byte by byte, in
6876 increasing byte addresses. Each byte is encoded as a two hex
6878 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6882 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6883 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6885 if (rs
->buf
[0] == 'E')
6887 /* There is no correspondance between what the remote protocol
6888 uses for errors and errno codes. We would like a cleaner way
6889 of representing errors (big enough to include errno codes,
6890 bfd_error codes, and others). But for now just return EIO. */
6895 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6896 fewer bytes than we'd planned. */
6900 /* Write memory data directly to the remote machine.
6901 This does not inform the data cache; the data cache uses this.
6902 MEMADDR is the address in the remote memory space.
6903 MYADDR is the address of the buffer in our space.
6904 LEN is the number of bytes.
6906 Returns number of bytes transferred, or 0 (setting errno) for
6907 error. Only transfer a single packet. */
6910 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
6912 char *packet_format
= 0;
6914 /* Check whether the target supports binary download. */
6915 check_binary_download (memaddr
);
6917 switch (remote_protocol_packets
[PACKET_X
].support
)
6920 packet_format
= "X";
6922 case PACKET_DISABLE
:
6923 packet_format
= "M";
6925 case PACKET_SUPPORT_UNKNOWN
:
6926 internal_error (__FILE__
, __LINE__
,
6927 _("remote_write_bytes: bad internal state"));
6929 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6932 return remote_write_bytes_aux (packet_format
,
6933 memaddr
, myaddr
, len
, packet_format
[0], 1);
6936 /* Read memory data directly from the remote machine.
6937 This does not use the data cache; the data cache uses this.
6938 MEMADDR is the address in the remote memory space.
6939 MYADDR is the address of the buffer in our space.
6940 LEN is the number of bytes.
6942 Returns number of bytes transferred, or 0 for error. */
6945 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6947 struct remote_state
*rs
= get_remote_state ();
6948 int max_buf_size
; /* Max size of packet output buffer. */
6956 max_buf_size
= get_memory_read_packet_size ();
6957 /* The packet buffer will be large enough for the payload;
6958 get_memory_packet_size ensures this. */
6960 /* Number if bytes that will fit. */
6961 todo
= min (len
, max_buf_size
/ 2);
6963 /* Construct "m"<memaddr>","<len>". */
6964 memaddr
= remote_address_masked (memaddr
);
6967 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6969 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6972 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6973 if (rs
->buf
[0] == 'E'
6974 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6975 && rs
->buf
[3] == '\0')
6977 /* There is no correspondance between what the remote protocol
6978 uses for errors and errno codes. We would like a cleaner way
6979 of representing errors (big enough to include errno codes,
6980 bfd_error codes, and others). But for now just return
6985 /* Reply describes memory byte by byte, each byte encoded as two hex
6988 i
= hex2bin (p
, myaddr
, todo
);
6989 /* Return what we have. Let higher layers handle partial reads. */
6994 /* Read or write LEN bytes from inferior memory at MEMADDR,
6995 transferring to or from debugger address BUFFER. Write to inferior
6996 if SHOULD_WRITE is nonzero. Returns length of data written or
6997 read; 0 for error. TARGET is unused. */
7000 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
7001 int should_write
, struct mem_attrib
*attrib
,
7002 struct target_ops
*target
)
7006 set_remote_traceframe ();
7007 set_general_thread (inferior_ptid
);
7010 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
7012 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
7017 /* Sends a packet with content determined by the printf format string
7018 FORMAT and the remaining arguments, then gets the reply. Returns
7019 whether the packet was a success, a failure, or unknown. */
7021 static enum packet_result
7022 remote_send_printf (const char *format
, ...)
7024 struct remote_state
*rs
= get_remote_state ();
7025 int max_size
= get_remote_packet_size ();
7028 va_start (ap
, format
);
7031 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7032 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7034 if (putpkt (rs
->buf
) < 0)
7035 error (_("Communication problem with target."));
7038 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7040 return packet_check_result (rs
->buf
);
7044 restore_remote_timeout (void *p
)
7046 int value
= *(int *)p
;
7048 remote_timeout
= value
;
7051 /* Flash writing can take quite some time. We'll set
7052 effectively infinite timeout for flash operations.
7053 In future, we'll need to decide on a better approach. */
7054 static const int remote_flash_timeout
= 1000;
7057 remote_flash_erase (struct target_ops
*ops
,
7058 ULONGEST address
, LONGEST length
)
7060 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7061 int saved_remote_timeout
= remote_timeout
;
7062 enum packet_result ret
;
7063 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7064 &saved_remote_timeout
);
7066 remote_timeout
= remote_flash_timeout
;
7068 ret
= remote_send_printf ("vFlashErase:%s,%s",
7069 phex (address
, addr_size
),
7073 case PACKET_UNKNOWN
:
7074 error (_("Remote target does not support flash erase"));
7076 error (_("Error erasing flash with vFlashErase packet"));
7081 do_cleanups (back_to
);
7085 remote_flash_write (struct target_ops
*ops
,
7086 ULONGEST address
, LONGEST length
,
7087 const gdb_byte
*data
)
7089 int saved_remote_timeout
= remote_timeout
;
7091 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7092 &saved_remote_timeout
);
7094 remote_timeout
= remote_flash_timeout
;
7095 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
7096 do_cleanups (back_to
);
7102 remote_flash_done (struct target_ops
*ops
)
7104 int saved_remote_timeout
= remote_timeout
;
7106 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7107 &saved_remote_timeout
);
7109 remote_timeout
= remote_flash_timeout
;
7110 ret
= remote_send_printf ("vFlashDone");
7111 do_cleanups (back_to
);
7115 case PACKET_UNKNOWN
:
7116 error (_("Remote target does not support vFlashDone"));
7118 error (_("Error finishing flash operation"));
7125 remote_files_info (struct target_ops
*ignore
)
7127 puts_filtered ("Debugging a target over a serial line.\n");
7130 /* Stuff for dealing with the packets which are part of this protocol.
7131 See comment at top of file for details. */
7133 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7134 error to higher layers. Called when a serial error is detected.
7135 The exception message is STRING, followed by a colon and a blank,
7136 the system error message for errno at function entry and final dot
7137 for output compatibility with throw_perror_with_name. */
7140 unpush_and_perror (const char *string
)
7142 int saved_errno
= errno
;
7144 remote_unpush_target ();
7145 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7146 safe_strerror (saved_errno
));
7149 /* Read a single character from the remote end. */
7152 readchar (int timeout
)
7155 struct remote_state
*rs
= get_remote_state ();
7157 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7162 switch ((enum serial_rc
) ch
)
7165 remote_unpush_target ();
7166 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7169 unpush_and_perror (_("Remote communication error. "
7170 "Target disconnected."));
7172 case SERIAL_TIMEOUT
:
7178 /* Wrapper for serial_write that closes the target and throws if
7182 remote_serial_write (const char *str
, int len
)
7184 struct remote_state
*rs
= get_remote_state ();
7186 if (serial_write (rs
->remote_desc
, str
, len
))
7188 unpush_and_perror (_("Remote communication error. "
7189 "Target disconnected."));
7193 /* Send the command in *BUF to the remote machine, and read the reply
7194 into *BUF. Report an error if we get an error reply. Resize
7195 *BUF using xrealloc if necessary to hold the result, and update
7199 remote_send (char **buf
,
7203 getpkt (buf
, sizeof_buf
, 0);
7205 if ((*buf
)[0] == 'E')
7206 error (_("Remote failure reply: %s"), *buf
);
7209 /* Return a pointer to an xmalloc'ed string representing an escaped
7210 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7211 etc. The caller is responsible for releasing the returned
7215 escape_buffer (const char *buf
, int n
)
7217 struct cleanup
*old_chain
;
7218 struct ui_file
*stb
;
7221 stb
= mem_fileopen ();
7222 old_chain
= make_cleanup_ui_file_delete (stb
);
7224 fputstrn_unfiltered (buf
, n
, 0, stb
);
7225 str
= ui_file_xstrdup (stb
, NULL
);
7226 do_cleanups (old_chain
);
7230 /* Display a null-terminated packet on stdout, for debugging, using C
7234 print_packet (char *buf
)
7236 puts_filtered ("\"");
7237 fputstr_filtered (buf
, '"', gdb_stdout
);
7238 puts_filtered ("\"");
7244 return putpkt_binary (buf
, strlen (buf
));
7247 /* Send a packet to the remote machine, with error checking. The data
7248 of the packet is in BUF. The string in BUF can be at most
7249 get_remote_packet_size () - 5 to account for the $, # and checksum,
7250 and for a possible /0 if we are debugging (remote_debug) and want
7251 to print the sent packet as a string. */
7254 putpkt_binary (char *buf
, int cnt
)
7256 struct remote_state
*rs
= get_remote_state ();
7258 unsigned char csum
= 0;
7259 char *buf2
= alloca (cnt
+ 6);
7266 /* Catch cases like trying to read memory or listing threads while
7267 we're waiting for a stop reply. The remote server wouldn't be
7268 ready to handle this request, so we'd hang and timeout. We don't
7269 have to worry about this in synchronous mode, because in that
7270 case it's not possible to issue a command while the target is
7271 running. This is not a problem in non-stop mode, because in that
7272 case, the stub is always ready to process serial input. */
7273 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
7274 error (_("Cannot execute this command while the target is running."));
7276 /* We're sending out a new packet. Make sure we don't look at a
7277 stale cached response. */
7278 rs
->cached_wait_status
= 0;
7280 /* Copy the packet into buffer BUF2, encapsulating it
7281 and giving it a checksum. */
7286 for (i
= 0; i
< cnt
; i
++)
7292 *p
++ = tohex ((csum
>> 4) & 0xf);
7293 *p
++ = tohex (csum
& 0xf);
7295 /* Send it over and over until we get a positive ack. */
7299 int started_error_output
= 0;
7303 struct cleanup
*old_chain
;
7307 str
= escape_buffer (buf2
, p
- buf2
);
7308 old_chain
= make_cleanup (xfree
, str
);
7309 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7310 gdb_flush (gdb_stdlog
);
7311 do_cleanups (old_chain
);
7313 remote_serial_write (buf2
, p
- buf2
);
7315 /* If this is a no acks version of the remote protocol, send the
7316 packet and move on. */
7320 /* Read until either a timeout occurs (-2) or '+' is read.
7321 Handle any notification that arrives in the mean time. */
7324 ch
= readchar (remote_timeout
);
7332 case SERIAL_TIMEOUT
:
7335 if (started_error_output
)
7337 putchar_unfiltered ('\n');
7338 started_error_output
= 0;
7347 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7351 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7353 case SERIAL_TIMEOUT
:
7357 break; /* Retransmit buffer. */
7361 fprintf_unfiltered (gdb_stdlog
,
7362 "Packet instead of Ack, ignoring it\n");
7363 /* It's probably an old response sent because an ACK
7364 was lost. Gobble up the packet and ack it so it
7365 doesn't get retransmitted when we resend this
7368 remote_serial_write ("+", 1);
7369 continue; /* Now, go look for +. */
7376 /* If we got a notification, handle it, and go back to looking
7378 /* We've found the start of a notification. Now
7379 collect the data. */
7380 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7385 struct cleanup
*old_chain
;
7388 str
= escape_buffer (rs
->buf
, val
);
7389 old_chain
= make_cleanup (xfree
, str
);
7390 fprintf_unfiltered (gdb_stdlog
,
7391 " Notification received: %s\n",
7393 do_cleanups (old_chain
);
7395 handle_notification (rs
->buf
);
7396 /* We're in sync now, rewait for the ack. */
7403 if (!started_error_output
)
7405 started_error_output
= 1;
7406 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7408 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7409 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7418 if (!started_error_output
)
7420 started_error_output
= 1;
7421 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7423 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7427 break; /* Here to retransmit. */
7431 /* This is wrong. If doing a long backtrace, the user should be
7432 able to get out next time we call QUIT, without anything as
7433 violent as interrupt_query. If we want to provide a way out of
7434 here without getting to the next QUIT, it should be based on
7435 hitting ^C twice as in remote_wait. */
7446 /* Come here after finding the start of a frame when we expected an
7447 ack. Do our best to discard the rest of this packet. */
7456 c
= readchar (remote_timeout
);
7459 case SERIAL_TIMEOUT
:
7460 /* Nothing we can do. */
7463 /* Discard the two bytes of checksum and stop. */
7464 c
= readchar (remote_timeout
);
7466 c
= readchar (remote_timeout
);
7469 case '*': /* Run length encoding. */
7470 /* Discard the repeat count. */
7471 c
= readchar (remote_timeout
);
7476 /* A regular character. */
7482 /* Come here after finding the start of the frame. Collect the rest
7483 into *BUF, verifying the checksum, length, and handling run-length
7484 compression. NUL terminate the buffer. If there is not enough room,
7485 expand *BUF using xrealloc.
7487 Returns -1 on error, number of characters in buffer (ignoring the
7488 trailing NULL) on success. (could be extended to return one of the
7489 SERIAL status indications). */
7492 read_frame (char **buf_p
,
7499 struct remote_state
*rs
= get_remote_state ();
7506 c
= readchar (remote_timeout
);
7509 case SERIAL_TIMEOUT
:
7511 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7515 fputs_filtered ("Saw new packet start in middle of old one\n",
7517 return -1; /* Start a new packet, count retries. */
7520 unsigned char pktcsum
;
7526 check_0
= readchar (remote_timeout
);
7528 check_1
= readchar (remote_timeout
);
7530 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7533 fputs_filtered ("Timeout in checksum, retrying\n",
7537 else if (check_0
< 0 || check_1
< 0)
7540 fputs_filtered ("Communication error in checksum\n",
7545 /* Don't recompute the checksum; with no ack packets we
7546 don't have any way to indicate a packet retransmission
7551 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7552 if (csum
== pktcsum
)
7557 struct cleanup
*old_chain
;
7560 str
= escape_buffer (buf
, bc
);
7561 old_chain
= make_cleanup (xfree
, str
);
7562 fprintf_unfiltered (gdb_stdlog
,
7563 "Bad checksum, sentsum=0x%x, "
7564 "csum=0x%x, buf=%s\n",
7565 pktcsum
, csum
, str
);
7566 do_cleanups (old_chain
);
7568 /* Number of characters in buffer ignoring trailing
7572 case '*': /* Run length encoding. */
7577 c
= readchar (remote_timeout
);
7579 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7581 /* The character before ``*'' is repeated. */
7583 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7585 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7587 /* Make some more room in the buffer. */
7588 *sizeof_buf
+= repeat
;
7589 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7593 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7599 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7603 if (bc
>= *sizeof_buf
- 1)
7605 /* Make some more room in the buffer. */
7607 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7618 /* Read a packet from the remote machine, with error checking, and
7619 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7620 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7621 rather than timing out; this is used (in synchronous mode) to wait
7622 for a target that is is executing user code to stop. */
7623 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7624 don't have to change all the calls to getpkt to deal with the
7625 return value, because at the moment I don't know what the right
7626 thing to do it for those. */
7634 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7638 /* Read a packet from the remote machine, with error checking, and
7639 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7640 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7641 rather than timing out; this is used (in synchronous mode) to wait
7642 for a target that is is executing user code to stop. If FOREVER ==
7643 0, this function is allowed to time out gracefully and return an
7644 indication of this to the caller. Otherwise return the number of
7645 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7646 enough reason to return to the caller. *IS_NOTIF is an output
7647 boolean that indicates whether *BUF holds a notification or not
7648 (a regular packet). */
7651 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7652 int expecting_notif
, int *is_notif
)
7654 struct remote_state
*rs
= get_remote_state ();
7660 /* We're reading a new response. Make sure we don't look at a
7661 previously cached response. */
7662 rs
->cached_wait_status
= 0;
7664 strcpy (*buf
, "timeout");
7667 timeout
= watchdog
> 0 ? watchdog
: -1;
7668 else if (expecting_notif
)
7669 timeout
= 0; /* There should already be a char in the buffer. If
7672 timeout
= remote_timeout
;
7676 /* Process any number of notifications, and then return when
7680 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7682 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7684 /* This can loop forever if the remote side sends us
7685 characters continuously, but if it pauses, we'll get
7686 SERIAL_TIMEOUT from readchar because of timeout. Then
7687 we'll count that as a retry.
7689 Note that even when forever is set, we will only wait
7690 forever prior to the start of a packet. After that, we
7691 expect characters to arrive at a brisk pace. They should
7692 show up within remote_timeout intervals. */
7694 c
= readchar (timeout
);
7695 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7697 if (c
== SERIAL_TIMEOUT
)
7699 if (expecting_notif
)
7700 return -1; /* Don't complain, it's normal to not get
7701 anything in this case. */
7703 if (forever
) /* Watchdog went off? Kill the target. */
7706 remote_unpush_target ();
7707 throw_error (TARGET_CLOSE_ERROR
,
7708 _("Watchdog timeout has expired. "
7709 "Target detached."));
7712 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7716 /* We've found the start of a packet or notification.
7717 Now collect the data. */
7718 val
= read_frame (buf
, sizeof_buf
);
7723 remote_serial_write ("-", 1);
7726 if (tries
> MAX_TRIES
)
7728 /* We have tried hard enough, and just can't receive the
7729 packet/notification. Give up. */
7730 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7732 /* Skip the ack char if we're in no-ack mode. */
7733 if (!rs
->noack_mode
)
7734 remote_serial_write ("+", 1);
7738 /* If we got an ordinary packet, return that to our caller. */
7743 struct cleanup
*old_chain
;
7746 str
= escape_buffer (*buf
, val
);
7747 old_chain
= make_cleanup (xfree
, str
);
7748 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7749 do_cleanups (old_chain
);
7752 /* Skip the ack char if we're in no-ack mode. */
7753 if (!rs
->noack_mode
)
7754 remote_serial_write ("+", 1);
7755 if (is_notif
!= NULL
)
7760 /* If we got a notification, handle it, and go back to looking
7764 gdb_assert (c
== '%');
7768 struct cleanup
*old_chain
;
7771 str
= escape_buffer (*buf
, val
);
7772 old_chain
= make_cleanup (xfree
, str
);
7773 fprintf_unfiltered (gdb_stdlog
,
7774 " Notification received: %s\n",
7776 do_cleanups (old_chain
);
7778 if (is_notif
!= NULL
)
7781 handle_notification (*buf
);
7783 /* Notifications require no acknowledgement. */
7785 if (expecting_notif
)
7792 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7794 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7798 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7801 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7806 /* A helper function that just calls putpkt; for type correctness. */
7809 putpkt_for_catch_errors (void *arg
)
7811 return putpkt (arg
);
7815 remote_kill (struct target_ops
*ops
)
7817 /* Use catch_errors so the user can quit from gdb even when we
7818 aren't on speaking terms with the remote system. */
7819 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7821 /* Don't wait for it to die. I'm not really sure it matters whether
7822 we do or not. For the existing stubs, kill is a noop. */
7823 target_mourn_inferior ();
7827 remote_vkill (int pid
, struct remote_state
*rs
)
7829 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7832 /* Tell the remote target to detach. */
7833 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7835 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7837 if (packet_ok (rs
->buf
,
7838 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7840 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7847 extended_remote_kill (struct target_ops
*ops
)
7850 int pid
= ptid_get_pid (inferior_ptid
);
7851 struct remote_state
*rs
= get_remote_state ();
7853 res
= remote_vkill (pid
, rs
);
7854 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7856 /* Don't try 'k' on a multi-process aware stub -- it has no way
7857 to specify the pid. */
7861 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7862 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7865 /* Don't wait for it to die. I'm not really sure it matters whether
7866 we do or not. For the existing stubs, kill is a noop. */
7872 error (_("Can't kill process"));
7874 target_mourn_inferior ();
7878 remote_mourn (struct target_ops
*ops
)
7880 remote_mourn_1 (ops
);
7883 /* Worker function for remote_mourn. */
7885 remote_mourn_1 (struct target_ops
*target
)
7887 unpush_target (target
);
7889 /* remote_close takes care of doing most of the clean up. */
7890 generic_mourn_inferior ();
7894 extended_remote_mourn_1 (struct target_ops
*target
)
7896 struct remote_state
*rs
= get_remote_state ();
7898 /* In case we got here due to an error, but we're going to stay
7900 rs
->waiting_for_stop_reply
= 0;
7902 /* If the current general thread belonged to the process we just
7903 detached from or has exited, the remote side current general
7904 thread becomes undefined. Considering a case like this:
7906 - We just got here due to a detach.
7907 - The process that we're detaching from happens to immediately
7908 report a global breakpoint being hit in non-stop mode, in the
7909 same thread we had selected before.
7910 - GDB attaches to this process again.
7911 - This event happens to be the next event we handle.
7913 GDB would consider that the current general thread didn't need to
7914 be set on the stub side (with Hg), since for all it knew,
7915 GENERAL_THREAD hadn't changed.
7917 Notice that although in all-stop mode, the remote server always
7918 sets the current thread to the thread reporting the stop event,
7919 that doesn't happen in non-stop mode; in non-stop, the stub *must
7920 not* change the current thread when reporting a breakpoint hit,
7921 due to the decoupling of event reporting and event handling.
7923 To keep things simple, we always invalidate our notion of the
7925 record_currthread (rs
, minus_one_ptid
);
7927 /* Unlike "target remote", we do not want to unpush the target; then
7928 the next time the user says "run", we won't be connected. */
7930 /* Call common code to mark the inferior as not running. */
7931 generic_mourn_inferior ();
7933 if (!have_inferiors ())
7935 if (!remote_multi_process_p (rs
))
7937 /* Check whether the target is running now - some remote stubs
7938 automatically restart after kill. */
7940 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7942 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7944 /* Assume that the target has been restarted. Set
7945 inferior_ptid so that bits of core GDB realizes
7946 there's something here, e.g., so that the user can
7947 say "kill" again. */
7948 inferior_ptid
= magic_null_ptid
;
7955 extended_remote_mourn (struct target_ops
*ops
)
7957 extended_remote_mourn_1 (ops
);
7961 extended_remote_supports_disable_randomization (void)
7963 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7968 extended_remote_disable_randomization (int val
)
7970 struct remote_state
*rs
= get_remote_state ();
7973 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
7976 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7978 error (_("Target does not support QDisableRandomization."));
7979 if (strcmp (reply
, "OK") != 0)
7980 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7984 extended_remote_run (char *args
)
7986 struct remote_state
*rs
= get_remote_state ();
7989 /* If the user has disabled vRun support, or we have detected that
7990 support is not available, do not try it. */
7991 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7994 strcpy (rs
->buf
, "vRun;");
7995 len
= strlen (rs
->buf
);
7997 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7998 error (_("Remote file name too long for run packet"));
7999 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
8001 gdb_assert (args
!= NULL
);
8004 struct cleanup
*back_to
;
8008 argv
= gdb_buildargv (args
);
8009 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
8010 for (i
= 0; argv
[i
] != NULL
; i
++)
8012 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8013 error (_("Argument list too long for run packet"));
8014 rs
->buf
[len
++] = ';';
8015 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
8017 do_cleanups (back_to
);
8020 rs
->buf
[len
++] = '\0';
8023 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8025 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
8027 /* We have a wait response. All is well. */
8030 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
8031 /* It wasn't disabled before, but it is now. */
8035 if (remote_exec_file
[0] == '\0')
8036 error (_("Running the default executable on the remote target failed; "
8037 "try \"set remote exec-file\"?"));
8039 error (_("Running \"%s\" on the remote target failed"),
8044 /* In the extended protocol we want to be able to do things like
8045 "run" and have them basically work as expected. So we need
8046 a special create_inferior function. We support changing the
8047 executable file and the command line arguments, but not the
8051 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
8052 char **env
, int from_tty
)
8056 struct remote_state
*rs
= get_remote_state ();
8058 /* If running asynchronously, register the target file descriptor
8059 with the event loop. */
8060 if (target_can_async_p ())
8061 target_async (inferior_event_handler
, 0);
8063 /* Disable address space randomization if requested (and supported). */
8064 if (extended_remote_supports_disable_randomization ())
8065 extended_remote_disable_randomization (disable_randomization
);
8067 /* Now restart the remote server. */
8068 run_worked
= extended_remote_run (args
) != -1;
8071 /* vRun was not supported. Fail if we need it to do what the
8073 if (remote_exec_file
[0])
8074 error (_("Remote target does not support \"set remote exec-file\""));
8076 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8078 /* Fall back to "R". */
8079 extended_remote_restart ();
8082 if (!have_inferiors ())
8084 /* Clean up from the last time we ran, before we mark the target
8085 running again. This will mark breakpoints uninserted, and
8086 get_offsets may insert breakpoints. */
8087 init_thread_list ();
8088 init_wait_for_inferior ();
8091 /* vRun's success return is a stop reply. */
8092 stop_reply
= run_worked
? rs
->buf
: NULL
;
8093 add_current_inferior_and_thread (stop_reply
);
8095 /* Get updated offsets, if the stub uses qOffsets. */
8100 extended_remote_create_inferior (struct target_ops
*ops
,
8101 char *exec_file
, char *args
,
8102 char **env
, int from_tty
)
8104 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
8108 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8109 the list of conditions (in agent expression bytecode format), if any, the
8110 target needs to evaluate. The output is placed into the packet buffer
8111 started from BUF and ended at BUF_END. */
8114 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8115 struct bp_target_info
*bp_tgt
, char *buf
,
8118 struct agent_expr
*aexpr
= NULL
;
8121 char *buf_start
= buf
;
8123 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8126 buf
+= strlen (buf
);
8127 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8130 /* Send conditions to the target and free the vector. */
8132 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8135 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8136 buf
+= strlen (buf
);
8137 for (i
= 0; i
< aexpr
->len
; ++i
)
8138 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8142 VEC_free (agent_expr_p
, bp_tgt
->conditions
);
8147 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8148 struct bp_target_info
*bp_tgt
, char *buf
)
8150 struct agent_expr
*aexpr
= NULL
;
8153 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8156 buf
+= strlen (buf
);
8158 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8159 buf
+= strlen (buf
);
8161 /* Concatenate all the agent expressions that are commands into the
8164 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8167 sprintf (buf
, "X%x,", aexpr
->len
);
8168 buf
+= strlen (buf
);
8169 for (i
= 0; i
< aexpr
->len
; ++i
)
8170 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8174 VEC_free (agent_expr_p
, bp_tgt
->tcommands
);
8177 /* Insert a breakpoint. On targets that have software breakpoint
8178 support, we ask the remote target to do the work; on targets
8179 which don't, we insert a traditional memory breakpoint. */
8182 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
8183 struct bp_target_info
*bp_tgt
)
8185 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8186 If it succeeds, then set the support to PACKET_ENABLE. If it
8187 fails, and the user has explicitly requested the Z support then
8188 report an error, otherwise, mark it disabled and go on. */
8190 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8192 CORE_ADDR addr
= bp_tgt
->placed_address
;
8193 struct remote_state
*rs
;
8196 struct condition_list
*cond
= NULL
;
8198 /* Make sure the remote is pointing at the right process, if
8200 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8201 set_general_process ();
8203 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8205 rs
= get_remote_state ();
8207 endbuf
= rs
->buf
+ get_remote_packet_size ();
8212 addr
= (ULONGEST
) remote_address_masked (addr
);
8213 p
+= hexnumstr (p
, addr
);
8214 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8216 if (remote_supports_cond_breakpoints ())
8217 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8219 if (remote_can_run_breakpoint_commands ())
8220 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8223 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8225 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8230 bp_tgt
->placed_address
= addr
;
8231 bp_tgt
->placed_size
= bpsize
;
8233 case PACKET_UNKNOWN
:
8238 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
8242 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
8243 struct bp_target_info
*bp_tgt
)
8245 CORE_ADDR addr
= bp_tgt
->placed_address
;
8246 struct remote_state
*rs
= get_remote_state ();
8248 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8251 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8253 /* Make sure the remote is pointing at the right process, if
8255 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8256 set_general_process ();
8262 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8263 p
+= hexnumstr (p
, addr
);
8264 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8267 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8269 return (rs
->buf
[0] == 'E');
8272 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
8276 watchpoint_to_Z_packet (int type
)
8281 return Z_PACKET_WRITE_WP
;
8284 return Z_PACKET_READ_WP
;
8287 return Z_PACKET_ACCESS_WP
;
8290 internal_error (__FILE__
, __LINE__
,
8291 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8296 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
8297 struct expression
*cond
)
8299 struct remote_state
*rs
= get_remote_state ();
8300 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8302 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8304 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8307 /* Make sure the remote is pointing at the right process, if
8309 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8310 set_general_process ();
8312 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8313 p
= strchr (rs
->buf
, '\0');
8314 addr
= remote_address_masked (addr
);
8315 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8316 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8319 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8321 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8325 case PACKET_UNKNOWN
:
8330 internal_error (__FILE__
, __LINE__
,
8331 _("remote_insert_watchpoint: reached end of function"));
8335 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8336 CORE_ADDR start
, int length
)
8338 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8340 return diff
< length
;
8345 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
8346 struct expression
*cond
)
8348 struct remote_state
*rs
= get_remote_state ();
8349 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8351 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8353 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8356 /* Make sure the remote is pointing at the right process, if
8358 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8359 set_general_process ();
8361 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8362 p
= strchr (rs
->buf
, '\0');
8363 addr
= remote_address_masked (addr
);
8364 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8365 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8367 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8369 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8372 case PACKET_UNKNOWN
:
8377 internal_error (__FILE__
, __LINE__
,
8378 _("remote_remove_watchpoint: reached end of function"));
8382 int remote_hw_watchpoint_limit
= -1;
8383 int remote_hw_watchpoint_length_limit
= -1;
8384 int remote_hw_breakpoint_limit
= -1;
8387 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
8389 if (remote_hw_watchpoint_length_limit
== 0)
8391 else if (remote_hw_watchpoint_length_limit
< 0)
8393 else if (len
<= remote_hw_watchpoint_length_limit
)
8400 remote_check_watch_resources (int type
, int cnt
, int ot
)
8402 if (type
== bp_hardware_breakpoint
)
8404 if (remote_hw_breakpoint_limit
== 0)
8406 else if (remote_hw_breakpoint_limit
< 0)
8408 else if (cnt
<= remote_hw_breakpoint_limit
)
8413 if (remote_hw_watchpoint_limit
== 0)
8415 else if (remote_hw_watchpoint_limit
< 0)
8419 else if (cnt
<= remote_hw_watchpoint_limit
)
8426 remote_stopped_by_watchpoint (void)
8428 return remote_stopped_by_watchpoint_p
;
8432 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8436 if (remote_stopped_by_watchpoint ())
8438 *addr_p
= remote_watch_data_address
;
8447 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
8448 struct bp_target_info
*bp_tgt
)
8451 struct remote_state
*rs
;
8455 /* The length field should be set to the size of a breakpoint
8456 instruction, even though we aren't inserting one ourselves. */
8458 gdbarch_remote_breakpoint_from_pc
8459 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
8461 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8464 /* Make sure the remote is pointing at the right process, if
8466 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8467 set_general_process ();
8469 rs
= get_remote_state ();
8471 endbuf
= rs
->buf
+ get_remote_packet_size ();
8477 addr
= remote_address_masked (bp_tgt
->placed_address
);
8478 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8479 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8481 if (remote_supports_cond_breakpoints ())
8482 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8484 if (remote_can_run_breakpoint_commands ())
8485 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8488 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8490 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8493 if (rs
->buf
[1] == '.')
8495 message
= strchr (rs
->buf
+ 2, '.');
8497 error (_("Remote failure reply: %s"), message
+ 1);
8500 case PACKET_UNKNOWN
:
8505 internal_error (__FILE__
, __LINE__
,
8506 _("remote_insert_hw_breakpoint: reached end of function"));
8511 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
8512 struct bp_target_info
*bp_tgt
)
8515 struct remote_state
*rs
= get_remote_state ();
8517 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8519 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8522 /* Make sure the remote is pointing at the right process, if
8524 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8525 set_general_process ();
8531 addr
= remote_address_masked (bp_tgt
->placed_address
);
8532 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8533 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8536 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8538 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8541 case PACKET_UNKNOWN
:
8546 internal_error (__FILE__
, __LINE__
,
8547 _("remote_remove_hw_breakpoint: reached end of function"));
8550 /* Verify memory using the "qCRC:" request. */
8553 remote_verify_memory (struct target_ops
*ops
,
8554 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8556 struct remote_state
*rs
= get_remote_state ();
8557 unsigned long host_crc
, target_crc
;
8560 /* Make sure the remote is pointing at the right process. */
8561 set_general_process ();
8563 /* FIXME: assumes lma can fit into long. */
8564 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8565 (long) lma
, (long) size
);
8568 /* Be clever; compute the host_crc before waiting for target
8570 host_crc
= xcrc32 (data
, size
, 0xffffffff);
8572 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8573 if (rs
->buf
[0] == 'E')
8576 if (rs
->buf
[0] != 'C')
8577 error (_("remote target does not support this operation"));
8579 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8580 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8582 return (host_crc
== target_crc
);
8585 /* compare-sections command
8587 With no arguments, compares each loadable section in the exec bfd
8588 with the same memory range on the target, and reports mismatches.
8589 Useful for verifying the image on the target against the exec file. */
8592 compare_sections_command (char *args
, int from_tty
)
8595 struct cleanup
*old_chain
;
8597 const char *sectname
;
8605 error (_("command cannot be used without an exec file"));
8607 /* Make sure the remote is pointing at the right process. */
8608 set_general_process ();
8610 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8612 if (!(s
->flags
& SEC_LOAD
))
8613 continue; /* Skip non-loadable section. */
8615 size
= bfd_get_section_size (s
);
8617 continue; /* Skip zero-length section. */
8619 sectname
= bfd_get_section_name (exec_bfd
, s
);
8620 if (args
&& strcmp (args
, sectname
) != 0)
8621 continue; /* Not the section selected by user. */
8623 matched
= 1; /* Do this section. */
8626 sectdata
= xmalloc (size
);
8627 old_chain
= make_cleanup (xfree
, sectdata
);
8628 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8630 res
= target_verify_memory (sectdata
, lma
, size
);
8633 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8634 paddress (target_gdbarch (), lma
),
8635 paddress (target_gdbarch (), lma
+ size
));
8637 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8638 paddress (target_gdbarch (), lma
),
8639 paddress (target_gdbarch (), lma
+ size
));
8641 printf_filtered ("matched.\n");
8644 printf_filtered ("MIS-MATCHED!\n");
8648 do_cleanups (old_chain
);
8651 warning (_("One or more sections of the remote executable does not match\n\
8652 the loaded file\n"));
8653 if (args
&& !matched
)
8654 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8657 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8658 into remote target. The number of bytes written to the remote
8659 target is returned, or -1 for error. */
8662 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8663 const char *annex
, const gdb_byte
*writebuf
,
8664 ULONGEST offset
, LONGEST len
,
8665 struct packet_config
*packet
)
8669 struct remote_state
*rs
= get_remote_state ();
8670 int max_size
= get_memory_write_packet_size ();
8672 if (packet
->support
== PACKET_DISABLE
)
8675 /* Insert header. */
8676 i
= snprintf (rs
->buf
, max_size
,
8677 "qXfer:%s:write:%s:%s:",
8678 object_name
, annex
? annex
: "",
8679 phex_nz (offset
, sizeof offset
));
8680 max_size
-= (i
+ 1);
8682 /* Escape as much data as fits into rs->buf. */
8683 buf_len
= remote_escape_output
8684 (writebuf
, len
, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
8686 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8687 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8688 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8691 unpack_varlen_hex (rs
->buf
, &n
);
8695 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8696 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8697 number of bytes read is returned, or 0 for EOF, or -1 for error.
8698 The number of bytes read may be less than LEN without indicating an
8699 EOF. PACKET is checked and updated to indicate whether the remote
8700 target supports this object. */
8703 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8705 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8706 struct packet_config
*packet
)
8708 struct remote_state
*rs
= get_remote_state ();
8709 LONGEST i
, n
, packet_len
;
8711 if (packet
->support
== PACKET_DISABLE
)
8714 /* Check whether we've cached an end-of-object packet that matches
8716 if (rs
->finished_object
)
8718 if (strcmp (object_name
, rs
->finished_object
) == 0
8719 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
8720 && offset
== rs
->finished_offset
)
8723 /* Otherwise, we're now reading something different. Discard
8725 xfree (rs
->finished_object
);
8726 xfree (rs
->finished_annex
);
8727 rs
->finished_object
= NULL
;
8728 rs
->finished_annex
= NULL
;
8731 /* Request only enough to fit in a single packet. The actual data
8732 may not, since we don't know how much of it will need to be escaped;
8733 the target is free to respond with slightly less data. We subtract
8734 five to account for the response type and the protocol frame. */
8735 n
= min (get_remote_packet_size () - 5, len
);
8736 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8737 object_name
, annex
? annex
: "",
8738 phex_nz (offset
, sizeof offset
),
8739 phex_nz (n
, sizeof n
));
8740 i
= putpkt (rs
->buf
);
8745 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8746 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8749 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8750 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8752 /* 'm' means there is (or at least might be) more data after this
8753 batch. That does not make sense unless there's at least one byte
8754 of data in this reply. */
8755 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8756 error (_("Remote qXfer reply contained no data."));
8758 /* Got some data. */
8759 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
8760 packet_len
- 1, readbuf
, n
);
8762 /* 'l' is an EOF marker, possibly including a final block of data,
8763 or possibly empty. If we have the final block of a non-empty
8764 object, record this fact to bypass a subsequent partial read. */
8765 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8767 rs
->finished_object
= xstrdup (object_name
);
8768 rs
->finished_annex
= xstrdup (annex
? annex
: "");
8769 rs
->finished_offset
= offset
+ i
;
8776 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8777 const char *annex
, gdb_byte
*readbuf
,
8778 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8780 struct remote_state
*rs
;
8785 set_remote_traceframe ();
8786 set_general_thread (inferior_ptid
);
8788 rs
= get_remote_state ();
8790 /* Handle memory using the standard memory routines. */
8791 if (object
== TARGET_OBJECT_MEMORY
)
8797 /* If the remote target is connected but not running, we should
8798 pass this request down to a lower stratum (e.g. the executable
8800 if (!target_has_execution
)
8803 if (writebuf
!= NULL
)
8804 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8806 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8810 else if (xfered
== 0 && errno
== 0)
8816 /* Handle SPU memory using qxfer packets. */
8817 if (object
== TARGET_OBJECT_SPU
)
8820 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8821 &remote_protocol_packets
8822 [PACKET_qXfer_spu_read
]);
8824 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8825 &remote_protocol_packets
8826 [PACKET_qXfer_spu_write
]);
8829 /* Handle extra signal info using qxfer packets. */
8830 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8833 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8834 &remote_protocol_packets
8835 [PACKET_qXfer_siginfo_read
]);
8837 return remote_write_qxfer (ops
, "siginfo", annex
,
8838 writebuf
, offset
, len
,
8839 &remote_protocol_packets
8840 [PACKET_qXfer_siginfo_write
]);
8843 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8846 return remote_read_qxfer (ops
, "statictrace", annex
,
8847 readbuf
, offset
, len
,
8848 &remote_protocol_packets
8849 [PACKET_qXfer_statictrace_read
]);
8854 /* Only handle flash writes. */
8855 if (writebuf
!= NULL
)
8861 case TARGET_OBJECT_FLASH
:
8862 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8866 else if (xfered
== 0 && errno
== 0)
8876 /* Map pre-existing objects onto letters. DO NOT do this for new
8877 objects!!! Instead specify new query packets. */
8880 case TARGET_OBJECT_AVR
:
8884 case TARGET_OBJECT_AUXV
:
8885 gdb_assert (annex
== NULL
);
8886 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8887 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8889 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8890 return remote_read_qxfer
8891 (ops
, "features", annex
, readbuf
, offset
, len
,
8892 &remote_protocol_packets
[PACKET_qXfer_features
]);
8894 case TARGET_OBJECT_LIBRARIES
:
8895 return remote_read_qxfer
8896 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8897 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8899 case TARGET_OBJECT_LIBRARIES_SVR4
:
8900 return remote_read_qxfer
8901 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8902 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8904 case TARGET_OBJECT_MEMORY_MAP
:
8905 gdb_assert (annex
== NULL
);
8906 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8907 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8909 case TARGET_OBJECT_OSDATA
:
8910 /* Should only get here if we're connected. */
8911 gdb_assert (rs
->remote_desc
);
8912 return remote_read_qxfer
8913 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8914 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8916 case TARGET_OBJECT_THREADS
:
8917 gdb_assert (annex
== NULL
);
8918 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8919 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8921 case TARGET_OBJECT_TRACEFRAME_INFO
:
8922 gdb_assert (annex
== NULL
);
8923 return remote_read_qxfer
8924 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8925 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8927 case TARGET_OBJECT_FDPIC
:
8928 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8929 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8931 case TARGET_OBJECT_OPENVMS_UIB
:
8932 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
8933 &remote_protocol_packets
[PACKET_qXfer_uib
]);
8935 case TARGET_OBJECT_BTRACE
:
8936 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
8937 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
8943 /* Note: a zero OFFSET and LEN can be used to query the minimum
8945 if (offset
== 0 && len
== 0)
8946 return (get_remote_packet_size ());
8947 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8948 large enough let the caller deal with it. */
8949 if (len
< get_remote_packet_size ())
8951 len
= get_remote_packet_size ();
8953 /* Except for querying the minimum buffer size, target must be open. */
8954 if (!rs
->remote_desc
)
8955 error (_("remote query is only available after target open"));
8957 gdb_assert (annex
!= NULL
);
8958 gdb_assert (readbuf
!= NULL
);
8964 /* We used one buffer char for the remote protocol q command and
8965 another for the query type. As the remote protocol encapsulation
8966 uses 4 chars plus one extra in case we are debugging
8967 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8970 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8972 /* Bad caller may have sent forbidden characters. */
8973 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8978 gdb_assert (annex
[i
] == '\0');
8980 i
= putpkt (rs
->buf
);
8984 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8985 strcpy ((char *) readbuf
, rs
->buf
);
8987 return strlen ((char *) readbuf
);
8991 remote_search_memory (struct target_ops
* ops
,
8992 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8993 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8994 CORE_ADDR
*found_addrp
)
8996 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8997 struct remote_state
*rs
= get_remote_state ();
8998 int max_size
= get_memory_write_packet_size ();
8999 struct packet_config
*packet
=
9000 &remote_protocol_packets
[PACKET_qSearch_memory
];
9001 /* Number of packet bytes used to encode the pattern;
9002 this could be more than PATTERN_LEN due to escape characters. */
9003 int escaped_pattern_len
;
9004 /* Amount of pattern that was encodable in the packet. */
9005 int used_pattern_len
;
9008 ULONGEST found_addr
;
9010 /* Don't go to the target if we don't have to.
9011 This is done before checking packet->support to avoid the possibility that
9012 a success for this edge case means the facility works in general. */
9013 if (pattern_len
> search_space_len
)
9015 if (pattern_len
== 0)
9017 *found_addrp
= start_addr
;
9021 /* If we already know the packet isn't supported, fall back to the simple
9022 way of searching memory. */
9024 if (packet
->support
== PACKET_DISABLE
)
9026 /* Target doesn't provided special support, fall back and use the
9027 standard support (copy memory and do the search here). */
9028 return simple_search_memory (ops
, start_addr
, search_space_len
,
9029 pattern
, pattern_len
, found_addrp
);
9032 /* Make sure the remote is pointing at the right process. */
9033 set_general_process ();
9035 /* Insert header. */
9036 i
= snprintf (rs
->buf
, max_size
,
9037 "qSearch:memory:%s;%s;",
9038 phex_nz (start_addr
, addr_size
),
9039 phex_nz (search_space_len
, sizeof (search_space_len
)));
9040 max_size
-= (i
+ 1);
9042 /* Escape as much data as fits into rs->buf. */
9043 escaped_pattern_len
=
9044 remote_escape_output (pattern
, pattern_len
, (gdb_byte
*) rs
->buf
+ i
,
9045 &used_pattern_len
, max_size
);
9047 /* Bail if the pattern is too large. */
9048 if (used_pattern_len
!= pattern_len
)
9049 error (_("Pattern is too large to transmit to remote target."));
9051 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9052 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9053 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9055 /* The request may not have worked because the command is not
9056 supported. If so, fall back to the simple way. */
9057 if (packet
->support
== PACKET_DISABLE
)
9059 return simple_search_memory (ops
, start_addr
, search_space_len
,
9060 pattern
, pattern_len
, found_addrp
);
9065 if (rs
->buf
[0] == '0')
9067 else if (rs
->buf
[0] == '1')
9070 if (rs
->buf
[1] != ',')
9071 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9072 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9073 *found_addrp
= found_addr
;
9076 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9082 remote_rcmd (char *command
,
9083 struct ui_file
*outbuf
)
9085 struct remote_state
*rs
= get_remote_state ();
9088 if (!rs
->remote_desc
)
9089 error (_("remote rcmd is only available after target open"));
9091 /* Send a NULL command across as an empty command. */
9092 if (command
== NULL
)
9095 /* The query prefix. */
9096 strcpy (rs
->buf
, "qRcmd,");
9097 p
= strchr (rs
->buf
, '\0');
9099 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9100 > get_remote_packet_size ())
9101 error (_("\"monitor\" command ``%s'' is too long."), command
);
9103 /* Encode the actual command. */
9104 bin2hex ((gdb_byte
*) command
, p
, 0);
9106 if (putpkt (rs
->buf
) < 0)
9107 error (_("Communication problem with target."));
9109 /* get/display the response */
9114 /* XXX - see also remote_get_noisy_reply(). */
9115 QUIT
; /* Allow user to bail out with ^C. */
9117 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9119 /* Timeout. Continue to (try to) read responses.
9120 This is better than stopping with an error, assuming the stub
9121 is still executing the (long) monitor command.
9122 If needed, the user can interrupt gdb using C-c, obtaining
9123 an effect similar to stop on timeout. */
9128 error (_("Target does not support this command."));
9129 if (buf
[0] == 'O' && buf
[1] != 'K')
9131 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9134 if (strcmp (buf
, "OK") == 0)
9136 if (strlen (buf
) == 3 && buf
[0] == 'E'
9137 && isdigit (buf
[1]) && isdigit (buf
[2]))
9139 error (_("Protocol error with Rcmd"));
9141 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9143 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9145 fputc_unfiltered (c
, outbuf
);
9151 static VEC(mem_region_s
) *
9152 remote_memory_map (struct target_ops
*ops
)
9154 VEC(mem_region_s
) *result
= NULL
;
9155 char *text
= target_read_stralloc (¤t_target
,
9156 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9160 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9162 result
= parse_memory_map (text
);
9163 do_cleanups (back_to
);
9170 packet_command (char *args
, int from_tty
)
9172 struct remote_state
*rs
= get_remote_state ();
9174 if (!rs
->remote_desc
)
9175 error (_("command can only be used with remote target"));
9178 error (_("remote-packet command requires packet text as argument"));
9180 puts_filtered ("sending: ");
9181 print_packet (args
);
9182 puts_filtered ("\n");
9185 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9186 puts_filtered ("received: ");
9187 print_packet (rs
->buf
);
9188 puts_filtered ("\n");
9192 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9194 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9196 static void threadset_test_cmd (char *cmd
, int tty
);
9198 static void threadalive_test (char *cmd
, int tty
);
9200 static void threadlist_test_cmd (char *cmd
, int tty
);
9202 int get_and_display_threadinfo (threadref
*ref
);
9204 static void threadinfo_test_cmd (char *cmd
, int tty
);
9206 static int thread_display_step (threadref
*ref
, void *context
);
9208 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9210 static void init_remote_threadtests (void);
9212 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9215 threadset_test_cmd (char *cmd
, int tty
)
9217 int sample_thread
= SAMPLE_THREAD
;
9219 printf_filtered (_("Remote threadset test\n"));
9220 set_general_thread (sample_thread
);
9225 threadalive_test (char *cmd
, int tty
)
9227 int sample_thread
= SAMPLE_THREAD
;
9228 int pid
= ptid_get_pid (inferior_ptid
);
9229 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
9231 if (remote_thread_alive (ptid
))
9232 printf_filtered ("PASS: Thread alive test\n");
9234 printf_filtered ("FAIL: Thread alive test\n");
9237 void output_threadid (char *title
, threadref
*ref
);
9240 output_threadid (char *title
, threadref
*ref
)
9244 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9246 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9250 threadlist_test_cmd (char *cmd
, int tty
)
9253 threadref nextthread
;
9254 int done
, result_count
;
9255 threadref threadlist
[3];
9257 printf_filtered ("Remote Threadlist test\n");
9258 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9259 &result_count
, &threadlist
[0]))
9260 printf_filtered ("FAIL: threadlist test\n");
9263 threadref
*scan
= threadlist
;
9264 threadref
*limit
= scan
+ result_count
;
9266 while (scan
< limit
)
9267 output_threadid (" thread ", scan
++);
9272 display_thread_info (struct gdb_ext_thread_info
*info
)
9274 output_threadid ("Threadid: ", &info
->threadid
);
9275 printf_filtered ("Name: %s\n ", info
->shortname
);
9276 printf_filtered ("State: %s\n", info
->display
);
9277 printf_filtered ("other: %s\n\n", info
->more_display
);
9281 get_and_display_threadinfo (threadref
*ref
)
9285 struct gdb_ext_thread_info threadinfo
;
9287 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9288 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9289 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9290 display_thread_info (&threadinfo
);
9295 threadinfo_test_cmd (char *cmd
, int tty
)
9297 int athread
= SAMPLE_THREAD
;
9301 int_to_threadref (&thread
, athread
);
9302 printf_filtered ("Remote Threadinfo test\n");
9303 if (!get_and_display_threadinfo (&thread
))
9304 printf_filtered ("FAIL cannot get thread info\n");
9308 thread_display_step (threadref
*ref
, void *context
)
9310 /* output_threadid(" threadstep ",ref); *//* simple test */
9311 return get_and_display_threadinfo (ref
);
9315 threadlist_update_test_cmd (char *cmd
, int tty
)
9317 printf_filtered ("Remote Threadlist update test\n");
9318 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9322 init_remote_threadtests (void)
9324 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9325 _("Fetch and print the remote list of "
9326 "thread identifiers, one pkt only"));
9327 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9328 _("Fetch and display info about one thread"));
9329 add_com ("tset", class_obscure
, threadset_test_cmd
,
9330 _("Test setting to a different thread"));
9331 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9332 _("Iterate through updating all remote thread info"));
9333 add_com ("talive", class_obscure
, threadalive_test
,
9334 _(" Remote thread alive test "));
9339 /* Convert a thread ID to a string. Returns the string in a static
9343 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9345 static char buf
[64];
9346 struct remote_state
*rs
= get_remote_state ();
9348 if (ptid_equal (ptid
, null_ptid
))
9349 return normal_pid_to_str (ptid
);
9350 else if (ptid_is_pid (ptid
))
9352 /* Printing an inferior target id. */
9354 /* When multi-process extensions are off, there's no way in the
9355 remote protocol to know the remote process id, if there's any
9356 at all. There's one exception --- when we're connected with
9357 target extended-remote, and we manually attached to a process
9358 with "attach PID". We don't record anywhere a flag that
9359 allows us to distinguish that case from the case of
9360 connecting with extended-remote and the stub already being
9361 attached to a process, and reporting yes to qAttached, hence
9362 no smart special casing here. */
9363 if (!remote_multi_process_p (rs
))
9365 xsnprintf (buf
, sizeof buf
, "Remote target");
9369 return normal_pid_to_str (ptid
);
9373 if (ptid_equal (magic_null_ptid
, ptid
))
9374 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9375 else if (rs
->extended
&& remote_multi_process_p (rs
))
9376 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9377 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
9379 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9380 ptid_get_tid (ptid
));
9385 /* Get the address of the thread local variable in OBJFILE which is
9386 stored at OFFSET within the thread local storage for thread PTID. */
9389 remote_get_thread_local_address (struct target_ops
*ops
,
9390 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9392 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
9394 struct remote_state
*rs
= get_remote_state ();
9396 char *endp
= rs
->buf
+ get_remote_packet_size ();
9397 enum packet_result result
;
9399 strcpy (p
, "qGetTLSAddr:");
9401 p
= write_ptid (p
, endp
, ptid
);
9403 p
+= hexnumstr (p
, offset
);
9405 p
+= hexnumstr (p
, lm
);
9409 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9410 result
= packet_ok (rs
->buf
,
9411 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9412 if (result
== PACKET_OK
)
9416 unpack_varlen_hex (rs
->buf
, &result
);
9419 else if (result
== PACKET_UNKNOWN
)
9420 throw_error (TLS_GENERIC_ERROR
,
9421 _("Remote target doesn't support qGetTLSAddr packet"));
9423 throw_error (TLS_GENERIC_ERROR
,
9424 _("Remote target failed to process qGetTLSAddr request"));
9427 throw_error (TLS_GENERIC_ERROR
,
9428 _("TLS not supported or disabled on this target"));
9433 /* Provide thread local base, i.e. Thread Information Block address.
9434 Returns 1 if ptid is found and thread_local_base is non zero. */
9437 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
9439 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
9441 struct remote_state
*rs
= get_remote_state ();
9443 char *endp
= rs
->buf
+ get_remote_packet_size ();
9444 enum packet_result result
;
9446 strcpy (p
, "qGetTIBAddr:");
9448 p
= write_ptid (p
, endp
, ptid
);
9452 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9453 result
= packet_ok (rs
->buf
,
9454 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9455 if (result
== PACKET_OK
)
9459 unpack_varlen_hex (rs
->buf
, &result
);
9461 *addr
= (CORE_ADDR
) result
;
9464 else if (result
== PACKET_UNKNOWN
)
9465 error (_("Remote target doesn't support qGetTIBAddr packet"));
9467 error (_("Remote target failed to process qGetTIBAddr request"));
9470 error (_("qGetTIBAddr not supported or disabled on this target"));
9475 /* Support for inferring a target description based on the current
9476 architecture and the size of a 'g' packet. While the 'g' packet
9477 can have any size (since optional registers can be left off the
9478 end), some sizes are easily recognizable given knowledge of the
9479 approximate architecture. */
9481 struct remote_g_packet_guess
9484 const struct target_desc
*tdesc
;
9486 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9487 DEF_VEC_O(remote_g_packet_guess_s
);
9489 struct remote_g_packet_data
9491 VEC(remote_g_packet_guess_s
) *guesses
;
9494 static struct gdbarch_data
*remote_g_packet_data_handle
;
9497 remote_g_packet_data_init (struct obstack
*obstack
)
9499 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9503 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9504 const struct target_desc
*tdesc
)
9506 struct remote_g_packet_data
*data
9507 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9508 struct remote_g_packet_guess new_guess
, *guess
;
9511 gdb_assert (tdesc
!= NULL
);
9514 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9516 if (guess
->bytes
== bytes
)
9517 internal_error (__FILE__
, __LINE__
,
9518 _("Duplicate g packet description added for size %d"),
9521 new_guess
.bytes
= bytes
;
9522 new_guess
.tdesc
= tdesc
;
9523 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9526 /* Return 1 if remote_read_description would do anything on this target
9527 and architecture, 0 otherwise. */
9530 remote_read_description_p (struct target_ops
*target
)
9532 struct remote_g_packet_data
*data
9533 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9535 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9541 static const struct target_desc
*
9542 remote_read_description (struct target_ops
*target
)
9544 struct remote_g_packet_data
*data
9545 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9547 /* Do not try this during initial connection, when we do not know
9548 whether there is a running but stopped thread. */
9549 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9552 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9554 struct remote_g_packet_guess
*guess
;
9556 int bytes
= send_g_packet ();
9559 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9561 if (guess
->bytes
== bytes
)
9562 return guess
->tdesc
;
9564 /* We discard the g packet. A minor optimization would be to
9565 hold on to it, and fill the register cache once we have selected
9566 an architecture, but it's too tricky to do safely. */
9572 /* Remote file transfer support. This is host-initiated I/O, not
9573 target-initiated; for target-initiated, see remote-fileio.c. */
9575 /* If *LEFT is at least the length of STRING, copy STRING to
9576 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9577 decrease *LEFT. Otherwise raise an error. */
9580 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9582 int len
= strlen (string
);
9585 error (_("Packet too long for target."));
9587 memcpy (*buffer
, string
, len
);
9591 /* NUL-terminate the buffer as a convenience, if there is
9597 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9598 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9599 decrease *LEFT. Otherwise raise an error. */
9602 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9605 if (2 * len
> *left
)
9606 error (_("Packet too long for target."));
9608 bin2hex (bytes
, *buffer
, len
);
9612 /* NUL-terminate the buffer as a convenience, if there is
9618 /* If *LEFT is large enough, convert VALUE to hex and add it to
9619 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9620 decrease *LEFT. Otherwise raise an error. */
9623 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9625 int len
= hexnumlen (value
);
9628 error (_("Packet too long for target."));
9630 hexnumstr (*buffer
, value
);
9634 /* NUL-terminate the buffer as a convenience, if there is
9640 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9641 value, *REMOTE_ERRNO to the remote error number or zero if none
9642 was included, and *ATTACHMENT to point to the start of the annex
9643 if any. The length of the packet isn't needed here; there may
9644 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9646 Return 0 if the packet could be parsed, -1 if it could not. If
9647 -1 is returned, the other variables may not be initialized. */
9650 remote_hostio_parse_result (char *buffer
, int *retcode
,
9651 int *remote_errno
, char **attachment
)
9658 if (buffer
[0] != 'F')
9662 *retcode
= strtol (&buffer
[1], &p
, 16);
9663 if (errno
!= 0 || p
== &buffer
[1])
9666 /* Check for ",errno". */
9670 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9671 if (errno
!= 0 || p
+ 1 == p2
)
9676 /* Check for ";attachment". If there is no attachment, the
9677 packet should end here. */
9680 *attachment
= p
+ 1;
9683 else if (*p
== '\0')
9689 /* Send a prepared I/O packet to the target and read its response.
9690 The prepared packet is in the global RS->BUF before this function
9691 is called, and the answer is there when we return.
9693 COMMAND_BYTES is the length of the request to send, which may include
9694 binary data. WHICH_PACKET is the packet configuration to check
9695 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9696 is set to the error number and -1 is returned. Otherwise the value
9697 returned by the function is returned.
9699 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9700 attachment is expected; an error will be reported if there's a
9701 mismatch. If one is found, *ATTACHMENT will be set to point into
9702 the packet buffer and *ATTACHMENT_LEN will be set to the
9703 attachment's length. */
9706 remote_hostio_send_command (int command_bytes
, int which_packet
,
9707 int *remote_errno
, char **attachment
,
9708 int *attachment_len
)
9710 struct remote_state
*rs
= get_remote_state ();
9711 int ret
, bytes_read
;
9712 char *attachment_tmp
;
9714 if (!rs
->remote_desc
9715 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9717 *remote_errno
= FILEIO_ENOSYS
;
9721 putpkt_binary (rs
->buf
, command_bytes
);
9722 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9724 /* If it timed out, something is wrong. Don't try to parse the
9728 *remote_errno
= FILEIO_EINVAL
;
9732 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9735 *remote_errno
= FILEIO_EINVAL
;
9737 case PACKET_UNKNOWN
:
9738 *remote_errno
= FILEIO_ENOSYS
;
9744 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9747 *remote_errno
= FILEIO_EINVAL
;
9751 /* Make sure we saw an attachment if and only if we expected one. */
9752 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9753 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9755 *remote_errno
= FILEIO_EINVAL
;
9759 /* If an attachment was found, it must point into the packet buffer;
9760 work out how many bytes there were. */
9761 if (attachment_tmp
!= NULL
)
9763 *attachment
= attachment_tmp
;
9764 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9770 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9771 remote file descriptor, or -1 if an error occurs (and set
9775 remote_hostio_open (const char *filename
, int flags
, int mode
,
9778 struct remote_state
*rs
= get_remote_state ();
9780 int left
= get_remote_packet_size () - 1;
9782 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9784 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9786 remote_buffer_add_string (&p
, &left
, ",");
9788 remote_buffer_add_int (&p
, &left
, flags
);
9789 remote_buffer_add_string (&p
, &left
, ",");
9791 remote_buffer_add_int (&p
, &left
, mode
);
9793 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9794 remote_errno
, NULL
, NULL
);
9797 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9798 Return the number of bytes written, or -1 if an error occurs (and
9799 set *REMOTE_ERRNO). */
9802 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9803 ULONGEST offset
, int *remote_errno
)
9805 struct remote_state
*rs
= get_remote_state ();
9807 int left
= get_remote_packet_size ();
9810 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9812 remote_buffer_add_int (&p
, &left
, fd
);
9813 remote_buffer_add_string (&p
, &left
, ",");
9815 remote_buffer_add_int (&p
, &left
, offset
);
9816 remote_buffer_add_string (&p
, &left
, ",");
9818 p
+= remote_escape_output (write_buf
, len
, (gdb_byte
*) p
, &out_len
,
9819 get_remote_packet_size () - (p
- rs
->buf
));
9821 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9822 remote_errno
, NULL
, NULL
);
9825 /* Read up to LEN bytes FD on the remote target into READ_BUF
9826 Return the number of bytes read, or -1 if an error occurs (and
9827 set *REMOTE_ERRNO). */
9830 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9831 ULONGEST offset
, int *remote_errno
)
9833 struct remote_state
*rs
= get_remote_state ();
9836 int left
= get_remote_packet_size ();
9837 int ret
, attachment_len
;
9840 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9842 remote_buffer_add_int (&p
, &left
, fd
);
9843 remote_buffer_add_string (&p
, &left
, ",");
9845 remote_buffer_add_int (&p
, &left
, len
);
9846 remote_buffer_add_string (&p
, &left
, ",");
9848 remote_buffer_add_int (&p
, &left
, offset
);
9850 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9851 remote_errno
, &attachment
,
9857 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9859 if (read_len
!= ret
)
9860 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9865 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9866 (and set *REMOTE_ERRNO). */
9869 remote_hostio_close (int fd
, int *remote_errno
)
9871 struct remote_state
*rs
= get_remote_state ();
9873 int left
= get_remote_packet_size () - 1;
9875 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9877 remote_buffer_add_int (&p
, &left
, fd
);
9879 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9880 remote_errno
, NULL
, NULL
);
9883 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9884 occurs (and set *REMOTE_ERRNO). */
9887 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9889 struct remote_state
*rs
= get_remote_state ();
9891 int left
= get_remote_packet_size () - 1;
9893 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9895 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9898 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9899 remote_errno
, NULL
, NULL
);
9902 /* Read value of symbolic link FILENAME on the remote target. Return
9903 a null-terminated string allocated via xmalloc, or NULL if an error
9904 occurs (and set *REMOTE_ERRNO). */
9907 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9909 struct remote_state
*rs
= get_remote_state ();
9912 int left
= get_remote_packet_size ();
9913 int len
, attachment_len
;
9917 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9919 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9922 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9923 remote_errno
, &attachment
,
9929 ret
= xmalloc (len
+ 1);
9931 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9932 (gdb_byte
*) ret
, len
);
9933 if (read_len
!= len
)
9934 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9941 remote_fileio_errno_to_host (int errnum
)
9965 case FILEIO_ENOTDIR
:
9985 case FILEIO_ENAMETOOLONG
:
9986 return ENAMETOOLONG
;
9992 remote_hostio_error (int errnum
)
9994 int host_error
= remote_fileio_errno_to_host (errnum
);
9996 if (host_error
== -1)
9997 error (_("Unknown remote I/O error %d"), errnum
);
9999 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
10003 remote_hostio_close_cleanup (void *opaque
)
10005 int fd
= *(int *) opaque
;
10008 remote_hostio_close (fd
, &remote_errno
);
10013 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
10015 const char *filename
= bfd_get_filename (abfd
);
10016 int fd
, remote_errno
;
10019 gdb_assert (remote_filename_p (filename
));
10021 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
10024 errno
= remote_fileio_errno_to_host (remote_errno
);
10025 bfd_set_error (bfd_error_system_call
);
10029 stream
= xmalloc (sizeof (int));
10035 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
10037 int fd
= *(int *)stream
;
10042 /* Ignore errors on close; these may happen if the remote
10043 connection was already torn down. */
10044 remote_hostio_close (fd
, &remote_errno
);
10046 /* Zero means success. */
10051 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
10052 file_ptr nbytes
, file_ptr offset
)
10054 int fd
= *(int *)stream
;
10056 file_ptr pos
, bytes
;
10059 while (nbytes
> pos
)
10061 bytes
= remote_hostio_pread (fd
, (gdb_byte
*) buf
+ pos
, nbytes
- pos
,
10062 offset
+ pos
, &remote_errno
);
10064 /* Success, but no bytes, means end-of-file. */
10068 errno
= remote_fileio_errno_to_host (remote_errno
);
10069 bfd_set_error (bfd_error_system_call
);
10080 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
10082 /* FIXME: We should probably implement remote_hostio_stat. */
10083 sb
->st_size
= INT_MAX
;
10088 remote_filename_p (const char *filename
)
10090 return strncmp (filename
, "remote:", 7) == 0;
10094 remote_bfd_open (const char *remote_file
, const char *target
)
10096 bfd
*abfd
= gdb_bfd_openr_iovec (remote_file
, target
,
10097 remote_bfd_iovec_open
, NULL
,
10098 remote_bfd_iovec_pread
,
10099 remote_bfd_iovec_close
,
10100 remote_bfd_iovec_stat
);
10106 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10108 struct cleanup
*back_to
, *close_cleanup
;
10109 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10112 int bytes_in_buffer
;
10115 struct remote_state
*rs
= get_remote_state ();
10117 if (!rs
->remote_desc
)
10118 error (_("command can only be used with remote target"));
10120 file
= gdb_fopen_cloexec (local_file
, "rb");
10122 perror_with_name (local_file
);
10123 back_to
= make_cleanup_fclose (file
);
10125 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10127 0700, &remote_errno
);
10129 remote_hostio_error (remote_errno
);
10131 /* Send up to this many bytes at once. They won't all fit in the
10132 remote packet limit, so we'll transfer slightly fewer. */
10133 io_size
= get_remote_packet_size ();
10134 buffer
= xmalloc (io_size
);
10135 make_cleanup (xfree
, buffer
);
10137 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10139 bytes_in_buffer
= 0;
10142 while (bytes_in_buffer
|| !saw_eof
)
10146 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10147 io_size
- bytes_in_buffer
,
10152 error (_("Error reading %s."), local_file
);
10155 /* EOF. Unless there is something still in the
10156 buffer from the last iteration, we are done. */
10158 if (bytes_in_buffer
== 0)
10166 bytes
+= bytes_in_buffer
;
10167 bytes_in_buffer
= 0;
10169 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
10170 offset
, &remote_errno
);
10173 remote_hostio_error (remote_errno
);
10174 else if (retcode
== 0)
10175 error (_("Remote write of %d bytes returned 0!"), bytes
);
10176 else if (retcode
< bytes
)
10178 /* Short write. Save the rest of the read data for the next
10180 bytes_in_buffer
= bytes
- retcode
;
10181 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10187 discard_cleanups (close_cleanup
);
10188 if (remote_hostio_close (fd
, &remote_errno
))
10189 remote_hostio_error (remote_errno
);
10192 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10193 do_cleanups (back_to
);
10197 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10199 struct cleanup
*back_to
, *close_cleanup
;
10200 int fd
, remote_errno
, bytes
, io_size
;
10204 struct remote_state
*rs
= get_remote_state ();
10206 if (!rs
->remote_desc
)
10207 error (_("command can only be used with remote target"));
10209 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10211 remote_hostio_error (remote_errno
);
10213 file
= gdb_fopen_cloexec (local_file
, "wb");
10215 perror_with_name (local_file
);
10216 back_to
= make_cleanup_fclose (file
);
10218 /* Send up to this many bytes at once. They won't all fit in the
10219 remote packet limit, so we'll transfer slightly fewer. */
10220 io_size
= get_remote_packet_size ();
10221 buffer
= xmalloc (io_size
);
10222 make_cleanup (xfree
, buffer
);
10224 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10229 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
10231 /* Success, but no bytes, means end-of-file. */
10234 remote_hostio_error (remote_errno
);
10238 bytes
= fwrite (buffer
, 1, bytes
, file
);
10240 perror_with_name (local_file
);
10243 discard_cleanups (close_cleanup
);
10244 if (remote_hostio_close (fd
, &remote_errno
))
10245 remote_hostio_error (remote_errno
);
10248 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10249 do_cleanups (back_to
);
10253 remote_file_delete (const char *remote_file
, int from_tty
)
10255 int retcode
, remote_errno
;
10256 struct remote_state
*rs
= get_remote_state ();
10258 if (!rs
->remote_desc
)
10259 error (_("command can only be used with remote target"));
10261 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
10263 remote_hostio_error (remote_errno
);
10266 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10270 remote_put_command (char *args
, int from_tty
)
10272 struct cleanup
*back_to
;
10276 error_no_arg (_("file to put"));
10278 argv
= gdb_buildargv (args
);
10279 back_to
= make_cleanup_freeargv (argv
);
10280 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10281 error (_("Invalid parameters to remote put"));
10283 remote_file_put (argv
[0], argv
[1], from_tty
);
10285 do_cleanups (back_to
);
10289 remote_get_command (char *args
, int from_tty
)
10291 struct cleanup
*back_to
;
10295 error_no_arg (_("file to get"));
10297 argv
= gdb_buildargv (args
);
10298 back_to
= make_cleanup_freeargv (argv
);
10299 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10300 error (_("Invalid parameters to remote get"));
10302 remote_file_get (argv
[0], argv
[1], from_tty
);
10304 do_cleanups (back_to
);
10308 remote_delete_command (char *args
, int from_tty
)
10310 struct cleanup
*back_to
;
10314 error_no_arg (_("file to delete"));
10316 argv
= gdb_buildargv (args
);
10317 back_to
= make_cleanup_freeargv (argv
);
10318 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10319 error (_("Invalid parameters to remote delete"));
10321 remote_file_delete (argv
[0], from_tty
);
10323 do_cleanups (back_to
);
10327 remote_command (char *args
, int from_tty
)
10329 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
10333 remote_can_execute_reverse (void)
10335 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
10336 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
10343 remote_supports_non_stop (void)
10349 remote_supports_disable_randomization (void)
10351 /* Only supported in extended mode. */
10356 remote_supports_multi_process (void)
10358 struct remote_state
*rs
= get_remote_state ();
10360 /* Only extended-remote handles being attached to multiple
10361 processes, even though plain remote can use the multi-process
10362 thread id extensions, so that GDB knows the target process's
10364 return rs
->extended
&& remote_multi_process_p (rs
);
10368 remote_supports_cond_tracepoints (void)
10370 struct remote_state
*rs
= get_remote_state ();
10372 return rs
->cond_tracepoints
;
10376 remote_supports_cond_breakpoints (void)
10378 struct remote_state
*rs
= get_remote_state ();
10380 return rs
->cond_breakpoints
;
10384 remote_supports_fast_tracepoints (void)
10386 struct remote_state
*rs
= get_remote_state ();
10388 return rs
->fast_tracepoints
;
10392 remote_supports_static_tracepoints (void)
10394 struct remote_state
*rs
= get_remote_state ();
10396 return rs
->static_tracepoints
;
10400 remote_supports_install_in_trace (void)
10402 struct remote_state
*rs
= get_remote_state ();
10404 return rs
->install_in_trace
;
10408 remote_supports_enable_disable_tracepoint (void)
10410 struct remote_state
*rs
= get_remote_state ();
10412 return rs
->enable_disable_tracepoints
;
10416 remote_supports_string_tracing (void)
10418 struct remote_state
*rs
= get_remote_state ();
10420 return rs
->string_tracing
;
10424 remote_can_run_breakpoint_commands (void)
10426 struct remote_state
*rs
= get_remote_state ();
10428 return rs
->breakpoint_commands
;
10432 remote_trace_init (void)
10435 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10436 if (strcmp (target_buf
, "OK") != 0)
10437 error (_("Target does not support this command."));
10440 static void free_actions_list (char **actions_list
);
10441 static void free_actions_list_cleanup_wrapper (void *);
10443 free_actions_list_cleanup_wrapper (void *al
)
10445 free_actions_list (al
);
10449 free_actions_list (char **actions_list
)
10453 if (actions_list
== 0)
10456 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10457 xfree (actions_list
[ndx
]);
10459 xfree (actions_list
);
10462 /* Recursive routine to walk through command list including loops, and
10463 download packets for each command. */
10466 remote_download_command_source (int num
, ULONGEST addr
,
10467 struct command_line
*cmds
)
10469 struct remote_state
*rs
= get_remote_state ();
10470 struct command_line
*cmd
;
10472 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10474 QUIT
; /* Allow user to bail out with ^C. */
10475 strcpy (rs
->buf
, "QTDPsrc:");
10476 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10477 rs
->buf
+ strlen (rs
->buf
),
10478 rs
->buf_size
- strlen (rs
->buf
));
10480 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10481 if (strcmp (target_buf
, "OK"))
10482 warning (_("Target does not support source download."));
10484 if (cmd
->control_type
== while_control
10485 || cmd
->control_type
== while_stepping_control
)
10487 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10489 QUIT
; /* Allow user to bail out with ^C. */
10490 strcpy (rs
->buf
, "QTDPsrc:");
10491 encode_source_string (num
, addr
, "cmd", "end",
10492 rs
->buf
+ strlen (rs
->buf
),
10493 rs
->buf_size
- strlen (rs
->buf
));
10495 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10496 if (strcmp (target_buf
, "OK"))
10497 warning (_("Target does not support source download."));
10503 remote_download_tracepoint (struct bp_location
*loc
)
10505 #define BUF_SIZE 2048
10509 char buf
[BUF_SIZE
];
10510 char **tdp_actions
;
10511 char **stepping_actions
;
10513 struct cleanup
*old_chain
= NULL
;
10514 struct agent_expr
*aexpr
;
10515 struct cleanup
*aexpr_chain
= NULL
;
10517 struct breakpoint
*b
= loc
->owner
;
10518 struct tracepoint
*t
= (struct tracepoint
*) b
;
10520 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
10521 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10523 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10526 tpaddr
= loc
->address
;
10527 sprintf_vma (addrbuf
, tpaddr
);
10528 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10529 addrbuf
, /* address */
10530 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10531 t
->step_count
, t
->pass_count
);
10532 /* Fast tracepoints are mostly handled by the target, but we can
10533 tell the target how big of an instruction block should be moved
10535 if (b
->type
== bp_fast_tracepoint
)
10537 /* Only test for support at download time; we may not know
10538 target capabilities at definition time. */
10539 if (remote_supports_fast_tracepoints ())
10543 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10544 tpaddr
, &isize
, NULL
))
10545 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10548 /* If it passed validation at definition but fails now,
10549 something is very wrong. */
10550 internal_error (__FILE__
, __LINE__
,
10551 _("Fast tracepoint not "
10552 "valid during download"));
10555 /* Fast tracepoints are functionally identical to regular
10556 tracepoints, so don't take lack of support as a reason to
10557 give up on the trace run. */
10558 warning (_("Target does not support fast tracepoints, "
10559 "downloading %d as regular tracepoint"), b
->number
);
10561 else if (b
->type
== bp_static_tracepoint
)
10563 /* Only test for support at download time; we may not know
10564 target capabilities at definition time. */
10565 if (remote_supports_static_tracepoints ())
10567 struct static_tracepoint_marker marker
;
10569 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10570 strcat (buf
, ":S");
10572 error (_("Static tracepoint not valid during download"));
10575 /* Fast tracepoints are functionally identical to regular
10576 tracepoints, so don't take lack of support as a reason
10577 to give up on the trace run. */
10578 error (_("Target does not support static tracepoints"));
10580 /* If the tracepoint has a conditional, make it into an agent
10581 expression and append to the definition. */
10584 /* Only test support at download time, we may not know target
10585 capabilities at definition time. */
10586 if (remote_supports_cond_tracepoints ())
10588 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10589 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10590 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10592 pkt
= buf
+ strlen (buf
);
10593 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10594 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10596 do_cleanups (aexpr_chain
);
10599 warning (_("Target does not support conditional tracepoints, "
10600 "ignoring tp %d cond"), b
->number
);
10603 if (b
->commands
|| *default_collect
)
10606 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10607 if (strcmp (target_buf
, "OK"))
10608 error (_("Target does not support tracepoints."));
10610 /* do_single_steps (t); */
10613 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10615 QUIT
; /* Allow user to bail out with ^C. */
10616 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10617 b
->number
, addrbuf
, /* address */
10619 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10622 remote_get_noisy_reply (&target_buf
,
10624 if (strcmp (target_buf
, "OK"))
10625 error (_("Error on target while setting tracepoints."));
10628 if (stepping_actions
)
10630 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10632 QUIT
; /* Allow user to bail out with ^C. */
10633 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10634 b
->number
, addrbuf
, /* address */
10635 ((ndx
== 0) ? "S" : ""),
10636 stepping_actions
[ndx
],
10637 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10639 remote_get_noisy_reply (&target_buf
,
10641 if (strcmp (target_buf
, "OK"))
10642 error (_("Error on target while setting tracepoints."));
10646 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10649 if (b
->addr_string
)
10651 strcpy (buf
, "QTDPsrc:");
10652 encode_source_string (b
->number
, loc
->address
,
10653 "at", b
->addr_string
, buf
+ strlen (buf
),
10654 2048 - strlen (buf
));
10657 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10658 if (strcmp (target_buf
, "OK"))
10659 warning (_("Target does not support source download."));
10661 if (b
->cond_string
)
10663 strcpy (buf
, "QTDPsrc:");
10664 encode_source_string (b
->number
, loc
->address
,
10665 "cond", b
->cond_string
, buf
+ strlen (buf
),
10666 2048 - strlen (buf
));
10668 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10669 if (strcmp (target_buf
, "OK"))
10670 warning (_("Target does not support source download."));
10672 remote_download_command_source (b
->number
, loc
->address
,
10673 breakpoint_commands (b
));
10676 do_cleanups (old_chain
);
10680 remote_can_download_tracepoint (void)
10682 struct remote_state
*rs
= get_remote_state ();
10683 struct trace_status
*ts
;
10686 /* Don't try to install tracepoints until we've relocated our
10687 symbols, and fetched and merged the target's tracepoint list with
10689 if (rs
->starting_up
)
10692 ts
= current_trace_status ();
10693 status
= remote_get_trace_status (ts
);
10695 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10698 /* If we are in a tracing experiment, but remote stub doesn't support
10699 installing tracepoint in trace, we have to return. */
10700 if (!remote_supports_install_in_trace ())
10708 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10710 struct remote_state
*rs
= get_remote_state ();
10713 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10714 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10716 p
= rs
->buf
+ strlen (rs
->buf
);
10717 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10718 error (_("Trace state variable name too long for tsv definition packet"));
10719 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10722 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10723 if (*target_buf
== '\0')
10724 error (_("Target does not support this command."));
10725 if (strcmp (target_buf
, "OK") != 0)
10726 error (_("Error on target while downloading trace state variable."));
10730 remote_enable_tracepoint (struct bp_location
*location
)
10732 struct remote_state
*rs
= get_remote_state ();
10735 sprintf_vma (addr_buf
, location
->address
);
10736 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10737 location
->owner
->number
, addr_buf
);
10739 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10740 if (*rs
->buf
== '\0')
10741 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10742 if (strcmp (rs
->buf
, "OK") != 0)
10743 error (_("Error on target while enabling tracepoint."));
10747 remote_disable_tracepoint (struct bp_location
*location
)
10749 struct remote_state
*rs
= get_remote_state ();
10752 sprintf_vma (addr_buf
, location
->address
);
10753 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10754 location
->owner
->number
, addr_buf
);
10756 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10757 if (*rs
->buf
== '\0')
10758 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10759 if (strcmp (rs
->buf
, "OK") != 0)
10760 error (_("Error on target while disabling tracepoint."));
10764 remote_trace_set_readonly_regions (void)
10768 bfd_size_type size
;
10774 return; /* No information to give. */
10776 strcpy (target_buf
, "QTro");
10777 offset
= strlen (target_buf
);
10778 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10780 char tmp1
[40], tmp2
[40];
10783 if ((s
->flags
& SEC_LOAD
) == 0 ||
10784 /* (s->flags & SEC_CODE) == 0 || */
10785 (s
->flags
& SEC_READONLY
) == 0)
10789 vma
= bfd_get_section_vma (abfd
, s
);
10790 size
= bfd_get_section_size (s
);
10791 sprintf_vma (tmp1
, vma
);
10792 sprintf_vma (tmp2
, vma
+ size
);
10793 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10794 if (offset
+ sec_length
+ 1 > target_buf_size
)
10796 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10799 Too many sections for read-only sections definition packet."));
10802 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10804 offset
+= sec_length
;
10808 putpkt (target_buf
);
10809 getpkt (&target_buf
, &target_buf_size
, 0);
10814 remote_trace_start (void)
10816 putpkt ("QTStart");
10817 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10818 if (*target_buf
== '\0')
10819 error (_("Target does not support this command."));
10820 if (strcmp (target_buf
, "OK") != 0)
10821 error (_("Bogus reply from target: %s"), target_buf
);
10825 remote_get_trace_status (struct trace_status
*ts
)
10827 /* Initialize it just to avoid a GCC false warning. */
10829 /* FIXME we need to get register block size some other way. */
10830 extern int trace_regblock_size
;
10831 volatile struct gdb_exception ex
;
10832 enum packet_result result
;
10834 if (remote_protocol_packets
[PACKET_qTStatus
].support
== PACKET_DISABLE
)
10837 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10839 putpkt ("qTStatus");
10841 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10843 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10847 if (ex
.error
!= TARGET_CLOSE_ERROR
)
10849 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10852 throw_exception (ex
);
10855 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
10857 /* If the remote target doesn't do tracing, flag it. */
10858 if (result
== PACKET_UNKNOWN
)
10861 /* We're working with a live target. */
10862 ts
->filename
= NULL
;
10865 error (_("Bogus trace status reply from target: %s"), target_buf
);
10867 /* Function 'parse_trace_status' sets default value of each field of
10868 'ts' at first, so we don't have to do it here. */
10869 parse_trace_status (p
, ts
);
10871 return ts
->running
;
10875 remote_get_tracepoint_status (struct breakpoint
*bp
,
10876 struct uploaded_tp
*utp
)
10878 struct remote_state
*rs
= get_remote_state ();
10880 struct bp_location
*loc
;
10881 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10882 size_t size
= get_remote_packet_size ();
10886 tp
->base
.hit_count
= 0;
10887 tp
->traceframe_usage
= 0;
10888 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10890 /* If the tracepoint was never downloaded, don't go asking for
10892 if (tp
->number_on_target
== 0)
10894 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10895 phex_nz (loc
->address
, 0));
10897 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10898 if (reply
&& *reply
)
10901 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10907 utp
->hit_count
= 0;
10908 utp
->traceframe_usage
= 0;
10909 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10910 phex_nz (utp
->addr
, 0));
10912 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10913 if (reply
&& *reply
)
10916 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10922 remote_trace_stop (void)
10925 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10926 if (*target_buf
== '\0')
10927 error (_("Target does not support this command."));
10928 if (strcmp (target_buf
, "OK") != 0)
10929 error (_("Bogus reply from target: %s"), target_buf
);
10933 remote_trace_find (enum trace_find_type type
, int num
,
10934 CORE_ADDR addr1
, CORE_ADDR addr2
,
10937 struct remote_state
*rs
= get_remote_state ();
10938 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10940 int target_frameno
= -1, target_tracept
= -1;
10942 /* Lookups other than by absolute frame number depend on the current
10943 trace selected, so make sure it is correct on the remote end
10945 if (type
!= tfind_number
)
10946 set_remote_traceframe ();
10949 strcpy (p
, "QTFrame:");
10950 p
= strchr (p
, '\0');
10954 xsnprintf (p
, endbuf
- p
, "%x", num
);
10957 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
10960 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
10963 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
10964 phex_nz (addr2
, 0));
10966 case tfind_outside
:
10967 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
10968 phex_nz (addr2
, 0));
10971 error (_("Unknown trace find type %d"), type
);
10975 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10976 if (*reply
== '\0')
10977 error (_("Target does not support this command."));
10979 while (reply
&& *reply
)
10984 target_frameno
= (int) strtol (p
, &reply
, 16);
10986 error (_("Unable to parse trace frame number"));
10987 /* Don't update our remote traceframe number cache on failure
10988 to select a remote traceframe. */
10989 if (target_frameno
== -1)
10994 target_tracept
= (int) strtol (p
, &reply
, 16);
10996 error (_("Unable to parse tracepoint number"));
10998 case 'O': /* "OK"? */
10999 if (reply
[1] == 'K' && reply
[2] == '\0')
11002 error (_("Bogus reply from target: %s"), reply
);
11005 error (_("Bogus reply from target: %s"), reply
);
11008 *tpp
= target_tracept
;
11010 rs
->remote_traceframe_number
= target_frameno
;
11011 return target_frameno
;
11015 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
11017 struct remote_state
*rs
= get_remote_state ();
11021 set_remote_traceframe ();
11023 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
11025 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11026 if (reply
&& *reply
)
11030 unpack_varlen_hex (reply
+ 1, &uval
);
11031 *val
= (LONGEST
) uval
;
11039 remote_save_trace_data (const char *filename
)
11041 struct remote_state
*rs
= get_remote_state ();
11045 strcpy (p
, "QTSave:");
11047 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
11048 error (_("Remote file name too long for trace save packet"));
11049 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
11052 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11053 if (*reply
== '\0')
11054 error (_("Target does not support this command."));
11055 if (strcmp (reply
, "OK") != 0)
11056 error (_("Bogus reply from target: %s"), reply
);
11060 /* This is basically a memory transfer, but needs to be its own packet
11061 because we don't know how the target actually organizes its trace
11062 memory, plus we want to be able to ask for as much as possible, but
11063 not be unhappy if we don't get as much as we ask for. */
11066 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11068 struct remote_state
*rs
= get_remote_state ();
11074 strcpy (p
, "qTBuffer:");
11076 p
+= hexnumstr (p
, offset
);
11078 p
+= hexnumstr (p
, len
);
11082 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11083 if (reply
&& *reply
)
11085 /* 'l' by itself means we're at the end of the buffer and
11086 there is nothing more to get. */
11090 /* Convert the reply into binary. Limit the number of bytes to
11091 convert according to our passed-in buffer size, rather than
11092 what was returned in the packet; if the target is
11093 unexpectedly generous and gives us a bigger reply than we
11094 asked for, we don't want to crash. */
11095 rslt
= hex2bin (target_buf
, buf
, len
);
11099 /* Something went wrong, flag as an error. */
11104 remote_set_disconnected_tracing (int val
)
11106 struct remote_state
*rs
= get_remote_state ();
11108 if (rs
->disconnected_tracing
)
11112 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11114 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11115 if (*reply
== '\0')
11116 error (_("Target does not support this command."));
11117 if (strcmp (reply
, "OK") != 0)
11118 error (_("Bogus reply from target: %s"), reply
);
11121 warning (_("Target does not support disconnected tracing."));
11125 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11127 struct thread_info
*info
= find_thread_ptid (ptid
);
11129 if (info
&& info
->private)
11130 return info
->private->core
;
11135 remote_set_circular_trace_buffer (int val
)
11137 struct remote_state
*rs
= get_remote_state ();
11140 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11142 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11143 if (*reply
== '\0')
11144 error (_("Target does not support this command."));
11145 if (strcmp (reply
, "OK") != 0)
11146 error (_("Bogus reply from target: %s"), reply
);
11149 static struct traceframe_info
*
11150 remote_traceframe_info (void)
11154 text
= target_read_stralloc (¤t_target
,
11155 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11158 struct traceframe_info
*info
;
11159 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11161 info
= parse_traceframe_info (text
);
11162 do_cleanups (back_to
);
11169 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11170 instruction on which a fast tracepoint may be placed. Returns -1
11171 if the packet is not supported, and 0 if the minimum instruction
11172 length is unknown. */
11175 remote_get_min_fast_tracepoint_insn_len (void)
11177 struct remote_state
*rs
= get_remote_state ();
11180 /* If we're not debugging a process yet, the IPA can't be
11182 if (!target_has_execution
)
11185 /* Make sure the remote is pointing at the right process. */
11186 set_general_process ();
11188 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11190 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11191 if (*reply
== '\0')
11195 ULONGEST min_insn_len
;
11197 unpack_varlen_hex (reply
, &min_insn_len
);
11199 return (int) min_insn_len
;
11204 remote_set_trace_buffer_size (LONGEST val
)
11206 if (remote_protocol_packets
[PACKET_QTBuffer_size
].support
11209 struct remote_state
*rs
= get_remote_state ();
11210 char *buf
= rs
->buf
;
11211 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11212 enum packet_result result
;
11214 gdb_assert (val
>= 0 || val
== -1);
11215 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11216 /* Send -1 as literal "-1" to avoid host size dependency. */
11220 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11223 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11226 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11227 result
= packet_ok (rs
->buf
,
11228 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11230 if (result
!= PACKET_OK
)
11231 warning (_("Bogus reply from target: %s"), rs
->buf
);
11236 remote_set_trace_notes (const char *user
, const char *notes
,
11237 const char *stop_notes
)
11239 struct remote_state
*rs
= get_remote_state ();
11241 char *buf
= rs
->buf
;
11242 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11245 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11248 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11249 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, 0);
11255 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11256 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, 0);
11262 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11263 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, 0);
11267 /* Ensure the buffer is terminated. */
11271 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11272 if (*reply
== '\0')
11275 if (strcmp (reply
, "OK") != 0)
11276 error (_("Bogus reply from target: %s"), reply
);
11282 remote_use_agent (int use
)
11284 if (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
)
11286 struct remote_state
*rs
= get_remote_state ();
11288 /* If the stub supports QAgent. */
11289 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11291 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11293 if (strcmp (rs
->buf
, "OK") == 0)
11304 remote_can_use_agent (void)
11306 return (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
);
11309 struct btrace_target_info
11311 /* The ptid of the traced thread. */
11315 /* Check whether the target supports branch tracing. */
11318 remote_supports_btrace (void)
11320 if (remote_protocol_packets
[PACKET_Qbtrace_off
].support
!= PACKET_ENABLE
)
11322 if (remote_protocol_packets
[PACKET_Qbtrace_bts
].support
!= PACKET_ENABLE
)
11324 if (remote_protocol_packets
[PACKET_qXfer_btrace
].support
!= PACKET_ENABLE
)
11330 /* Enable branch tracing. */
11332 static struct btrace_target_info
*
11333 remote_enable_btrace (ptid_t ptid
)
11335 struct btrace_target_info
*tinfo
= NULL
;
11336 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
11337 struct remote_state
*rs
= get_remote_state ();
11338 char *buf
= rs
->buf
;
11339 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11341 if (packet
->support
!= PACKET_ENABLE
)
11342 error (_("Target does not support branch tracing."));
11344 set_general_thread (ptid
);
11346 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11348 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11350 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11352 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11353 error (_("Could not enable branch tracing for %s: %s"),
11354 target_pid_to_str (ptid
), rs
->buf
+ 2);
11356 error (_("Could not enable branch tracing for %s."),
11357 target_pid_to_str (ptid
));
11360 tinfo
= xzalloc (sizeof (*tinfo
));
11361 tinfo
->ptid
= ptid
;
11366 /* Disable branch tracing. */
11369 remote_disable_btrace (struct btrace_target_info
*tinfo
)
11371 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
11372 struct remote_state
*rs
= get_remote_state ();
11373 char *buf
= rs
->buf
;
11374 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11376 if (packet
->support
!= PACKET_ENABLE
)
11377 error (_("Target does not support branch tracing."));
11379 set_general_thread (tinfo
->ptid
);
11381 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11383 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11385 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11387 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11388 error (_("Could not disable branch tracing for %s: %s"),
11389 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
11391 error (_("Could not disable branch tracing for %s."),
11392 target_pid_to_str (tinfo
->ptid
));
11398 /* Teardown branch tracing. */
11401 remote_teardown_btrace (struct btrace_target_info
*tinfo
)
11403 /* We must not talk to the target during teardown. */
11407 /* Read the branch trace. */
11409 static VEC (btrace_block_s
) *
11410 remote_read_btrace (struct btrace_target_info
*tinfo
,
11411 enum btrace_read_type type
)
11413 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
11414 struct remote_state
*rs
= get_remote_state ();
11415 VEC (btrace_block_s
) *btrace
= NULL
;
11419 if (packet
->support
!= PACKET_ENABLE
)
11420 error (_("Target does not support branch tracing."));
11422 #if !defined(HAVE_LIBEXPAT)
11423 error (_("Cannot process branch tracing result. XML parsing not supported."));
11428 case btrace_read_all
:
11431 case btrace_read_new
:
11435 internal_error (__FILE__
, __LINE__
,
11436 _("Bad branch tracing read type: %u."),
11437 (unsigned int) type
);
11440 xml
= target_read_stralloc (¤t_target
,
11441 TARGET_OBJECT_BTRACE
, annex
);
11444 struct cleanup
*cleanup
= make_cleanup (xfree
, xml
);
11446 btrace
= parse_xml_btrace (xml
);
11447 do_cleanups (cleanup
);
11454 remote_augmented_libraries_svr4_read (void)
11456 struct remote_state
*rs
= get_remote_state ();
11458 return rs
->augmented_libraries_svr4_read
;
11462 init_remote_ops (void)
11464 remote_ops
.to_shortname
= "remote";
11465 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11466 remote_ops
.to_doc
=
11467 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11468 Specify the serial device it is connected to\n\
11469 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11470 remote_ops
.to_open
= remote_open
;
11471 remote_ops
.to_close
= remote_close
;
11472 remote_ops
.to_detach
= remote_detach
;
11473 remote_ops
.to_disconnect
= remote_disconnect
;
11474 remote_ops
.to_resume
= remote_resume
;
11475 remote_ops
.to_wait
= remote_wait
;
11476 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11477 remote_ops
.to_store_registers
= remote_store_registers
;
11478 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11479 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
11480 remote_ops
.to_files_info
= remote_files_info
;
11481 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11482 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11483 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11484 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11485 remote_ops
.to_watchpoint_addr_within_range
=
11486 remote_watchpoint_addr_within_range
;
11487 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11488 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11489 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11490 remote_ops
.to_region_ok_for_hw_watchpoint
11491 = remote_region_ok_for_hw_watchpoint
;
11492 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11493 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11494 remote_ops
.to_kill
= remote_kill
;
11495 remote_ops
.to_load
= generic_load
;
11496 remote_ops
.to_mourn_inferior
= remote_mourn
;
11497 remote_ops
.to_pass_signals
= remote_pass_signals
;
11498 remote_ops
.to_program_signals
= remote_program_signals
;
11499 remote_ops
.to_thread_alive
= remote_thread_alive
;
11500 remote_ops
.to_find_new_threads
= remote_threads_info
;
11501 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11502 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11503 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11504 remote_ops
.to_stop
= remote_stop
;
11505 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11506 remote_ops
.to_rcmd
= remote_rcmd
;
11507 remote_ops
.to_log_command
= serial_log_command
;
11508 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11509 remote_ops
.to_stratum
= process_stratum
;
11510 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11511 remote_ops
.to_has_memory
= default_child_has_memory
;
11512 remote_ops
.to_has_stack
= default_child_has_stack
;
11513 remote_ops
.to_has_registers
= default_child_has_registers
;
11514 remote_ops
.to_has_execution
= default_child_has_execution
;
11515 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11516 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11517 remote_ops
.to_magic
= OPS_MAGIC
;
11518 remote_ops
.to_memory_map
= remote_memory_map
;
11519 remote_ops
.to_flash_erase
= remote_flash_erase
;
11520 remote_ops
.to_flash_done
= remote_flash_done
;
11521 remote_ops
.to_read_description
= remote_read_description
;
11522 remote_ops
.to_search_memory
= remote_search_memory
;
11523 remote_ops
.to_can_async_p
= remote_can_async_p
;
11524 remote_ops
.to_is_async_p
= remote_is_async_p
;
11525 remote_ops
.to_async
= remote_async
;
11526 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11527 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11528 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11529 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11530 remote_ops
.to_supports_disable_randomization
11531 = remote_supports_disable_randomization
;
11532 remote_ops
.to_fileio_open
= remote_hostio_open
;
11533 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11534 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11535 remote_ops
.to_fileio_close
= remote_hostio_close
;
11536 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11537 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11538 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11539 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11540 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11541 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11542 remote_ops
.to_trace_init
= remote_trace_init
;
11543 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11544 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11545 remote_ops
.to_download_trace_state_variable
11546 = remote_download_trace_state_variable
;
11547 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11548 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11549 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11550 remote_ops
.to_trace_start
= remote_trace_start
;
11551 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11552 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11553 remote_ops
.to_trace_stop
= remote_trace_stop
;
11554 remote_ops
.to_trace_find
= remote_trace_find
;
11555 remote_ops
.to_get_trace_state_variable_value
11556 = remote_get_trace_state_variable_value
;
11557 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11558 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11559 remote_ops
.to_upload_trace_state_variables
11560 = remote_upload_trace_state_variables
;
11561 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11562 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11563 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11564 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11565 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
11566 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11567 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11568 remote_ops
.to_verify_memory
= remote_verify_memory
;
11569 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11570 remote_ops
.to_set_permissions
= remote_set_permissions
;
11571 remote_ops
.to_static_tracepoint_marker_at
11572 = remote_static_tracepoint_marker_at
;
11573 remote_ops
.to_static_tracepoint_markers_by_strid
11574 = remote_static_tracepoint_markers_by_strid
;
11575 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11576 remote_ops
.to_use_agent
= remote_use_agent
;
11577 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11578 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
11579 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
11580 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
11581 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
11582 remote_ops
.to_read_btrace
= remote_read_btrace
;
11583 remote_ops
.to_augmented_libraries_svr4_read
=
11584 remote_augmented_libraries_svr4_read
;
11587 /* Set up the extended remote vector by making a copy of the standard
11588 remote vector and adding to it. */
11591 init_extended_remote_ops (void)
11593 extended_remote_ops
= remote_ops
;
11595 extended_remote_ops
.to_shortname
= "extended-remote";
11596 extended_remote_ops
.to_longname
=
11597 "Extended remote serial target in gdb-specific protocol";
11598 extended_remote_ops
.to_doc
=
11599 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11600 Specify the serial device it is connected to (e.g. /dev/ttya).";
11601 extended_remote_ops
.to_open
= extended_remote_open
;
11602 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11603 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11604 extended_remote_ops
.to_detach
= extended_remote_detach
;
11605 extended_remote_ops
.to_attach
= extended_remote_attach
;
11606 extended_remote_ops
.to_kill
= extended_remote_kill
;
11607 extended_remote_ops
.to_supports_disable_randomization
11608 = extended_remote_supports_disable_randomization
;
11612 remote_can_async_p (void)
11614 struct remote_state
*rs
= get_remote_state ();
11616 if (!target_async_permitted
)
11617 /* We only enable async when the user specifically asks for it. */
11620 /* We're async whenever the serial device is. */
11621 return serial_can_async_p (rs
->remote_desc
);
11625 remote_is_async_p (void)
11627 struct remote_state
*rs
= get_remote_state ();
11629 if (!target_async_permitted
)
11630 /* We only enable async when the user specifically asks for it. */
11633 /* We're async whenever the serial device is. */
11634 return serial_is_async_p (rs
->remote_desc
);
11637 /* Pass the SERIAL event on and up to the client. One day this code
11638 will be able to delay notifying the client of an event until the
11639 point where an entire packet has been received. */
11641 static void (*async_client_callback
) (enum inferior_event_type event_type
,
11643 static void *async_client_context
;
11644 static serial_event_ftype remote_async_serial_handler
;
11647 remote_async_serial_handler (struct serial
*scb
, void *context
)
11649 /* Don't propogate error information up to the client. Instead let
11650 the client find out about the error by querying the target. */
11651 async_client_callback (INF_REG_EVENT
, async_client_context
);
11655 remote_async_inferior_event_handler (gdb_client_data data
)
11657 inferior_event_handler (INF_REG_EVENT
, NULL
);
11661 remote_async (void (*callback
) (enum inferior_event_type event_type
,
11662 void *context
), void *context
)
11664 struct remote_state
*rs
= get_remote_state ();
11666 if (callback
!= NULL
)
11668 serial_async (rs
->remote_desc
, remote_async_serial_handler
, NULL
);
11669 async_client_callback
= callback
;
11670 async_client_context
= context
;
11673 serial_async (rs
->remote_desc
, NULL
, NULL
);
11677 set_remote_cmd (char *args
, int from_tty
)
11679 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
11683 show_remote_cmd (char *args
, int from_tty
)
11685 /* We can't just use cmd_show_list here, because we want to skip
11686 the redundant "show remote Z-packet" and the legacy aliases. */
11687 struct cleanup
*showlist_chain
;
11688 struct cmd_list_element
*list
= remote_show_cmdlist
;
11689 struct ui_out
*uiout
= current_uiout
;
11691 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11692 for (; list
!= NULL
; list
= list
->next
)
11693 if (strcmp (list
->name
, "Z-packet") == 0)
11695 else if (list
->type
== not_set_cmd
)
11696 /* Alias commands are exactly like the original, except they
11697 don't have the normal type. */
11701 struct cleanup
*option_chain
11702 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11704 ui_out_field_string (uiout
, "name", list
->name
);
11705 ui_out_text (uiout
, ": ");
11706 if (list
->type
== show_cmd
)
11707 do_show_command ((char *) NULL
, from_tty
, list
);
11709 cmd_func (list
, NULL
, from_tty
);
11710 /* Close the tuple. */
11711 do_cleanups (option_chain
);
11714 /* Close the tuple. */
11715 do_cleanups (showlist_chain
);
11719 /* Function to be called whenever a new objfile (shlib) is detected. */
11721 remote_new_objfile (struct objfile
*objfile
)
11723 struct remote_state
*rs
= get_remote_state ();
11725 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
11726 remote_check_symbols ();
11729 /* Pull all the tracepoints defined on the target and create local
11730 data structures representing them. We don't want to create real
11731 tracepoints yet, we don't want to mess up the user's existing
11735 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
11737 struct remote_state
*rs
= get_remote_state ();
11740 /* Ask for a first packet of tracepoint definition. */
11742 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11744 while (*p
&& *p
!= 'l')
11746 parse_tracepoint_definition (p
, utpp
);
11747 /* Ask for another packet of tracepoint definition. */
11749 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11756 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
11758 struct remote_state
*rs
= get_remote_state ();
11761 /* Ask for a first packet of variable definition. */
11763 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11765 while (*p
&& *p
!= 'l')
11767 parse_tsv_definition (p
, utsvp
);
11768 /* Ask for another packet of variable definition. */
11770 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11776 /* The "set/show range-stepping" show hook. */
11779 show_range_stepping (struct ui_file
*file
, int from_tty
,
11780 struct cmd_list_element
*c
,
11783 fprintf_filtered (file
,
11784 _("Debugger's willingness to use range stepping "
11785 "is %s.\n"), value
);
11788 /* The "set/show range-stepping" set hook. */
11791 set_range_stepping (char *ignore_args
, int from_tty
,
11792 struct cmd_list_element
*c
)
11794 struct remote_state
*rs
= get_remote_state ();
11796 /* Whene enabling, check whether range stepping is actually
11797 supported by the target, and warn if not. */
11798 if (use_range_stepping
)
11800 if (rs
->remote_desc
!= NULL
)
11802 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
11803 remote_vcont_probe (rs
);
11805 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_ENABLE
11806 && rs
->supports_vCont
.r
)
11810 warning (_("Range stepping is not supported by the current target"));
11815 _initialize_remote (void)
11817 struct remote_state
*rs
;
11818 struct cmd_list_element
*cmd
;
11819 const char *cmd_name
;
11821 /* architecture specific data */
11822 remote_gdbarch_data_handle
=
11823 gdbarch_data_register_post_init (init_remote_state
);
11824 remote_g_packet_data_handle
=
11825 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
11827 /* Initialize the per-target state. At the moment there is only one
11828 of these, not one per target. Only one target is active at a
11830 remote_state
= new_remote_state ();
11832 init_remote_ops ();
11833 add_target (&remote_ops
);
11835 init_extended_remote_ops ();
11836 add_target (&extended_remote_ops
);
11838 /* Hook into new objfile notification. */
11839 observer_attach_new_objfile (remote_new_objfile
);
11840 /* We're no longer interested in notification events of an inferior
11842 observer_attach_inferior_exit (discard_pending_stop_replies
);
11844 /* Set up signal handlers. */
11845 async_sigint_remote_token
=
11846 create_async_signal_handler (async_remote_interrupt
, NULL
);
11847 async_sigint_remote_twice_token
=
11848 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11851 init_remote_threadtests ();
11854 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
11855 /* set/show remote ... */
11857 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11858 Remote protocol specific variables\n\
11859 Configure various remote-protocol specific variables such as\n\
11860 the packets being used"),
11861 &remote_set_cmdlist
, "set remote ",
11862 0 /* allow-unknown */, &setlist
);
11863 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11864 Remote protocol specific variables\n\
11865 Configure various remote-protocol specific variables such as\n\
11866 the packets being used"),
11867 &remote_show_cmdlist
, "show remote ",
11868 0 /* allow-unknown */, &showlist
);
11870 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11871 Compare section data on target to the exec file.\n\
11872 Argument is a single section name (default: all loaded sections)."),
11875 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11876 Send an arbitrary packet to a remote target.\n\
11877 maintenance packet TEXT\n\
11878 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11879 this command sends the string TEXT to the inferior, and displays the\n\
11880 response packet. GDB supplies the initial `$' character, and the\n\
11881 terminating `#' character and checksum."),
11884 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11885 Set whether to send break if interrupted."), _("\
11886 Show whether to send break if interrupted."), _("\
11887 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11888 set_remotebreak
, show_remotebreak
,
11889 &setlist
, &showlist
);
11890 cmd_name
= "remotebreak";
11891 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11892 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11893 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11894 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11895 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11897 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11898 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11900 Set interrupt sequence to remote target."), _("\
11901 Show interrupt sequence to remote target."), _("\
11902 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11903 NULL
, show_interrupt_sequence
,
11904 &remote_set_cmdlist
,
11905 &remote_show_cmdlist
);
11907 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11908 &interrupt_on_connect
, _("\
11909 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11910 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11911 If set, interrupt sequence is sent to remote target."),
11913 &remote_set_cmdlist
, &remote_show_cmdlist
);
11915 /* Install commands for configuring memory read/write packets. */
11917 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11918 Set the maximum number of bytes per memory write packet (deprecated)."),
11920 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11921 Show the maximum number of bytes per memory write packet (deprecated)."),
11923 add_cmd ("memory-write-packet-size", no_class
,
11924 set_memory_write_packet_size
, _("\
11925 Set the maximum number of bytes per memory-write packet.\n\
11926 Specify the number of bytes in a packet or 0 (zero) for the\n\
11927 default packet size. The actual limit is further reduced\n\
11928 dependent on the target. Specify ``fixed'' to disable the\n\
11929 further restriction and ``limit'' to enable that restriction."),
11930 &remote_set_cmdlist
);
11931 add_cmd ("memory-read-packet-size", no_class
,
11932 set_memory_read_packet_size
, _("\
11933 Set the maximum number of bytes per memory-read packet.\n\
11934 Specify the number of bytes in a packet or 0 (zero) for the\n\
11935 default packet size. The actual limit is further reduced\n\
11936 dependent on the target. Specify ``fixed'' to disable the\n\
11937 further restriction and ``limit'' to enable that restriction."),
11938 &remote_set_cmdlist
);
11939 add_cmd ("memory-write-packet-size", no_class
,
11940 show_memory_write_packet_size
,
11941 _("Show the maximum number of bytes per memory-write packet."),
11942 &remote_show_cmdlist
);
11943 add_cmd ("memory-read-packet-size", no_class
,
11944 show_memory_read_packet_size
,
11945 _("Show the maximum number of bytes per memory-read packet."),
11946 &remote_show_cmdlist
);
11948 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11949 &remote_hw_watchpoint_limit
, _("\
11950 Set the maximum number of target hardware watchpoints."), _("\
11951 Show the maximum number of target hardware watchpoints."), _("\
11952 Specify a negative limit for unlimited."),
11953 NULL
, NULL
, /* FIXME: i18n: The maximum
11954 number of target hardware
11955 watchpoints is %s. */
11956 &remote_set_cmdlist
, &remote_show_cmdlist
);
11957 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11958 &remote_hw_watchpoint_length_limit
, _("\
11959 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11960 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11961 Specify a negative limit for unlimited."),
11962 NULL
, NULL
, /* FIXME: i18n: The maximum
11963 length (in bytes) of a target
11964 hardware watchpoint is %s. */
11965 &remote_set_cmdlist
, &remote_show_cmdlist
);
11966 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11967 &remote_hw_breakpoint_limit
, _("\
11968 Set the maximum number of target hardware breakpoints."), _("\
11969 Show the maximum number of target hardware breakpoints."), _("\
11970 Specify a negative limit for unlimited."),
11971 NULL
, NULL
, /* FIXME: i18n: The maximum
11972 number of target hardware
11973 breakpoints is %s. */
11974 &remote_set_cmdlist
, &remote_show_cmdlist
);
11976 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
11977 &remote_address_size
, _("\
11978 Set the maximum size of the address (in bits) in a memory packet."), _("\
11979 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11981 NULL
, /* FIXME: i18n: */
11982 &setlist
, &showlist
);
11984 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11985 "X", "binary-download", 1);
11987 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11988 "vCont", "verbose-resume", 0);
11990 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11991 "QPassSignals", "pass-signals", 0);
11993 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
11994 "QProgramSignals", "program-signals", 0);
11996 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11997 "qSymbol", "symbol-lookup", 0);
11999 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
12000 "P", "set-register", 1);
12002 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
12003 "p", "fetch-register", 1);
12005 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
12006 "Z0", "software-breakpoint", 0);
12008 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
12009 "Z1", "hardware-breakpoint", 0);
12011 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
12012 "Z2", "write-watchpoint", 0);
12014 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
12015 "Z3", "read-watchpoint", 0);
12017 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
12018 "Z4", "access-watchpoint", 0);
12020 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
12021 "qXfer:auxv:read", "read-aux-vector", 0);
12023 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
12024 "qXfer:features:read", "target-features", 0);
12026 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
12027 "qXfer:libraries:read", "library-info", 0);
12029 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
12030 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
12032 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
12033 "qXfer:memory-map:read", "memory-map", 0);
12035 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
12036 "qXfer:spu:read", "read-spu-object", 0);
12038 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
12039 "qXfer:spu:write", "write-spu-object", 0);
12041 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
12042 "qXfer:osdata:read", "osdata", 0);
12044 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
12045 "qXfer:threads:read", "threads", 0);
12047 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
12048 "qXfer:siginfo:read", "read-siginfo-object", 0);
12050 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
12051 "qXfer:siginfo:write", "write-siginfo-object", 0);
12053 add_packet_config_cmd
12054 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
12055 "qXfer:traceframe-info:read", "traceframe-info", 0);
12057 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
12058 "qXfer:uib:read", "unwind-info-block", 0);
12060 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
12061 "qGetTLSAddr", "get-thread-local-storage-address",
12064 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
12065 "qGetTIBAddr", "get-thread-information-block-address",
12068 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
12069 "bc", "reverse-continue", 0);
12071 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
12072 "bs", "reverse-step", 0);
12074 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
12075 "qSupported", "supported-packets", 0);
12077 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
12078 "qSearch:memory", "search-memory", 0);
12080 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
12081 "qTStatus", "trace-status", 0);
12083 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
12084 "vFile:open", "hostio-open", 0);
12086 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
12087 "vFile:pread", "hostio-pread", 0);
12089 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
12090 "vFile:pwrite", "hostio-pwrite", 0);
12092 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
12093 "vFile:close", "hostio-close", 0);
12095 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
12096 "vFile:unlink", "hostio-unlink", 0);
12098 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
12099 "vFile:readlink", "hostio-readlink", 0);
12101 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
12102 "vAttach", "attach", 0);
12104 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
12107 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
12108 "QStartNoAckMode", "noack", 0);
12110 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
12111 "vKill", "kill", 0);
12113 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
12114 "qAttached", "query-attached", 0);
12116 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
12117 "ConditionalTracepoints",
12118 "conditional-tracepoints", 0);
12120 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
12121 "ConditionalBreakpoints",
12122 "conditional-breakpoints", 0);
12124 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
12125 "BreakpointCommands",
12126 "breakpoint-commands", 0);
12128 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
12129 "FastTracepoints", "fast-tracepoints", 0);
12131 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
12132 "TracepointSource", "TracepointSource", 0);
12134 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
12135 "QAllow", "allow", 0);
12137 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
12138 "StaticTracepoints", "static-tracepoints", 0);
12140 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
12141 "InstallInTrace", "install-in-trace", 0);
12143 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
12144 "qXfer:statictrace:read", "read-sdata-object", 0);
12146 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
12147 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12149 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
12150 "QDisableRandomization", "disable-randomization", 0);
12152 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
12153 "QAgent", "agent", 0);
12155 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
12156 "QTBuffer:size", "trace-buffer-size", 0);
12158 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
12159 "Qbtrace:off", "disable-btrace", 0);
12161 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12162 "Qbtrace:bts", "enable-btrace", 0);
12164 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12165 "qXfer:btrace", "read-btrace", 0);
12167 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12168 Z sub-packet has its own set and show commands, but users may
12169 have sets to this variable in their .gdbinit files (or in their
12171 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
12172 &remote_Z_packet_detect
, _("\
12173 Set use of remote protocol `Z' packets"), _("\
12174 Show use of remote protocol `Z' packets "), _("\
12175 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12177 set_remote_protocol_Z_packet_cmd
,
12178 show_remote_protocol_Z_packet_cmd
,
12179 /* FIXME: i18n: Use of remote protocol
12180 `Z' packets is %s. */
12181 &remote_set_cmdlist
, &remote_show_cmdlist
);
12183 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
12184 Manipulate files on the remote system\n\
12185 Transfer files to and from the remote target system."),
12186 &remote_cmdlist
, "remote ",
12187 0 /* allow-unknown */, &cmdlist
);
12189 add_cmd ("put", class_files
, remote_put_command
,
12190 _("Copy a local file to the remote system."),
12193 add_cmd ("get", class_files
, remote_get_command
,
12194 _("Copy a remote file to the local system."),
12197 add_cmd ("delete", class_files
, remote_delete_command
,
12198 _("Delete a remote file."),
12201 remote_exec_file
= xstrdup ("");
12202 add_setshow_string_noescape_cmd ("exec-file", class_files
,
12203 &remote_exec_file
, _("\
12204 Set the remote pathname for \"run\""), _("\
12205 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
12206 &remote_set_cmdlist
, &remote_show_cmdlist
);
12208 add_setshow_boolean_cmd ("range-stepping", class_run
,
12209 &use_range_stepping
, _("\
12210 Enable or disable range stepping."), _("\
12211 Show whether target-assisted range stepping is enabled."), _("\
12212 If on, and the target supports it, when stepping a source line, GDB\n\
12213 tells the target to step the corresponding range of addresses itself instead\n\
12214 of issuing multiple single-steps. This speeds up source level\n\
12215 stepping. If off, GDB always issues single-steps, even if range\n\
12216 stepping is supported by the target. The default is on."),
12217 set_range_stepping
,
12218 show_range_stepping
,
12222 /* Eventually initialize fileio. See fileio.c */
12223 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
12225 /* Take advantage of the fact that the LWP field is not used, to tag
12226 special ptids with it set to != 0. */
12227 magic_null_ptid
= ptid_build (42000, 1, -1);
12228 not_sent_ptid
= ptid_build (42000, 1, -2);
12229 any_thread_ptid
= ptid_build (42000, 1, 0);
12231 target_buf_size
= 2048;
12232 target_buf
= xmalloc (target_buf_size
);