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 #define OPAQUETHREADBYTES 8
267 /* a 64 bit opaque identifier */
268 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
270 /* About this many threadisds fit in a packet. */
272 #define MAXTHREADLISTRESULTS 32
274 /* Description of the remote protocol state for the currently
275 connected target. This is per-target state, and independent of the
276 selected architecture. */
280 /* A buffer to use for incoming packets, and its current size. The
281 buffer is grown dynamically for larger incoming packets.
282 Outgoing packets may also be constructed in this buffer.
283 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
284 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
289 /* True if we're going through initial connection setup (finding out
290 about the remote side's threads, relocating symbols, etc.). */
293 /* If we negotiated packet size explicitly (and thus can bypass
294 heuristics for the largest packet size that will not overflow
295 a buffer in the stub), this will be set to that packet size.
296 Otherwise zero, meaning to use the guessed size. */
297 long explicit_packet_size
;
299 /* remote_wait is normally called when the target is running and
300 waits for a stop reply packet. But sometimes we need to call it
301 when the target is already stopped. We can send a "?" packet
302 and have remote_wait read the response. Or, if we already have
303 the response, we can stash it in BUF and tell remote_wait to
304 skip calling getpkt. This flag is set when BUF contains a
305 stop reply packet and the target is not waiting. */
306 int cached_wait_status
;
308 /* True, if in no ack mode. That is, neither GDB nor the stub will
309 expect acks from each other. The connection is assumed to be
313 /* True if we're connected in extended remote mode. */
316 /* True if the stub reported support for multi-process
318 int multi_process_aware
;
320 /* True if we resumed the target and we're waiting for the target to
321 stop. In the mean time, we can't start another command/query.
322 The remote server wouldn't be ready to process it, so we'd
323 timeout waiting for a reply that would never come and eventually
324 we'd close the connection. This can happen in asynchronous mode
325 because we allow GDB commands while the target is running. */
326 int waiting_for_stop_reply
;
328 /* True if the stub reports support for non-stop mode. */
331 /* The status of the stub support for the various vCont actions. */
332 struct vCont_action_support supports_vCont
;
334 /* True if the stub reports support for conditional tracepoints. */
335 int cond_tracepoints
;
337 /* True if the stub reports support for target-side breakpoint
339 int cond_breakpoints
;
341 /* True if the stub reports support for target-side breakpoint
343 int breakpoint_commands
;
345 /* True if the stub reports support for fast tracepoints. */
346 int fast_tracepoints
;
348 /* True if the stub reports support for static tracepoints. */
349 int static_tracepoints
;
351 /* True if the stub reports support for installing tracepoint while
353 int install_in_trace
;
355 /* True if the stub can continue running a trace while GDB is
357 int disconnected_tracing
;
359 /* True if the stub reports support for enabling and disabling
360 tracepoints while a trace experiment is running. */
361 int enable_disable_tracepoints
;
363 /* True if the stub can collect strings using tracenz bytecode. */
366 /* True if the stub supports qXfer:libraries-svr4:read with a
368 int augmented_libraries_svr4_read
;
370 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
371 responded to that. */
374 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
375 remote_open knows that we don't have a file open when the program
377 struct serial
*remote_desc
;
379 /* These are the threads which we last sent to the remote system. The
380 TID member will be -1 for all or -2 for not sent yet. */
381 ptid_t general_thread
;
382 ptid_t continue_thread
;
384 /* This is the traceframe which we last selected on the remote system.
385 It will be -1 if no traceframe is selected. */
386 int remote_traceframe_number
;
388 char *last_pass_packet
;
390 /* The last QProgramSignals packet sent to the target. We bypass
391 sending a new program signals list down to the target if the new
392 packet is exactly the same as the last we sent. IOW, we only let
393 the target know about program signals list changes. */
394 char *last_program_signals_packet
;
396 enum gdb_signal last_sent_signal
;
400 char *finished_object
;
401 char *finished_annex
;
402 ULONGEST finished_offset
;
404 /* Should we try the 'ThreadInfo' query packet?
406 This variable (NOT available to the user: auto-detect only!)
407 determines whether GDB will use the new, simpler "ThreadInfo"
408 query or the older, more complex syntax for thread queries.
409 This is an auto-detect variable (set to true at each connect,
410 and set to false when the target fails to recognize it). */
411 int use_threadinfo_query
;
412 int use_threadextra_query
;
414 void (*async_client_callback
) (enum inferior_event_type event_type
,
416 void *async_client_context
;
418 /* This is set to the data address of the access causing the target
419 to stop for a watchpoint. */
420 CORE_ADDR remote_watch_data_address
;
422 /* This is non-zero if target stopped for a watchpoint. */
423 int remote_stopped_by_watchpoint_p
;
425 threadref echo_nextthread
;
426 threadref nextthread
;
427 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
430 /* Private data that we'll store in (struct thread_info)->private. */
431 struct private_thread_info
438 free_private_thread_info (struct private_thread_info
*info
)
444 /* Returns true if the multi-process extensions are in effect. */
446 remote_multi_process_p (struct remote_state
*rs
)
448 return rs
->multi_process_aware
;
451 /* This data could be associated with a target, but we do not always
452 have access to the current target when we need it, so for now it is
453 static. This will be fine for as long as only one target is in use
455 static struct remote_state
*remote_state
;
457 static struct remote_state
*
458 get_remote_state_raw (void)
463 /* Allocate a new struct remote_state with xmalloc, initialize it, and
466 static struct remote_state
*
467 new_remote_state (void)
469 struct remote_state
*result
= XCNEW (struct remote_state
);
471 /* The default buffer size is unimportant; it will be expanded
472 whenever a larger buffer is needed. */
473 result
->buf_size
= 400;
474 result
->buf
= xmalloc (result
->buf_size
);
475 result
->remote_traceframe_number
= -1;
476 result
->last_sent_signal
= GDB_SIGNAL_0
;
481 /* Description of the remote protocol for a given architecture. */
485 long offset
; /* Offset into G packet. */
486 long regnum
; /* GDB's internal register number. */
487 LONGEST pnum
; /* Remote protocol register number. */
488 int in_g_packet
; /* Always part of G packet. */
489 /* long size in bytes; == register_size (target_gdbarch (), regnum);
491 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
495 struct remote_arch_state
497 /* Description of the remote protocol registers. */
498 long sizeof_g_packet
;
500 /* Description of the remote protocol registers indexed by REGNUM
501 (making an array gdbarch_num_regs in size). */
502 struct packet_reg
*regs
;
504 /* This is the size (in chars) of the first response to the ``g''
505 packet. It is used as a heuristic when determining the maximum
506 size of memory-read and memory-write packets. A target will
507 typically only reserve a buffer large enough to hold the ``g''
508 packet. The size does not include packet overhead (headers and
510 long actual_register_packet_size
;
512 /* This is the maximum size (in chars) of a non read/write packet.
513 It is also used as a cap on the size of read/write packets. */
514 long remote_packet_size
;
517 /* Utility: generate error from an incoming stub packet. */
519 trace_error (char *buf
)
522 return; /* not an error msg */
525 case '1': /* malformed packet error */
526 if (*++buf
== '0') /* general case: */
527 error (_("remote.c: error in outgoing packet."));
529 error (_("remote.c: error in outgoing packet at field #%ld."),
530 strtol (buf
, NULL
, 16));
532 error (_("Target returns error code '%s'."), buf
);
536 /* Utility: wait for reply from stub, while accepting "O" packets. */
538 remote_get_noisy_reply (char **buf_p
,
541 do /* Loop on reply from remote stub. */
545 QUIT
; /* Allow user to bail out with ^C. */
546 getpkt (buf_p
, sizeof_buf
, 0);
550 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
553 CORE_ADDR from
, to
, org_to
;
555 int adjusted_size
= 0;
556 volatile struct gdb_exception ex
;
558 p
= buf
+ strlen ("qRelocInsn:");
559 pp
= unpack_varlen_hex (p
, &ul
);
561 error (_("invalid qRelocInsn packet: %s"), buf
);
565 unpack_varlen_hex (p
, &ul
);
570 TRY_CATCH (ex
, RETURN_MASK_ALL
)
572 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
576 adjusted_size
= to
- org_to
;
578 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
581 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
583 /* Propagate memory errors silently back to the target.
584 The stub may have limited the range of addresses we
585 can write to, for example. */
590 /* Something unexpectedly bad happened. Be verbose so
591 we can tell what, and propagate the error back to the
592 stub, so it doesn't get stuck waiting for a
594 exception_fprintf (gdb_stderr
, ex
,
595 _("warning: relocating instruction: "));
599 else if (buf
[0] == 'O' && buf
[1] != 'K')
600 remote_console_output (buf
+ 1); /* 'O' message from stub */
602 return buf
; /* Here's the actual reply. */
607 /* Handle for retreving the remote protocol data from gdbarch. */
608 static struct gdbarch_data
*remote_gdbarch_data_handle
;
610 static struct remote_arch_state
*
611 get_remote_arch_state (void)
613 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
616 /* Fetch the global remote target state. */
618 static struct remote_state
*
619 get_remote_state (void)
621 /* Make sure that the remote architecture state has been
622 initialized, because doing so might reallocate rs->buf. Any
623 function which calls getpkt also needs to be mindful of changes
624 to rs->buf, but this call limits the number of places which run
626 get_remote_arch_state ();
628 return get_remote_state_raw ();
632 compare_pnums (const void *lhs_
, const void *rhs_
)
634 const struct packet_reg
* const *lhs
= lhs_
;
635 const struct packet_reg
* const *rhs
= rhs_
;
637 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
639 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
646 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
648 int regnum
, num_remote_regs
, offset
;
649 struct packet_reg
**remote_regs
;
651 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
653 struct packet_reg
*r
= ®s
[regnum
];
655 if (register_size (gdbarch
, regnum
) == 0)
656 /* Do not try to fetch zero-sized (placeholder) registers. */
659 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
664 /* Define the g/G packet format as the contents of each register
665 with a remote protocol number, in order of ascending protocol
668 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
669 * sizeof (struct packet_reg
*));
670 for (num_remote_regs
= 0, regnum
= 0;
671 regnum
< gdbarch_num_regs (gdbarch
);
673 if (regs
[regnum
].pnum
!= -1)
674 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
676 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
679 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
681 remote_regs
[regnum
]->in_g_packet
= 1;
682 remote_regs
[regnum
]->offset
= offset
;
683 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
689 /* Given the architecture described by GDBARCH, return the remote
690 protocol register's number and the register's offset in the g/G
691 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
692 If the target does not have a mapping for REGNUM, return false,
693 otherwise, return true. */
696 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
697 int *pnum
, int *poffset
)
700 struct packet_reg
*regs
;
701 struct cleanup
*old_chain
;
703 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
705 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
706 old_chain
= make_cleanup (xfree
, regs
);
708 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
710 *pnum
= regs
[regnum
].pnum
;
711 *poffset
= regs
[regnum
].offset
;
713 do_cleanups (old_chain
);
719 init_remote_state (struct gdbarch
*gdbarch
)
721 struct remote_state
*rs
= get_remote_state_raw ();
722 struct remote_arch_state
*rsa
;
724 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
726 /* Use the architecture to build a regnum<->pnum table, which will be
727 1:1 unless a feature set specifies otherwise. */
728 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
729 gdbarch_num_regs (gdbarch
),
732 /* Record the maximum possible size of the g packet - it may turn out
734 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
736 /* Default maximum number of characters in a packet body. Many
737 remote stubs have a hardwired buffer size of 400 bytes
738 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
739 as the maximum packet-size to ensure that the packet and an extra
740 NUL character can always fit in the buffer. This stops GDB
741 trashing stubs that try to squeeze an extra NUL into what is
742 already a full buffer (As of 1999-12-04 that was most stubs). */
743 rsa
->remote_packet_size
= 400 - 1;
745 /* This one is filled in when a ``g'' packet is received. */
746 rsa
->actual_register_packet_size
= 0;
748 /* Should rsa->sizeof_g_packet needs more space than the
749 default, adjust the size accordingly. Remember that each byte is
750 encoded as two characters. 32 is the overhead for the packet
751 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
752 (``$NN:G...#NN'') is a better guess, the below has been padded a
754 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
755 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
757 /* Make sure that the packet buffer is plenty big enough for
758 this architecture. */
759 if (rs
->buf_size
< rsa
->remote_packet_size
)
761 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
762 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
768 /* Return the current allowed size of a remote packet. This is
769 inferred from the current architecture, and should be used to
770 limit the length of outgoing packets. */
772 get_remote_packet_size (void)
774 struct remote_state
*rs
= get_remote_state ();
775 struct remote_arch_state
*rsa
= get_remote_arch_state ();
777 if (rs
->explicit_packet_size
)
778 return rs
->explicit_packet_size
;
780 return rsa
->remote_packet_size
;
783 static struct packet_reg
*
784 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
786 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
790 struct packet_reg
*r
= &rsa
->regs
[regnum
];
792 gdb_assert (r
->regnum
== regnum
);
797 static struct packet_reg
*
798 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
802 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
804 struct packet_reg
*r
= &rsa
->regs
[i
];
812 static struct target_ops remote_ops
;
814 static struct target_ops extended_remote_ops
;
816 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
817 ``forever'' still use the normal timeout mechanism. This is
818 currently used by the ASYNC code to guarentee that target reads
819 during the initial connect always time-out. Once getpkt has been
820 modified to return a timeout indication and, in turn
821 remote_wait()/wait_for_inferior() have gained a timeout parameter
823 static int wait_forever_enabled_p
= 1;
825 /* Allow the user to specify what sequence to send to the remote
826 when he requests a program interruption: Although ^C is usually
827 what remote systems expect (this is the default, here), it is
828 sometimes preferable to send a break. On other systems such
829 as the Linux kernel, a break followed by g, which is Magic SysRq g
830 is required in order to interrupt the execution. */
831 const char interrupt_sequence_control_c
[] = "Ctrl-C";
832 const char interrupt_sequence_break
[] = "BREAK";
833 const char interrupt_sequence_break_g
[] = "BREAK-g";
834 static const char *const interrupt_sequence_modes
[] =
836 interrupt_sequence_control_c
,
837 interrupt_sequence_break
,
838 interrupt_sequence_break_g
,
841 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
844 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
845 struct cmd_list_element
*c
,
848 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
849 fprintf_filtered (file
,
850 _("Send the ASCII ETX character (Ctrl-c) "
851 "to the remote target to interrupt the "
852 "execution of the program.\n"));
853 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
854 fprintf_filtered (file
,
855 _("send a break signal to the remote target "
856 "to interrupt the execution of the program.\n"));
857 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
858 fprintf_filtered (file
,
859 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
860 "the remote target to interrupt the execution "
861 "of Linux kernel.\n"));
863 internal_error (__FILE__
, __LINE__
,
864 _("Invalid value for interrupt_sequence_mode: %s."),
865 interrupt_sequence_mode
);
868 /* This boolean variable specifies whether interrupt_sequence is sent
869 to the remote target when gdb connects to it.
870 This is mostly needed when you debug the Linux kernel: The Linux kernel
871 expects BREAK g which is Magic SysRq g for connecting gdb. */
872 static int interrupt_on_connect
= 0;
874 /* This variable is used to implement the "set/show remotebreak" commands.
875 Since these commands are now deprecated in favor of "set/show remote
876 interrupt-sequence", it no longer has any effect on the code. */
877 static int remote_break
;
880 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
883 interrupt_sequence_mode
= interrupt_sequence_break
;
885 interrupt_sequence_mode
= interrupt_sequence_control_c
;
889 show_remotebreak (struct ui_file
*file
, int from_tty
,
890 struct cmd_list_element
*c
,
895 /* This variable sets the number of bits in an address that are to be
896 sent in a memory ("M" or "m") packet. Normally, after stripping
897 leading zeros, the entire address would be sent. This variable
898 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
899 initial implementation of remote.c restricted the address sent in
900 memory packets to ``host::sizeof long'' bytes - (typically 32
901 bits). Consequently, for 64 bit targets, the upper 32 bits of an
902 address was never sent. Since fixing this bug may cause a break in
903 some remote targets this variable is principly provided to
904 facilitate backward compatibility. */
906 static unsigned int remote_address_size
;
908 /* Temporary to track who currently owns the terminal. See
909 remote_terminal_* for more details. */
911 static int remote_async_terminal_ours_p
;
913 /* The executable file to use for "run" on the remote side. */
915 static char *remote_exec_file
= "";
918 /* User configurable variables for the number of characters in a
919 memory read/write packet. MIN (rsa->remote_packet_size,
920 rsa->sizeof_g_packet) is the default. Some targets need smaller
921 values (fifo overruns, et.al.) and some users need larger values
922 (speed up transfers). The variables ``preferred_*'' (the user
923 request), ``current_*'' (what was actually set) and ``forced_*''
924 (Positive - a soft limit, negative - a hard limit). */
926 struct memory_packet_config
933 /* Compute the current size of a read/write packet. Since this makes
934 use of ``actual_register_packet_size'' the computation is dynamic. */
937 get_memory_packet_size (struct memory_packet_config
*config
)
939 struct remote_state
*rs
= get_remote_state ();
940 struct remote_arch_state
*rsa
= get_remote_arch_state ();
942 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
943 law?) that some hosts don't cope very well with large alloca()
944 calls. Eventually the alloca() code will be replaced by calls to
945 xmalloc() and make_cleanups() allowing this restriction to either
946 be lifted or removed. */
947 #ifndef MAX_REMOTE_PACKET_SIZE
948 #define MAX_REMOTE_PACKET_SIZE 16384
950 /* NOTE: 20 ensures we can write at least one byte. */
951 #ifndef MIN_REMOTE_PACKET_SIZE
952 #define MIN_REMOTE_PACKET_SIZE 20
957 if (config
->size
<= 0)
958 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
960 what_they_get
= config
->size
;
964 what_they_get
= get_remote_packet_size ();
965 /* Limit the packet to the size specified by the user. */
967 && what_they_get
> config
->size
)
968 what_they_get
= config
->size
;
970 /* Limit it to the size of the targets ``g'' response unless we have
971 permission from the stub to use a larger packet size. */
972 if (rs
->explicit_packet_size
== 0
973 && rsa
->actual_register_packet_size
> 0
974 && what_they_get
> rsa
->actual_register_packet_size
)
975 what_they_get
= rsa
->actual_register_packet_size
;
977 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
978 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
979 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
980 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
982 /* Make sure there is room in the global buffer for this packet
983 (including its trailing NUL byte). */
984 if (rs
->buf_size
< what_they_get
+ 1)
986 rs
->buf_size
= 2 * what_they_get
;
987 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
990 return what_they_get
;
993 /* Update the size of a read/write packet. If they user wants
994 something really big then do a sanity check. */
997 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
999 int fixed_p
= config
->fixed_p
;
1000 long size
= config
->size
;
1003 error (_("Argument required (integer, `fixed' or `limited')."));
1004 else if (strcmp (args
, "hard") == 0
1005 || strcmp (args
, "fixed") == 0)
1007 else if (strcmp (args
, "soft") == 0
1008 || strcmp (args
, "limit") == 0)
1014 size
= strtoul (args
, &end
, 0);
1016 error (_("Invalid %s (bad syntax)."), config
->name
);
1018 /* Instead of explicitly capping the size of a packet to
1019 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
1020 instead allowed to set the size to something arbitrarily
1022 if (size
> MAX_REMOTE_PACKET_SIZE
)
1023 error (_("Invalid %s (too large)."), config
->name
);
1027 if (fixed_p
&& !config
->fixed_p
)
1029 if (! query (_("The target may not be able to correctly handle a %s\n"
1030 "of %ld bytes. Change the packet size? "),
1031 config
->name
, size
))
1032 error (_("Packet size not changed."));
1034 /* Update the config. */
1035 config
->fixed_p
= fixed_p
;
1036 config
->size
= size
;
1040 show_memory_packet_size (struct memory_packet_config
*config
)
1042 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1043 if (config
->fixed_p
)
1044 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1045 get_memory_packet_size (config
));
1047 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1048 get_memory_packet_size (config
));
1051 static struct memory_packet_config memory_write_packet_config
=
1053 "memory-write-packet-size",
1057 set_memory_write_packet_size (char *args
, int from_tty
)
1059 set_memory_packet_size (args
, &memory_write_packet_config
);
1063 show_memory_write_packet_size (char *args
, int from_tty
)
1065 show_memory_packet_size (&memory_write_packet_config
);
1069 get_memory_write_packet_size (void)
1071 return get_memory_packet_size (&memory_write_packet_config
);
1074 static struct memory_packet_config memory_read_packet_config
=
1076 "memory-read-packet-size",
1080 set_memory_read_packet_size (char *args
, int from_tty
)
1082 set_memory_packet_size (args
, &memory_read_packet_config
);
1086 show_memory_read_packet_size (char *args
, int from_tty
)
1088 show_memory_packet_size (&memory_read_packet_config
);
1092 get_memory_read_packet_size (void)
1094 long size
= get_memory_packet_size (&memory_read_packet_config
);
1096 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1097 extra buffer size argument before the memory read size can be
1098 increased beyond this. */
1099 if (size
> get_remote_packet_size ())
1100 size
= get_remote_packet_size ();
1105 /* Generic configuration support for packets the stub optionally
1106 supports. Allows the user to specify the use of the packet as well
1107 as allowing GDB to auto-detect support in the remote stub. */
1111 PACKET_SUPPORT_UNKNOWN
= 0,
1116 struct packet_config
1120 enum auto_boolean detect
;
1121 enum packet_support support
;
1124 /* Analyze a packet's return value and update the packet config
1135 update_packet_config (struct packet_config
*config
)
1137 switch (config
->detect
)
1139 case AUTO_BOOLEAN_TRUE
:
1140 config
->support
= PACKET_ENABLE
;
1142 case AUTO_BOOLEAN_FALSE
:
1143 config
->support
= PACKET_DISABLE
;
1145 case AUTO_BOOLEAN_AUTO
:
1146 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1152 show_packet_config_cmd (struct packet_config
*config
)
1154 char *support
= "internal-error";
1156 switch (config
->support
)
1159 support
= "enabled";
1161 case PACKET_DISABLE
:
1162 support
= "disabled";
1164 case PACKET_SUPPORT_UNKNOWN
:
1165 support
= "unknown";
1168 switch (config
->detect
)
1170 case AUTO_BOOLEAN_AUTO
:
1171 printf_filtered (_("Support for the `%s' packet "
1172 "is auto-detected, currently %s.\n"),
1173 config
->name
, support
);
1175 case AUTO_BOOLEAN_TRUE
:
1176 case AUTO_BOOLEAN_FALSE
:
1177 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1178 config
->name
, support
);
1184 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1185 const char *title
, int legacy
)
1191 config
->name
= name
;
1192 config
->title
= title
;
1193 config
->detect
= AUTO_BOOLEAN_AUTO
;
1194 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1195 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1197 show_doc
= xstrprintf ("Show current use of remote "
1198 "protocol `%s' (%s) packet",
1200 /* set/show TITLE-packet {auto,on,off} */
1201 cmd_name
= xstrprintf ("%s-packet", title
);
1202 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1203 &config
->detect
, set_doc
,
1204 show_doc
, NULL
, /* help_doc */
1205 set_remote_protocol_packet_cmd
,
1206 show_remote_protocol_packet_cmd
,
1207 &remote_set_cmdlist
, &remote_show_cmdlist
);
1208 /* The command code copies the documentation strings. */
1211 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1216 legacy_name
= xstrprintf ("%s-packet", name
);
1217 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1218 &remote_set_cmdlist
);
1219 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1220 &remote_show_cmdlist
);
1224 static enum packet_result
1225 packet_check_result (const char *buf
)
1229 /* The stub recognized the packet request. Check that the
1230 operation succeeded. */
1232 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1234 /* "Enn" - definitly an error. */
1235 return PACKET_ERROR
;
1237 /* Always treat "E." as an error. This will be used for
1238 more verbose error messages, such as E.memtypes. */
1239 if (buf
[0] == 'E' && buf
[1] == '.')
1240 return PACKET_ERROR
;
1242 /* The packet may or may not be OK. Just assume it is. */
1246 /* The stub does not support the packet. */
1247 return PACKET_UNKNOWN
;
1250 static enum packet_result
1251 packet_ok (const char *buf
, struct packet_config
*config
)
1253 enum packet_result result
;
1255 result
= packet_check_result (buf
);
1260 /* The stub recognized the packet request. */
1261 switch (config
->support
)
1263 case PACKET_SUPPORT_UNKNOWN
:
1265 fprintf_unfiltered (gdb_stdlog
,
1266 "Packet %s (%s) is supported\n",
1267 config
->name
, config
->title
);
1268 config
->support
= PACKET_ENABLE
;
1270 case PACKET_DISABLE
:
1271 internal_error (__FILE__
, __LINE__
,
1272 _("packet_ok: attempt to use a disabled packet"));
1278 case PACKET_UNKNOWN
:
1279 /* The stub does not support the packet. */
1280 switch (config
->support
)
1283 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1284 /* If the stub previously indicated that the packet was
1285 supported then there is a protocol error.. */
1286 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1287 config
->name
, config
->title
);
1289 /* The user set it wrong. */
1290 error (_("Enabled packet %s (%s) not recognized by stub"),
1291 config
->name
, config
->title
);
1293 case PACKET_SUPPORT_UNKNOWN
:
1295 fprintf_unfiltered (gdb_stdlog
,
1296 "Packet %s (%s) is NOT supported\n",
1297 config
->name
, config
->title
);
1298 config
->support
= PACKET_DISABLE
;
1300 case PACKET_DISABLE
:
1322 PACKET_vFile_pwrite
,
1324 PACKET_vFile_unlink
,
1325 PACKET_vFile_readlink
,
1327 PACKET_qXfer_features
,
1328 PACKET_qXfer_libraries
,
1329 PACKET_qXfer_libraries_svr4
,
1330 PACKET_qXfer_memory_map
,
1331 PACKET_qXfer_spu_read
,
1332 PACKET_qXfer_spu_write
,
1333 PACKET_qXfer_osdata
,
1334 PACKET_qXfer_threads
,
1335 PACKET_qXfer_statictrace_read
,
1336 PACKET_qXfer_traceframe_info
,
1342 PACKET_QPassSignals
,
1343 PACKET_QProgramSignals
,
1344 PACKET_qSearch_memory
,
1347 PACKET_QStartNoAckMode
,
1349 PACKET_qXfer_siginfo_read
,
1350 PACKET_qXfer_siginfo_write
,
1352 PACKET_ConditionalTracepoints
,
1353 PACKET_ConditionalBreakpoints
,
1354 PACKET_BreakpointCommands
,
1355 PACKET_FastTracepoints
,
1356 PACKET_StaticTracepoints
,
1357 PACKET_InstallInTrace
,
1360 PACKET_TracepointSource
,
1363 PACKET_QDisableRandomization
,
1365 PACKET_QTBuffer_size
,
1368 PACKET_qXfer_btrace
,
1372 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1375 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1376 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 update_packet_config (packet
);
1390 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1395 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1396 struct cmd_list_element
*c
,
1399 struct packet_config
*packet
;
1401 for (packet
= remote_protocol_packets
;
1402 packet
< &remote_protocol_packets
[PACKET_MAX
];
1405 if (&packet
->detect
== c
->var
)
1407 show_packet_config_cmd (packet
);
1411 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1415 /* Should we try one of the 'Z' requests? */
1419 Z_PACKET_SOFTWARE_BP
,
1420 Z_PACKET_HARDWARE_BP
,
1427 /* For compatibility with older distributions. Provide a ``set remote
1428 Z-packet ...'' command that updates all the Z packet types. */
1430 static enum auto_boolean remote_Z_packet_detect
;
1433 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1434 struct cmd_list_element
*c
)
1438 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1440 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1441 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1446 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1447 struct cmd_list_element
*c
,
1452 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1454 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1458 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1459 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1460 static struct async_signal_handler
*async_sigint_remote_token
;
1463 /* Asynchronous signal handle registered as event loop source for
1464 when we have pending events ready to be passed to the core. */
1466 static struct async_event_handler
*remote_async_inferior_event_token
;
1470 static ptid_t magic_null_ptid
;
1471 static ptid_t not_sent_ptid
;
1472 static ptid_t any_thread_ptid
;
1474 /* Find out if the stub attached to PID (and hence GDB should offer to
1475 detach instead of killing it when bailing out). */
1478 remote_query_attached (int pid
)
1480 struct remote_state
*rs
= get_remote_state ();
1481 size_t size
= get_remote_packet_size ();
1483 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1486 if (remote_multi_process_p (rs
))
1487 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1489 xsnprintf (rs
->buf
, size
, "qAttached");
1492 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1494 switch (packet_ok (rs
->buf
,
1495 &remote_protocol_packets
[PACKET_qAttached
]))
1498 if (strcmp (rs
->buf
, "1") == 0)
1502 warning (_("Remote failure reply: %s"), rs
->buf
);
1504 case PACKET_UNKNOWN
:
1511 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1512 has been invented by GDB, instead of reported by the target. Since
1513 we can be connected to a remote system before before knowing about
1514 any inferior, mark the target with execution when we find the first
1515 inferior. If ATTACHED is 1, then we had just attached to this
1516 inferior. If it is 0, then we just created this inferior. If it
1517 is -1, then try querying the remote stub to find out if it had
1518 attached to the inferior or not. */
1520 static struct inferior
*
1521 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1523 struct inferior
*inf
;
1525 /* Check whether this process we're learning about is to be
1526 considered attached, or if is to be considered to have been
1527 spawned by the stub. */
1529 attached
= remote_query_attached (pid
);
1531 if (gdbarch_has_global_solist (target_gdbarch ()))
1533 /* If the target shares code across all inferiors, then every
1534 attach adds a new inferior. */
1535 inf
= add_inferior (pid
);
1537 /* ... and every inferior is bound to the same program space.
1538 However, each inferior may still have its own address
1540 inf
->aspace
= maybe_new_address_space ();
1541 inf
->pspace
= current_program_space
;
1545 /* In the traditional debugging scenario, there's a 1-1 match
1546 between program/address spaces. We simply bind the inferior
1547 to the program space's address space. */
1548 inf
= current_inferior ();
1549 inferior_appeared (inf
, pid
);
1552 inf
->attach_flag
= attached
;
1553 inf
->fake_pid_p
= fake_pid_p
;
1558 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1559 according to RUNNING. */
1562 remote_add_thread (ptid_t ptid
, int running
)
1566 set_executing (ptid
, running
);
1567 set_running (ptid
, running
);
1570 /* Come here when we learn about a thread id from the remote target.
1571 It may be the first time we hear about such thread, so take the
1572 opportunity to add it to GDB's thread list. In case this is the
1573 first time we're noticing its corresponding inferior, add it to
1574 GDB's inferior list as well. */
1577 remote_notice_new_inferior (ptid_t currthread
, int running
)
1579 /* If this is a new thread, add it to GDB's thread list.
1580 If we leave it up to WFI to do this, bad things will happen. */
1582 if (in_thread_list (currthread
) && is_exited (currthread
))
1584 /* We're seeing an event on a thread id we knew had exited.
1585 This has to be a new thread reusing the old id. Add it. */
1586 remote_add_thread (currthread
, running
);
1590 if (!in_thread_list (currthread
))
1592 struct inferior
*inf
= NULL
;
1593 int pid
= ptid_get_pid (currthread
);
1595 if (ptid_is_pid (inferior_ptid
)
1596 && pid
== ptid_get_pid (inferior_ptid
))
1598 /* inferior_ptid has no thread member yet. This can happen
1599 with the vAttach -> remote_wait,"TAAthread:" path if the
1600 stub doesn't support qC. This is the first stop reported
1601 after an attach, so this is the main thread. Update the
1602 ptid in the thread list. */
1603 if (in_thread_list (pid_to_ptid (pid
)))
1604 thread_change_ptid (inferior_ptid
, currthread
);
1607 remote_add_thread (currthread
, running
);
1608 inferior_ptid
= currthread
;
1613 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1615 /* inferior_ptid is not set yet. This can happen with the
1616 vRun -> remote_wait,"TAAthread:" path if the stub
1617 doesn't support qC. This is the first stop reported
1618 after an attach, so this is the main thread. Update the
1619 ptid in the thread list. */
1620 thread_change_ptid (inferior_ptid
, currthread
);
1624 /* When connecting to a target remote, or to a target
1625 extended-remote which already was debugging an inferior, we
1626 may not know about it yet. Add it before adding its child
1627 thread, so notifications are emitted in a sensible order. */
1628 if (!in_inferior_list (ptid_get_pid (currthread
)))
1630 struct remote_state
*rs
= get_remote_state ();
1631 int fake_pid_p
= !remote_multi_process_p (rs
);
1633 inf
= remote_add_inferior (fake_pid_p
,
1634 ptid_get_pid (currthread
), -1);
1637 /* This is really a new thread. Add it. */
1638 remote_add_thread (currthread
, running
);
1640 /* If we found a new inferior, let the common code do whatever
1641 it needs to with it (e.g., read shared libraries, insert
1644 notice_new_inferior (currthread
, running
, 0);
1648 /* Return the private thread data, creating it if necessary. */
1650 static struct private_thread_info
*
1651 demand_private_info (ptid_t ptid
)
1653 struct thread_info
*info
= find_thread_ptid (ptid
);
1659 info
->private = xmalloc (sizeof (*(info
->private)));
1660 info
->private_dtor
= free_private_thread_info
;
1661 info
->private->core
= -1;
1662 info
->private->extra
= 0;
1665 return info
->private;
1668 /* Call this function as a result of
1669 1) A halt indication (T packet) containing a thread id
1670 2) A direct query of currthread
1671 3) Successful execution of set thread */
1674 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1676 rs
->general_thread
= currthread
;
1679 /* If 'QPassSignals' is supported, tell the remote stub what signals
1680 it can simply pass through to the inferior without reporting. */
1683 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1685 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1687 char *pass_packet
, *p
;
1689 struct remote_state
*rs
= get_remote_state ();
1691 gdb_assert (numsigs
< 256);
1692 for (i
= 0; i
< numsigs
; i
++)
1694 if (pass_signals
[i
])
1697 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1698 strcpy (pass_packet
, "QPassSignals:");
1699 p
= pass_packet
+ strlen (pass_packet
);
1700 for (i
= 0; i
< numsigs
; i
++)
1702 if (pass_signals
[i
])
1705 *p
++ = tohex (i
>> 4);
1706 *p
++ = tohex (i
& 15);
1715 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1717 char *buf
= rs
->buf
;
1719 putpkt (pass_packet
);
1720 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1721 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1722 if (rs
->last_pass_packet
)
1723 xfree (rs
->last_pass_packet
);
1724 rs
->last_pass_packet
= pass_packet
;
1727 xfree (pass_packet
);
1731 /* If 'QProgramSignals' is supported, tell the remote stub what
1732 signals it should pass through to the inferior when detaching. */
1735 remote_program_signals (int numsigs
, unsigned char *signals
)
1737 if (remote_protocol_packets
[PACKET_QProgramSignals
].support
!= PACKET_DISABLE
)
1741 struct remote_state
*rs
= get_remote_state ();
1743 gdb_assert (numsigs
< 256);
1744 for (i
= 0; i
< numsigs
; i
++)
1749 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1750 strcpy (packet
, "QProgramSignals:");
1751 p
= packet
+ strlen (packet
);
1752 for (i
= 0; i
< numsigs
; i
++)
1754 if (signal_pass_state (i
))
1757 *p
++ = tohex (i
>> 4);
1758 *p
++ = tohex (i
& 15);
1767 if (!rs
->last_program_signals_packet
1768 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1770 char *buf
= rs
->buf
;
1773 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1774 packet_ok (buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1775 xfree (rs
->last_program_signals_packet
);
1776 rs
->last_program_signals_packet
= packet
;
1783 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1784 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1785 thread. If GEN is set, set the general thread, if not, then set
1786 the step/continue thread. */
1788 set_thread (struct ptid ptid
, int gen
)
1790 struct remote_state
*rs
= get_remote_state ();
1791 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1792 char *buf
= rs
->buf
;
1793 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1795 if (ptid_equal (state
, ptid
))
1799 *buf
++ = gen
? 'g' : 'c';
1800 if (ptid_equal (ptid
, magic_null_ptid
))
1801 xsnprintf (buf
, endbuf
- buf
, "0");
1802 else if (ptid_equal (ptid
, any_thread_ptid
))
1803 xsnprintf (buf
, endbuf
- buf
, "0");
1804 else if (ptid_equal (ptid
, minus_one_ptid
))
1805 xsnprintf (buf
, endbuf
- buf
, "-1");
1807 write_ptid (buf
, endbuf
, ptid
);
1809 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1811 rs
->general_thread
= ptid
;
1813 rs
->continue_thread
= ptid
;
1817 set_general_thread (struct ptid ptid
)
1819 set_thread (ptid
, 1);
1823 set_continue_thread (struct ptid ptid
)
1825 set_thread (ptid
, 0);
1828 /* Change the remote current process. Which thread within the process
1829 ends up selected isn't important, as long as it is the same process
1830 as what INFERIOR_PTID points to.
1832 This comes from that fact that there is no explicit notion of
1833 "selected process" in the protocol. The selected process for
1834 general operations is the process the selected general thread
1838 set_general_process (void)
1840 struct remote_state
*rs
= get_remote_state ();
1842 /* If the remote can't handle multiple processes, don't bother. */
1843 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1846 /* We only need to change the remote current thread if it's pointing
1847 at some other process. */
1848 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1849 set_general_thread (inferior_ptid
);
1853 /* Return nonzero if the thread PTID is still alive on the remote
1857 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1859 struct remote_state
*rs
= get_remote_state ();
1862 if (ptid_equal (ptid
, magic_null_ptid
))
1863 /* The main thread is always alive. */
1866 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1867 /* The main thread is always alive. This can happen after a
1868 vAttach, if the remote side doesn't support
1873 endp
= rs
->buf
+ get_remote_packet_size ();
1876 write_ptid (p
, endp
, ptid
);
1879 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1880 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1883 /* About these extended threadlist and threadinfo packets. They are
1884 variable length packets but, the fields within them are often fixed
1885 length. They are redundent enough to send over UDP as is the
1886 remote protocol in general. There is a matching unit test module
1889 /* WARNING: This threadref data structure comes from the remote O.S.,
1890 libstub protocol encoding, and remote.c. It is not particularly
1893 /* Right now, the internal structure is int. We want it to be bigger.
1894 Plan to fix this. */
1896 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1898 /* gdb_ext_thread_info is an internal GDB data structure which is
1899 equivalent to the reply of the remote threadinfo packet. */
1901 struct gdb_ext_thread_info
1903 threadref threadid
; /* External form of thread reference. */
1904 int active
; /* Has state interesting to GDB?
1906 char display
[256]; /* Brief state display, name,
1907 blocked/suspended. */
1908 char shortname
[32]; /* To be used to name threads. */
1909 char more_display
[256]; /* Long info, statistics, queue depth,
1913 /* The volume of remote transfers can be limited by submitting
1914 a mask containing bits specifying the desired information.
1915 Use a union of these values as the 'selection' parameter to
1916 get_thread_info. FIXME: Make these TAG names more thread specific. */
1918 #define TAG_THREADID 1
1919 #define TAG_EXISTS 2
1920 #define TAG_DISPLAY 4
1921 #define TAG_THREADNAME 8
1922 #define TAG_MOREDISPLAY 16
1924 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1926 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1928 static char *unpack_nibble (char *buf
, int *val
);
1930 static char *pack_nibble (char *buf
, int nibble
);
1932 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1934 static char *unpack_byte (char *buf
, int *value
);
1936 static char *pack_int (char *buf
, int value
);
1938 static char *unpack_int (char *buf
, int *value
);
1940 static char *unpack_string (char *src
, char *dest
, int length
);
1942 static char *pack_threadid (char *pkt
, threadref
*id
);
1944 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1946 void int_to_threadref (threadref
*id
, int value
);
1948 static int threadref_to_int (threadref
*ref
);
1950 static void copy_threadref (threadref
*dest
, threadref
*src
);
1952 static int threadmatch (threadref
*dest
, threadref
*src
);
1954 static char *pack_threadinfo_request (char *pkt
, int mode
,
1957 static int remote_unpack_thread_info_response (char *pkt
,
1958 threadref
*expectedref
,
1959 struct gdb_ext_thread_info
1963 static int remote_get_threadinfo (threadref
*threadid
,
1964 int fieldset
, /*TAG mask */
1965 struct gdb_ext_thread_info
*info
);
1967 static char *pack_threadlist_request (char *pkt
, int startflag
,
1969 threadref
*nextthread
);
1971 static int parse_threadlist_response (char *pkt
,
1973 threadref
*original_echo
,
1974 threadref
*resultlist
,
1977 static int remote_get_threadlist (int startflag
,
1978 threadref
*nextthread
,
1982 threadref
*threadlist
);
1984 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1986 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1987 void *context
, int looplimit
);
1989 static int remote_newthread_step (threadref
*ref
, void *context
);
1992 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1993 buffer we're allowed to write to. Returns
1994 BUF+CHARACTERS_WRITTEN. */
1997 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2000 struct remote_state
*rs
= get_remote_state ();
2002 if (remote_multi_process_p (rs
))
2004 pid
= ptid_get_pid (ptid
);
2006 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2008 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2010 tid
= ptid_get_tid (ptid
);
2012 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2014 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2019 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2020 passed the last parsed char. Returns null_ptid on error. */
2023 read_ptid (char *buf
, char **obuf
)
2027 ULONGEST pid
= 0, tid
= 0;
2031 /* Multi-process ptid. */
2032 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2034 error (_("invalid remote ptid: %s"), p
);
2037 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2040 return ptid_build (pid
, 0, tid
);
2043 /* No multi-process. Just a tid. */
2044 pp
= unpack_varlen_hex (p
, &tid
);
2046 /* Since the stub is not sending a process id, then default to
2047 what's in inferior_ptid, unless it's null at this point. If so,
2048 then since there's no way to know the pid of the reported
2049 threads, use the magic number. */
2050 if (ptid_equal (inferior_ptid
, null_ptid
))
2051 pid
= ptid_get_pid (magic_null_ptid
);
2053 pid
= ptid_get_pid (inferior_ptid
);
2057 return ptid_build (pid
, 0, tid
);
2060 /* Encode 64 bits in 16 chars of hex. */
2062 static const char hexchars
[] = "0123456789abcdef";
2065 ishex (int ch
, int *val
)
2067 if ((ch
>= 'a') && (ch
<= 'f'))
2069 *val
= ch
- 'a' + 10;
2072 if ((ch
>= 'A') && (ch
<= 'F'))
2074 *val
= ch
- 'A' + 10;
2077 if ((ch
>= '0') && (ch
<= '9'))
2088 if (ch
>= 'a' && ch
<= 'f')
2089 return ch
- 'a' + 10;
2090 if (ch
>= '0' && ch
<= '9')
2092 if (ch
>= 'A' && ch
<= 'F')
2093 return ch
- 'A' + 10;
2098 stub_unpack_int (char *buff
, int fieldlength
)
2105 nibble
= stubhex (*buff
++);
2109 retval
= retval
<< 4;
2115 unpack_varlen_hex (char *buff
, /* packet to parse */
2119 ULONGEST retval
= 0;
2121 while (ishex (*buff
, &nibble
))
2124 retval
= retval
<< 4;
2125 retval
|= nibble
& 0x0f;
2132 unpack_nibble (char *buf
, int *val
)
2134 *val
= fromhex (*buf
++);
2139 pack_nibble (char *buf
, int nibble
)
2141 *buf
++ = hexchars
[(nibble
& 0x0f)];
2146 pack_hex_byte (char *pkt
, int byte
)
2148 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2149 *pkt
++ = hexchars
[(byte
& 0xf)];
2154 unpack_byte (char *buf
, int *value
)
2156 *value
= stub_unpack_int (buf
, 2);
2161 pack_int (char *buf
, int value
)
2163 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2164 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2165 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2166 buf
= pack_hex_byte (buf
, (value
& 0xff));
2171 unpack_int (char *buf
, int *value
)
2173 *value
= stub_unpack_int (buf
, 8);
2177 #if 0 /* Currently unused, uncomment when needed. */
2178 static char *pack_string (char *pkt
, char *string
);
2181 pack_string (char *pkt
, char *string
)
2186 len
= strlen (string
);
2188 len
= 200; /* Bigger than most GDB packets, junk??? */
2189 pkt
= pack_hex_byte (pkt
, len
);
2193 if ((ch
== '\0') || (ch
== '#'))
2194 ch
= '*'; /* Protect encapsulation. */
2199 #endif /* 0 (unused) */
2202 unpack_string (char *src
, char *dest
, int length
)
2211 pack_threadid (char *pkt
, threadref
*id
)
2214 unsigned char *altid
;
2216 altid
= (unsigned char *) id
;
2217 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2219 pkt
= pack_hex_byte (pkt
, *altid
++);
2225 unpack_threadid (char *inbuf
, threadref
*id
)
2228 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2231 altref
= (char *) id
;
2233 while (inbuf
< limit
)
2235 x
= stubhex (*inbuf
++);
2236 y
= stubhex (*inbuf
++);
2237 *altref
++ = (x
<< 4) | y
;
2242 /* Externally, threadrefs are 64 bits but internally, they are still
2243 ints. This is due to a mismatch of specifications. We would like
2244 to use 64bit thread references internally. This is an adapter
2248 int_to_threadref (threadref
*id
, int value
)
2250 unsigned char *scan
;
2252 scan
= (unsigned char *) id
;
2258 *scan
++ = (value
>> 24) & 0xff;
2259 *scan
++ = (value
>> 16) & 0xff;
2260 *scan
++ = (value
>> 8) & 0xff;
2261 *scan
++ = (value
& 0xff);
2265 threadref_to_int (threadref
*ref
)
2268 unsigned char *scan
;
2274 value
= (value
<< 8) | ((*scan
++) & 0xff);
2279 copy_threadref (threadref
*dest
, threadref
*src
)
2282 unsigned char *csrc
, *cdest
;
2284 csrc
= (unsigned char *) src
;
2285 cdest
= (unsigned char *) dest
;
2292 threadmatch (threadref
*dest
, threadref
*src
)
2294 /* Things are broken right now, so just assume we got a match. */
2296 unsigned char *srcp
, *destp
;
2298 srcp
= (char *) src
;
2299 destp
= (char *) dest
;
2303 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2310 threadid:1, # always request threadid
2317 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2320 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2322 *pkt
++ = 'q'; /* Info Query */
2323 *pkt
++ = 'P'; /* process or thread info */
2324 pkt
= pack_int (pkt
, mode
); /* mode */
2325 pkt
= pack_threadid (pkt
, id
); /* threadid */
2326 *pkt
= '\0'; /* terminate */
2330 /* These values tag the fields in a thread info response packet. */
2331 /* Tagging the fields allows us to request specific fields and to
2332 add more fields as time goes by. */
2334 #define TAG_THREADID 1 /* Echo the thread identifier. */
2335 #define TAG_EXISTS 2 /* Is this process defined enough to
2336 fetch registers and its stack? */
2337 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2338 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2339 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2343 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2344 struct gdb_ext_thread_info
*info
)
2346 struct remote_state
*rs
= get_remote_state ();
2350 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2353 /* info->threadid = 0; FIXME: implement zero_threadref. */
2355 info
->display
[0] = '\0';
2356 info
->shortname
[0] = '\0';
2357 info
->more_display
[0] = '\0';
2359 /* Assume the characters indicating the packet type have been
2361 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2362 pkt
= unpack_threadid (pkt
, &ref
);
2365 warning (_("Incomplete response to threadinfo request."));
2366 if (!threadmatch (&ref
, expectedref
))
2367 { /* This is an answer to a different request. */
2368 warning (_("ERROR RMT Thread info mismatch."));
2371 copy_threadref (&info
->threadid
, &ref
);
2373 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2375 /* Packets are terminated with nulls. */
2376 while ((pkt
< limit
) && mask
&& *pkt
)
2378 pkt
= unpack_int (pkt
, &tag
); /* tag */
2379 pkt
= unpack_byte (pkt
, &length
); /* length */
2380 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2382 warning (_("ERROR RMT: threadinfo tag mismatch."));
2386 if (tag
== TAG_THREADID
)
2390 warning (_("ERROR RMT: length of threadid is not 16."));
2394 pkt
= unpack_threadid (pkt
, &ref
);
2395 mask
= mask
& ~TAG_THREADID
;
2398 if (tag
== TAG_EXISTS
)
2400 info
->active
= stub_unpack_int (pkt
, length
);
2402 mask
= mask
& ~(TAG_EXISTS
);
2405 warning (_("ERROR RMT: 'exists' length too long."));
2411 if (tag
== TAG_THREADNAME
)
2413 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2414 mask
= mask
& ~TAG_THREADNAME
;
2417 if (tag
== TAG_DISPLAY
)
2419 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2420 mask
= mask
& ~TAG_DISPLAY
;
2423 if (tag
== TAG_MOREDISPLAY
)
2425 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2426 mask
= mask
& ~TAG_MOREDISPLAY
;
2429 warning (_("ERROR RMT: unknown thread info tag."));
2430 break; /* Not a tag we know about. */
2436 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2437 struct gdb_ext_thread_info
*info
)
2439 struct remote_state
*rs
= get_remote_state ();
2442 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2444 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2446 if (rs
->buf
[0] == '\0')
2449 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2454 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2457 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2458 threadref
*nextthread
)
2460 *pkt
++ = 'q'; /* info query packet */
2461 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2462 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2463 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2464 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2469 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2472 parse_threadlist_response (char *pkt
, int result_limit
,
2473 threadref
*original_echo
, threadref
*resultlist
,
2476 struct remote_state
*rs
= get_remote_state ();
2478 int count
, resultcount
, done
;
2481 /* Assume the 'q' and 'M chars have been stripped. */
2482 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2483 /* done parse past here */
2484 pkt
= unpack_byte (pkt
, &count
); /* count field */
2485 pkt
= unpack_nibble (pkt
, &done
);
2486 /* The first threadid is the argument threadid. */
2487 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2488 while ((count
-- > 0) && (pkt
< limit
))
2490 pkt
= unpack_threadid (pkt
, resultlist
++);
2491 if (resultcount
++ >= result_limit
)
2500 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2501 int *done
, int *result_count
, threadref
*threadlist
)
2503 struct remote_state
*rs
= get_remote_state ();
2506 /* Trancate result limit to be smaller than the packet size. */
2507 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2508 >= get_remote_packet_size ())
2509 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2511 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2513 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2515 if (*rs
->buf
== '\0')
2519 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2520 &rs
->echo_nextthread
, threadlist
, done
);
2522 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2524 /* FIXME: This is a good reason to drop the packet. */
2525 /* Possably, there is a duplicate response. */
2527 retransmit immediatly - race conditions
2528 retransmit after timeout - yes
2530 wait for packet, then exit
2532 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2533 return 0; /* I choose simply exiting. */
2535 if (*result_count
<= 0)
2539 warning (_("RMT ERROR : failed to get remote thread list."));
2542 return result
; /* break; */
2544 if (*result_count
> result_limit
)
2547 warning (_("RMT ERROR: threadlist response longer than requested."));
2553 /* This is the interface between remote and threads, remotes upper
2556 /* remote_find_new_threads retrieves the thread list and for each
2557 thread in the list, looks up the thread in GDB's internal list,
2558 adding the thread if it does not already exist. This involves
2559 getting partial thread lists from the remote target so, polling the
2560 quit_flag is required. */
2564 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2567 struct remote_state
*rs
= get_remote_state ();
2568 int done
, i
, result_count
;
2576 if (loopcount
++ > looplimit
)
2579 warning (_("Remote fetch threadlist -infinite loop-."));
2582 if (!remote_get_threadlist (startflag
, &rs
->nextthread
,
2583 MAXTHREADLISTRESULTS
,
2584 &done
, &result_count
, rs
->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 (&rs
->nextthread
,
2594 &rs
->resultthreadlist
[result_count
- 1]);
2596 while (result_count
--)
2597 if (!(result
= (*stepfunction
) (&rs
->resultthreadlist
[i
++], context
)))
2604 remote_newthread_step (threadref
*ref
, void *context
)
2606 int pid
= ptid_get_pid (inferior_ptid
);
2607 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2609 if (!in_thread_list (ptid
))
2611 return 1; /* continue iterator */
2614 #define CRAZY_MAX_THREADS 1000
2617 remote_current_thread (ptid_t oldpid
)
2619 struct remote_state
*rs
= get_remote_state ();
2622 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2623 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2624 return read_ptid (&rs
->buf
[2], NULL
);
2629 /* Find new threads for info threads command.
2630 * Original version, using John Metzler's thread protocol.
2634 remote_find_new_threads (void)
2636 remote_threadlist_iterator (remote_newthread_step
, 0,
2640 #if defined(HAVE_LIBEXPAT)
2642 typedef struct thread_item
2648 DEF_VEC_O(thread_item_t
);
2650 struct threads_parsing_context
2652 VEC (thread_item_t
) *items
;
2656 start_thread (struct gdb_xml_parser
*parser
,
2657 const struct gdb_xml_element
*element
,
2658 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2660 struct threads_parsing_context
*data
= user_data
;
2662 struct thread_item item
;
2664 struct gdb_xml_value
*attr
;
2666 id
= xml_find_attribute (attributes
, "id")->value
;
2667 item
.ptid
= read_ptid (id
, NULL
);
2669 attr
= xml_find_attribute (attributes
, "core");
2671 item
.core
= *(ULONGEST
*) attr
->value
;
2677 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2681 end_thread (struct gdb_xml_parser
*parser
,
2682 const struct gdb_xml_element
*element
,
2683 void *user_data
, const char *body_text
)
2685 struct threads_parsing_context
*data
= user_data
;
2687 if (body_text
&& *body_text
)
2688 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2691 const struct gdb_xml_attribute thread_attributes
[] = {
2692 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2693 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2694 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2697 const struct gdb_xml_element thread_children
[] = {
2698 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2701 const struct gdb_xml_element threads_children
[] = {
2702 { "thread", thread_attributes
, thread_children
,
2703 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2704 start_thread
, end_thread
},
2705 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2708 const struct gdb_xml_element threads_elements
[] = {
2709 { "threads", NULL
, threads_children
,
2710 GDB_XML_EF_NONE
, NULL
, NULL
},
2711 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2714 /* Discard the contents of the constructed thread info context. */
2717 clear_threads_parsing_context (void *p
)
2719 struct threads_parsing_context
*context
= p
;
2721 struct thread_item
*item
;
2723 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2724 xfree (item
->extra
);
2726 VEC_free (thread_item_t
, context
->items
);
2732 * Find all threads for info threads command.
2733 * Uses new thread protocol contributed by Cisco.
2734 * Falls back and attempts to use the older method (above)
2735 * if the target doesn't respond to the new method.
2739 remote_threads_info (struct target_ops
*ops
)
2741 struct remote_state
*rs
= get_remote_state ();
2745 if (rs
->remote_desc
== 0) /* paranoia */
2746 error (_("Command can only be used when connected to the remote target."));
2748 #if defined(HAVE_LIBEXPAT)
2749 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2751 char *xml
= target_read_stralloc (¤t_target
,
2752 TARGET_OBJECT_THREADS
, NULL
);
2754 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2758 struct threads_parsing_context context
;
2760 context
.items
= NULL
;
2761 make_cleanup (clear_threads_parsing_context
, &context
);
2763 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2764 threads_elements
, xml
, &context
) == 0)
2767 struct thread_item
*item
;
2770 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2773 if (!ptid_equal (item
->ptid
, null_ptid
))
2775 struct private_thread_info
*info
;
2776 /* In non-stop mode, we assume new found threads
2777 are running until proven otherwise with a
2778 stop reply. In all-stop, we can only get
2779 here if all threads are stopped. */
2780 int running
= non_stop
? 1 : 0;
2782 remote_notice_new_inferior (item
->ptid
, running
);
2784 info
= demand_private_info (item
->ptid
);
2785 info
->core
= item
->core
;
2786 info
->extra
= item
->extra
;
2793 do_cleanups (back_to
);
2798 if (rs
->use_threadinfo_query
)
2800 putpkt ("qfThreadInfo");
2801 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2803 if (bufp
[0] != '\0') /* q packet recognized */
2805 struct cleanup
*old_chain
;
2808 /* remote_notice_new_inferior (in the loop below) may make
2809 new RSP calls, which clobber rs->buf. Work with a
2811 bufp
= saved_reply
= xstrdup (rs
->buf
);
2812 old_chain
= make_cleanup (free_current_contents
, &saved_reply
);
2814 while (*bufp
++ == 'm') /* reply contains one or more TID */
2818 new_thread
= read_ptid (bufp
, &bufp
);
2819 if (!ptid_equal (new_thread
, null_ptid
))
2821 /* In non-stop mode, we assume new found threads
2822 are running until proven otherwise with a
2823 stop reply. In all-stop, we can only get
2824 here if all threads are stopped. */
2825 int running
= non_stop
? 1 : 0;
2827 remote_notice_new_inferior (new_thread
, running
);
2830 while (*bufp
++ == ','); /* comma-separated list */
2831 free_current_contents (&saved_reply
);
2832 putpkt ("qsThreadInfo");
2833 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2834 bufp
= saved_reply
= xstrdup (rs
->buf
);
2836 do_cleanups (old_chain
);
2841 /* Only qfThreadInfo is supported in non-stop mode. */
2845 /* Else fall back to old method based on jmetzler protocol. */
2846 rs
->use_threadinfo_query
= 0;
2847 remote_find_new_threads ();
2852 * Collect a descriptive string about the given thread.
2853 * The target may say anything it wants to about the thread
2854 * (typically info about its blocked / runnable state, name, etc.).
2855 * This string will appear in the info threads display.
2857 * Optional: targets are not required to implement this function.
2861 remote_threads_extra_info (struct thread_info
*tp
)
2863 struct remote_state
*rs
= get_remote_state ();
2867 struct gdb_ext_thread_info threadinfo
;
2868 static char display_buf
[100]; /* arbitrary... */
2869 int n
= 0; /* position in display_buf */
2871 if (rs
->remote_desc
== 0) /* paranoia */
2872 internal_error (__FILE__
, __LINE__
,
2873 _("remote_threads_extra_info"));
2875 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2876 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2877 /* This is the main thread which was added by GDB. The remote
2878 server doesn't know about it. */
2881 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2883 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2885 if (info
&& info
->private)
2886 return info
->private->extra
;
2891 if (rs
->use_threadextra_query
)
2894 char *endb
= rs
->buf
+ get_remote_packet_size ();
2896 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2898 write_ptid (b
, endb
, tp
->ptid
);
2901 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2902 if (rs
->buf
[0] != 0)
2904 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2905 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2906 display_buf
[result
] = '\0';
2911 /* If the above query fails, fall back to the old method. */
2912 rs
->use_threadextra_query
= 0;
2913 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2914 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2915 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2916 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2917 if (threadinfo
.active
)
2919 if (*threadinfo
.shortname
)
2920 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2921 " Name: %s,", threadinfo
.shortname
);
2922 if (*threadinfo
.display
)
2923 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2924 " State: %s,", threadinfo
.display
);
2925 if (*threadinfo
.more_display
)
2926 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2927 " Priority: %s", threadinfo
.more_display
);
2931 /* For purely cosmetic reasons, clear up trailing commas. */
2932 if (',' == display_buf
[n
-1])
2933 display_buf
[n
-1] = ' ';
2942 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2943 struct static_tracepoint_marker
*marker
)
2945 struct remote_state
*rs
= get_remote_state ();
2948 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2950 p
+= hexnumstr (p
, addr
);
2952 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2956 error (_("Remote failure reply: %s"), p
);
2960 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2967 static VEC(static_tracepoint_marker_p
) *
2968 remote_static_tracepoint_markers_by_strid (const char *strid
)
2970 struct remote_state
*rs
= get_remote_state ();
2971 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2972 struct static_tracepoint_marker
*marker
= NULL
;
2973 struct cleanup
*old_chain
;
2976 /* Ask for a first packet of static tracepoint marker
2979 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2982 error (_("Remote failure reply: %s"), p
);
2984 old_chain
= make_cleanup (free_current_marker
, &marker
);
2989 marker
= XCNEW (struct static_tracepoint_marker
);
2993 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2995 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2997 VEC_safe_push (static_tracepoint_marker_p
,
3003 release_static_tracepoint_marker (marker
);
3004 memset (marker
, 0, sizeof (*marker
));
3007 while (*p
++ == ','); /* comma-separated list */
3008 /* Ask for another packet of static tracepoint definition. */
3010 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3014 do_cleanups (old_chain
);
3019 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3022 remote_get_ada_task_ptid (long lwp
, long thread
)
3024 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
3028 /* Restart the remote side; this is an extended protocol operation. */
3031 extended_remote_restart (void)
3033 struct remote_state
*rs
= get_remote_state ();
3035 /* Send the restart command; for reasons I don't understand the
3036 remote side really expects a number after the "R". */
3037 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3040 remote_fileio_reset ();
3043 /* Clean up connection to a remote debugger. */
3048 struct remote_state
*rs
= get_remote_state ();
3050 if (rs
->remote_desc
== NULL
)
3051 return; /* already closed */
3053 /* Make sure we leave stdin registered in the event loop, and we
3054 don't leave the async SIGINT signal handler installed. */
3055 remote_terminal_ours ();
3057 serial_close (rs
->remote_desc
);
3058 rs
->remote_desc
= NULL
;
3060 /* We don't have a connection to the remote stub anymore. Get rid
3061 of all the inferiors and their threads we were controlling.
3062 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3063 will be unable to find the thread corresponding to (pid, 0, 0). */
3064 inferior_ptid
= null_ptid
;
3065 discard_all_inferiors ();
3067 /* Stop replies may from inferiors which are still unknown to GDB.
3068 We are closing the remote target, so we should discard
3069 everything, including the stop replies from GDB-unknown
3071 discard_pending_stop_replies (NULL
);
3073 if (remote_async_inferior_event_token
)
3074 delete_async_event_handler (&remote_async_inferior_event_token
);
3076 remote_notif_unregister_async_event_handler ();
3078 trace_reset_local_state ();
3081 /* Query the remote side for the text, data and bss offsets. */
3086 struct remote_state
*rs
= get_remote_state ();
3089 int lose
, num_segments
= 0, do_sections
, do_segments
;
3090 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3091 struct section_offsets
*offs
;
3092 struct symfile_segment_data
*data
;
3094 if (symfile_objfile
== NULL
)
3097 putpkt ("qOffsets");
3098 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3101 if (buf
[0] == '\000')
3102 return; /* Return silently. Stub doesn't support
3106 warning (_("Remote failure reply: %s"), buf
);
3110 /* Pick up each field in turn. This used to be done with scanf, but
3111 scanf will make trouble if CORE_ADDR size doesn't match
3112 conversion directives correctly. The following code will work
3113 with any size of CORE_ADDR. */
3114 text_addr
= data_addr
= bss_addr
= 0;
3118 if (strncmp (ptr
, "Text=", 5) == 0)
3121 /* Don't use strtol, could lose on big values. */
3122 while (*ptr
&& *ptr
!= ';')
3123 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3125 if (strncmp (ptr
, ";Data=", 6) == 0)
3128 while (*ptr
&& *ptr
!= ';')
3129 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3134 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3137 while (*ptr
&& *ptr
!= ';')
3138 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3140 if (bss_addr
!= data_addr
)
3141 warning (_("Target reported unsupported offsets: %s"), buf
);
3146 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3149 /* Don't use strtol, could lose on big values. */
3150 while (*ptr
&& *ptr
!= ';')
3151 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3154 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3157 while (*ptr
&& *ptr
!= ';')
3158 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3166 error (_("Malformed response to offset query, %s"), buf
);
3167 else if (*ptr
!= '\0')
3168 warning (_("Target reported unsupported offsets: %s"), buf
);
3170 offs
= ((struct section_offsets
*)
3171 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3172 memcpy (offs
, symfile_objfile
->section_offsets
,
3173 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3175 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3176 do_segments
= (data
!= NULL
);
3177 do_sections
= num_segments
== 0;
3179 if (num_segments
> 0)
3181 segments
[0] = text_addr
;
3182 segments
[1] = data_addr
;
3184 /* If we have two segments, we can still try to relocate everything
3185 by assuming that the .text and .data offsets apply to the whole
3186 text and data segments. Convert the offsets given in the packet
3187 to base addresses for symfile_map_offsets_to_segments. */
3188 else if (data
&& data
->num_segments
== 2)
3190 segments
[0] = data
->segment_bases
[0] + text_addr
;
3191 segments
[1] = data
->segment_bases
[1] + data_addr
;
3194 /* If the object file has only one segment, assume that it is text
3195 rather than data; main programs with no writable data are rare,
3196 but programs with no code are useless. Of course the code might
3197 have ended up in the data segment... to detect that we would need
3198 the permissions here. */
3199 else if (data
&& data
->num_segments
== 1)
3201 segments
[0] = data
->segment_bases
[0] + text_addr
;
3204 /* There's no way to relocate by segment. */
3210 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3211 offs
, num_segments
, segments
);
3213 if (ret
== 0 && !do_sections
)
3214 error (_("Can not handle qOffsets TextSeg "
3215 "response with this symbol file"));
3222 free_symfile_segment_data (data
);
3226 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3228 /* This is a temporary kludge to force data and bss to use the
3229 same offsets because that's what nlmconv does now. The real
3230 solution requires changes to the stub and remote.c that I
3231 don't have time to do right now. */
3233 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3234 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3237 objfile_relocate (symfile_objfile
, offs
);
3240 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3241 threads we know are stopped already. This is used during the
3242 initial remote connection in non-stop mode --- threads that are
3243 reported as already being stopped are left stopped. */
3246 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3248 /* If we have a stop reply for this thread, it must be stopped. */
3249 if (peek_stop_reply (thread
->ptid
))
3250 set_stop_requested (thread
->ptid
, 1);
3255 /* Send interrupt_sequence to remote target. */
3257 send_interrupt_sequence (void)
3259 struct remote_state
*rs
= get_remote_state ();
3261 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3262 remote_serial_write ("\x03", 1);
3263 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3264 serial_send_break (rs
->remote_desc
);
3265 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3267 serial_send_break (rs
->remote_desc
);
3268 remote_serial_write ("g", 1);
3271 internal_error (__FILE__
, __LINE__
,
3272 _("Invalid value for interrupt_sequence_mode: %s."),
3273 interrupt_sequence_mode
);
3277 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3278 and extract the PTID. Returns NULL_PTID if not found. */
3281 stop_reply_extract_thread (char *stop_reply
)
3283 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3287 /* Txx r:val ; r:val (...) */
3290 /* Look for "register" named "thread". */
3295 p1
= strchr (p
, ':');
3299 if (strncmp (p
, "thread", p1
- p
) == 0)
3300 return read_ptid (++p1
, &p
);
3302 p1
= strchr (p
, ';');
3314 /* Query the remote target for which is the current thread/process,
3315 add it to our tables, and update INFERIOR_PTID. The caller is
3316 responsible for setting the state such that the remote end is ready
3317 to return the current thread.
3319 This function is called after handling the '?' or 'vRun' packets,
3320 whose response is a stop reply from which we can also try
3321 extracting the thread. If the target doesn't support the explicit
3322 qC query, we infer the current thread from that stop reply, passed
3323 in in WAIT_STATUS, which may be NULL. */
3326 add_current_inferior_and_thread (char *wait_status
)
3328 struct remote_state
*rs
= get_remote_state ();
3330 ptid_t ptid
= null_ptid
;
3332 inferior_ptid
= null_ptid
;
3334 /* Now, if we have thread information, update inferior_ptid. First
3335 if we have a stop reply handy, maybe it's a T stop reply with a
3336 "thread" register we can extract the current thread from. If
3337 not, ask the remote which is the current thread, with qC. The
3338 former method avoids a roundtrip. Note we don't use
3339 remote_parse_stop_reply as that makes use of the target
3340 architecture, which we haven't yet fully determined at this
3342 if (wait_status
!= NULL
)
3343 ptid
= stop_reply_extract_thread (wait_status
);
3344 if (ptid_equal (ptid
, null_ptid
))
3345 ptid
= remote_current_thread (inferior_ptid
);
3347 if (!ptid_equal (ptid
, null_ptid
))
3349 if (!remote_multi_process_p (rs
))
3352 inferior_ptid
= ptid
;
3356 /* Without this, some commands which require an active target
3357 (such as kill) won't work. This variable serves (at least)
3358 double duty as both the pid of the target process (if it has
3359 such), and as a flag indicating that a target is active. */
3360 inferior_ptid
= magic_null_ptid
;
3364 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3366 /* Add the main thread. */
3367 add_thread_silent (inferior_ptid
);
3371 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3373 struct remote_state
*rs
= get_remote_state ();
3374 struct packet_config
*noack_config
;
3375 char *wait_status
= NULL
;
3377 immediate_quit
++; /* Allow user to interrupt it. */
3380 if (interrupt_on_connect
)
3381 send_interrupt_sequence ();
3383 /* Ack any packet which the remote side has already sent. */
3384 serial_write (rs
->remote_desc
, "+", 1);
3386 /* Signal other parts that we're going through the initial setup,
3387 and so things may not be stable yet. */
3388 rs
->starting_up
= 1;
3390 /* The first packet we send to the target is the optional "supported
3391 packets" request. If the target can answer this, it will tell us
3392 which later probes to skip. */
3393 remote_query_supported ();
3395 /* If the stub wants to get a QAllow, compose one and send it. */
3396 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3397 remote_set_permissions ();
3399 /* Next, we possibly activate noack mode.
3401 If the QStartNoAckMode packet configuration is set to AUTO,
3402 enable noack mode if the stub reported a wish for it with
3405 If set to TRUE, then enable noack mode even if the stub didn't
3406 report it in qSupported. If the stub doesn't reply OK, the
3407 session ends with an error.
3409 If FALSE, then don't activate noack mode, regardless of what the
3410 stub claimed should be the default with qSupported. */
3412 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3414 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3415 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3416 && noack_config
->support
== PACKET_ENABLE
))
3418 putpkt ("QStartNoAckMode");
3419 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3420 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3426 /* Tell the remote that we are using the extended protocol. */
3428 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3431 /* Let the target know which signals it is allowed to pass down to
3433 update_signals_program_target ();
3435 /* Next, if the target can specify a description, read it. We do
3436 this before anything involving memory or registers. */
3437 target_find_description ();
3439 /* Next, now that we know something about the target, update the
3440 address spaces in the program spaces. */
3441 update_address_spaces ();
3443 /* On OSs where the list of libraries is global to all
3444 processes, we fetch them early. */
3445 if (gdbarch_has_global_solist (target_gdbarch ()))
3446 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3450 if (!rs
->non_stop_aware
)
3451 error (_("Non-stop mode requested, but remote "
3452 "does not support non-stop"));
3454 putpkt ("QNonStop:1");
3455 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3457 if (strcmp (rs
->buf
, "OK") != 0)
3458 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3460 /* Find about threads and processes the stub is already
3461 controlling. We default to adding them in the running state.
3462 The '?' query below will then tell us about which threads are
3464 remote_threads_info (target
);
3466 else if (rs
->non_stop_aware
)
3468 /* Don't assume that the stub can operate in all-stop mode.
3469 Request it explicitly. */
3470 putpkt ("QNonStop:0");
3471 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3473 if (strcmp (rs
->buf
, "OK") != 0)
3474 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3477 /* Upload TSVs regardless of whether the target is running or not. The
3478 remote stub, such as GDBserver, may have some predefined or builtin
3479 TSVs, even if the target is not running. */
3480 if (remote_get_trace_status (current_trace_status ()) != -1)
3482 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3484 remote_upload_trace_state_variables (&uploaded_tsvs
);
3485 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3488 /* Check whether the target is running now. */
3490 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3496 struct inferior
*inf
;
3498 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3501 error (_("The target is not running (try extended-remote?)"));
3503 /* We're connected, but not running. Drop out before we
3504 call start_remote. */
3505 rs
->starting_up
= 0;
3510 /* Save the reply for later. */
3511 wait_status
= alloca (strlen (rs
->buf
) + 1);
3512 strcpy (wait_status
, rs
->buf
);
3515 /* Let the stub know that we want it to return the thread. */
3516 set_continue_thread (minus_one_ptid
);
3518 add_current_inferior_and_thread (wait_status
);
3520 /* init_wait_for_inferior should be called before get_offsets in order
3521 to manage `inserted' flag in bp loc in a correct state.
3522 breakpoint_init_inferior, called from init_wait_for_inferior, set
3523 `inserted' flag to 0, while before breakpoint_re_set, called from
3524 start_remote, set `inserted' flag to 1. In the initialization of
3525 inferior, breakpoint_init_inferior should be called first, and then
3526 breakpoint_re_set can be called. If this order is broken, state of
3527 `inserted' flag is wrong, and cause some problems on breakpoint
3529 init_wait_for_inferior ();
3531 get_offsets (); /* Get text, data & bss offsets. */
3533 /* If we could not find a description using qXfer, and we know
3534 how to do it some other way, try again. This is not
3535 supported for non-stop; it could be, but it is tricky if
3536 there are no stopped threads when we connect. */
3537 if (remote_read_description_p (target
)
3538 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3540 target_clear_description ();
3541 target_find_description ();
3544 /* Use the previously fetched status. */
3545 gdb_assert (wait_status
!= NULL
);
3546 strcpy (rs
->buf
, wait_status
);
3547 rs
->cached_wait_status
= 1;
3550 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3554 /* Clear WFI global state. Do this before finding about new
3555 threads and inferiors, and setting the current inferior.
3556 Otherwise we would clear the proceed status of the current
3557 inferior when we want its stop_soon state to be preserved
3558 (see notice_new_inferior). */
3559 init_wait_for_inferior ();
3561 /* In non-stop, we will either get an "OK", meaning that there
3562 are no stopped threads at this time; or, a regular stop
3563 reply. In the latter case, there may be more than one thread
3564 stopped --- we pull them all out using the vStopped
3566 if (strcmp (rs
->buf
, "OK") != 0)
3568 struct notif_client
*notif
= ¬if_client_stop
;
3570 /* remote_notif_get_pending_replies acks this one, and gets
3572 notif_client_stop
.pending_event
3573 = remote_notif_parse (notif
, rs
->buf
);
3574 remote_notif_get_pending_events (notif
);
3576 /* Make sure that threads that were stopped remain
3578 iterate_over_threads (set_stop_requested_callback
, NULL
);
3581 if (target_can_async_p ())
3582 target_async (inferior_event_handler
, 0);
3584 if (thread_count () == 0)
3587 error (_("The target is not running (try extended-remote?)"));
3589 /* We're connected, but not running. Drop out before we
3590 call start_remote. */
3591 rs
->starting_up
= 0;
3595 /* Let the stub know that we want it to return the thread. */
3597 /* Force the stub to choose a thread. */
3598 set_general_thread (null_ptid
);
3601 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3602 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3603 error (_("remote didn't report the current thread in non-stop mode"));
3605 get_offsets (); /* Get text, data & bss offsets. */
3607 /* In non-stop mode, any cached wait status will be stored in
3608 the stop reply queue. */
3609 gdb_assert (wait_status
== NULL
);
3611 /* Report all signals during attach/startup. */
3612 remote_pass_signals (0, NULL
);
3615 /* If we connected to a live target, do some additional setup. */
3616 if (target_has_execution
)
3618 if (exec_bfd
) /* No use without an exec file. */
3619 remote_check_symbols ();
3622 /* Possibly the target has been engaged in a trace run started
3623 previously; find out where things are at. */
3624 if (remote_get_trace_status (current_trace_status ()) != -1)
3626 struct uploaded_tp
*uploaded_tps
= NULL
;
3628 if (current_trace_status ()->running
)
3629 printf_filtered (_("Trace is already running on the target.\n"));
3631 remote_upload_tracepoints (&uploaded_tps
);
3633 merge_uploaded_tracepoints (&uploaded_tps
);
3636 /* The thread and inferior lists are now synchronized with the
3637 target, our symbols have been relocated, and we're merged the
3638 target's tracepoints with ours. We're done with basic start
3640 rs
->starting_up
= 0;
3642 /* If breakpoints are global, insert them now. */
3643 if (gdbarch_has_global_breakpoints (target_gdbarch ())
3644 && breakpoints_always_inserted_mode ())
3645 insert_breakpoints ();
3648 /* Open a connection to a remote debugger.
3649 NAME is the filename used for communication. */
3652 remote_open (char *name
, int from_tty
)
3654 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3657 /* Open a connection to a remote debugger using the extended
3658 remote gdb protocol. NAME is the filename used for communication. */
3661 extended_remote_open (char *name
, int from_tty
)
3663 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3666 /* Generic code for opening a connection to a remote target. */
3669 init_all_packet_configs (void)
3673 for (i
= 0; i
< PACKET_MAX
; i
++)
3674 update_packet_config (&remote_protocol_packets
[i
]);
3677 /* Symbol look-up. */
3680 remote_check_symbols (void)
3682 struct remote_state
*rs
= get_remote_state ();
3683 char *msg
, *reply
, *tmp
;
3684 struct minimal_symbol
*sym
;
3687 /* The remote side has no concept of inferiors that aren't running
3688 yet, it only knows about running processes. If we're connected
3689 but our current inferior is not running, we should not invite the
3690 remote target to request symbol lookups related to its
3691 (unrelated) current process. */
3692 if (!target_has_execution
)
3695 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3698 /* Make sure the remote is pointing at the right process. Note
3699 there's no way to select "no process". */
3700 set_general_process ();
3702 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3703 because we need both at the same time. */
3704 msg
= alloca (get_remote_packet_size ());
3706 /* Invite target to request symbol lookups. */
3708 putpkt ("qSymbol::");
3709 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3710 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3713 while (strncmp (reply
, "qSymbol:", 8) == 0)
3716 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3718 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3720 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3723 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3724 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3726 /* If this is a function address, return the start of code
3727 instead of any data function descriptor. */
3728 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3732 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3733 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3737 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3742 static struct serial
*
3743 remote_serial_open (char *name
)
3745 static int udp_warning
= 0;
3747 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3748 of in ser-tcp.c, because it is the remote protocol assuming that the
3749 serial connection is reliable and not the serial connection promising
3751 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3753 warning (_("The remote protocol may be unreliable over UDP.\n"
3754 "Some events may be lost, rendering further debugging "
3759 return serial_open (name
);
3762 /* Inform the target of our permission settings. The permission flags
3763 work without this, but if the target knows the settings, it can do
3764 a couple things. First, it can add its own check, to catch cases
3765 that somehow manage to get by the permissions checks in target
3766 methods. Second, if the target is wired to disallow particular
3767 settings (for instance, a system in the field that is not set up to
3768 be able to stop at a breakpoint), it can object to any unavailable
3772 remote_set_permissions (void)
3774 struct remote_state
*rs
= get_remote_state ();
3776 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3777 "WriteReg:%x;WriteMem:%x;"
3778 "InsertBreak:%x;InsertTrace:%x;"
3779 "InsertFastTrace:%x;Stop:%x",
3780 may_write_registers
, may_write_memory
,
3781 may_insert_breakpoints
, may_insert_tracepoints
,
3782 may_insert_fast_tracepoints
, may_stop
);
3784 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3786 /* If the target didn't like the packet, warn the user. Do not try
3787 to undo the user's settings, that would just be maddening. */
3788 if (strcmp (rs
->buf
, "OK") != 0)
3789 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3792 /* This type describes each known response to the qSupported
3794 struct protocol_feature
3796 /* The name of this protocol feature. */
3799 /* The default for this protocol feature. */
3800 enum packet_support default_support
;
3802 /* The function to call when this feature is reported, or after
3803 qSupported processing if the feature is not supported.
3804 The first argument points to this structure. The second
3805 argument indicates whether the packet requested support be
3806 enabled, disabled, or probed (or the default, if this function
3807 is being called at the end of processing and this feature was
3808 not reported). The third argument may be NULL; if not NULL, it
3809 is a NUL-terminated string taken from the packet following
3810 this feature's name and an equals sign. */
3811 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3814 /* The corresponding packet for this feature. Only used if
3815 FUNC is remote_supported_packet. */
3820 remote_supported_packet (const struct protocol_feature
*feature
,
3821 enum packet_support support
,
3822 const char *argument
)
3826 warning (_("Remote qSupported response supplied an unexpected value for"
3827 " \"%s\"."), feature
->name
);
3831 if (remote_protocol_packets
[feature
->packet
].support
3832 == PACKET_SUPPORT_UNKNOWN
)
3833 remote_protocol_packets
[feature
->packet
].support
= support
;
3837 remote_packet_size (const struct protocol_feature
*feature
,
3838 enum packet_support support
, const char *value
)
3840 struct remote_state
*rs
= get_remote_state ();
3845 if (support
!= PACKET_ENABLE
)
3848 if (value
== NULL
|| *value
== '\0')
3850 warning (_("Remote target reported \"%s\" without a size."),
3856 packet_size
= strtol (value
, &value_end
, 16);
3857 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3859 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3860 feature
->name
, value
);
3864 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3866 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3867 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3868 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3871 /* Record the new maximum packet size. */
3872 rs
->explicit_packet_size
= packet_size
;
3876 remote_multi_process_feature (const struct protocol_feature
*feature
,
3877 enum packet_support support
, const char *value
)
3879 struct remote_state
*rs
= get_remote_state ();
3881 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3885 remote_non_stop_feature (const struct protocol_feature
*feature
,
3886 enum packet_support support
, const char *value
)
3888 struct remote_state
*rs
= get_remote_state ();
3890 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3894 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3895 enum packet_support support
,
3898 struct remote_state
*rs
= get_remote_state ();
3900 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3904 remote_cond_breakpoint_feature (const struct protocol_feature
*feature
,
3905 enum packet_support support
,
3908 struct remote_state
*rs
= get_remote_state ();
3910 rs
->cond_breakpoints
= (support
== PACKET_ENABLE
);
3914 remote_breakpoint_commands_feature (const struct protocol_feature
*feature
,
3915 enum packet_support support
,
3918 struct remote_state
*rs
= get_remote_state ();
3920 rs
->breakpoint_commands
= (support
== PACKET_ENABLE
);
3924 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3925 enum packet_support support
,
3928 struct remote_state
*rs
= get_remote_state ();
3930 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3934 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3935 enum packet_support support
,
3938 struct remote_state
*rs
= get_remote_state ();
3940 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3944 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3945 enum packet_support support
,
3948 struct remote_state
*rs
= get_remote_state ();
3950 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3954 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3955 enum packet_support support
,
3958 struct remote_state
*rs
= get_remote_state ();
3960 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3964 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3965 enum packet_support support
,
3968 struct remote_state
*rs
= get_remote_state ();
3970 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3974 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3975 enum packet_support support
,
3978 struct remote_state
*rs
= get_remote_state ();
3980 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3984 remote_augmented_libraries_svr4_read_feature
3985 (const struct protocol_feature
*feature
,
3986 enum packet_support support
, const char *value
)
3988 struct remote_state
*rs
= get_remote_state ();
3990 rs
->augmented_libraries_svr4_read
= (support
== PACKET_ENABLE
);
3993 static const struct protocol_feature remote_protocol_features
[] = {
3994 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3995 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3996 PACKET_qXfer_auxv
},
3997 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3998 PACKET_qXfer_features
},
3999 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4000 PACKET_qXfer_libraries
},
4001 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4002 PACKET_qXfer_libraries_svr4
},
4003 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4004 remote_augmented_libraries_svr4_read_feature
, -1 },
4005 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4006 PACKET_qXfer_memory_map
},
4007 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4008 PACKET_qXfer_spu_read
},
4009 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4010 PACKET_qXfer_spu_write
},
4011 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4012 PACKET_qXfer_osdata
},
4013 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4014 PACKET_qXfer_threads
},
4015 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4016 PACKET_qXfer_traceframe_info
},
4017 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4018 PACKET_QPassSignals
},
4019 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4020 PACKET_QProgramSignals
},
4021 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4022 PACKET_QStartNoAckMode
},
4023 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
4024 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
4025 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4026 PACKET_qXfer_siginfo_read
},
4027 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4028 PACKET_qXfer_siginfo_write
},
4029 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
4030 PACKET_ConditionalTracepoints
},
4031 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_cond_breakpoint_feature
,
4032 PACKET_ConditionalBreakpoints
},
4033 { "BreakpointCommands", PACKET_DISABLE
, remote_breakpoint_commands_feature
,
4034 PACKET_BreakpointCommands
},
4035 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
4036 PACKET_FastTracepoints
},
4037 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
4038 PACKET_StaticTracepoints
},
4039 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
4040 PACKET_InstallInTrace
},
4041 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
4043 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4045 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4047 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4048 PACKET_TracepointSource
},
4049 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4051 { "EnableDisableTracepoints", PACKET_DISABLE
,
4052 remote_enable_disable_tracepoint_feature
, -1 },
4053 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4054 PACKET_qXfer_fdpic
},
4055 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4057 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4058 PACKET_QDisableRandomization
},
4059 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4060 { "QTBuffer:size", PACKET_DISABLE
,
4061 remote_supported_packet
, PACKET_QTBuffer_size
},
4062 { "tracenz", PACKET_DISABLE
,
4063 remote_string_tracing_feature
, -1 },
4064 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4065 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4066 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4067 PACKET_qXfer_btrace
}
4070 static char *remote_support_xml
;
4072 /* Register string appended to "xmlRegisters=" in qSupported query. */
4075 register_remote_support_xml (const char *xml
)
4077 #if defined(HAVE_LIBEXPAT)
4078 if (remote_support_xml
== NULL
)
4079 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4082 char *copy
= xstrdup (remote_support_xml
+ 13);
4083 char *p
= strtok (copy
, ",");
4087 if (strcmp (p
, xml
) == 0)
4094 while ((p
= strtok (NULL
, ",")) != NULL
);
4097 remote_support_xml
= reconcat (remote_support_xml
,
4098 remote_support_xml
, ",", xml
,
4105 remote_query_supported_append (char *msg
, const char *append
)
4108 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4110 return xstrdup (append
);
4114 remote_query_supported (void)
4116 struct remote_state
*rs
= get_remote_state ();
4119 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4121 /* The packet support flags are handled differently for this packet
4122 than for most others. We treat an error, a disabled packet, and
4123 an empty response identically: any features which must be reported
4124 to be used will be automatically disabled. An empty buffer
4125 accomplishes this, since that is also the representation for a list
4126 containing no features. */
4129 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
4132 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4134 q
= remote_query_supported_append (q
, "multiprocess+");
4136 if (remote_support_xml
)
4137 q
= remote_query_supported_append (q
, remote_support_xml
);
4139 q
= remote_query_supported_append (q
, "qRelocInsn+");
4141 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4144 do_cleanups (old_chain
);
4146 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4148 /* If an error occured, warn, but do not return - just reset the
4149 buffer to empty and go on to disable features. */
4150 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4153 warning (_("Remote failure reply: %s"), rs
->buf
);
4158 memset (seen
, 0, sizeof (seen
));
4163 enum packet_support is_supported
;
4164 char *p
, *end
, *name_end
, *value
;
4166 /* First separate out this item from the rest of the packet. If
4167 there's another item after this, we overwrite the separator
4168 (terminated strings are much easier to work with). */
4170 end
= strchr (p
, ';');
4173 end
= p
+ strlen (p
);
4183 warning (_("empty item in \"qSupported\" response"));
4188 name_end
= strchr (p
, '=');
4191 /* This is a name=value entry. */
4192 is_supported
= PACKET_ENABLE
;
4193 value
= name_end
+ 1;
4202 is_supported
= PACKET_ENABLE
;
4206 is_supported
= PACKET_DISABLE
;
4210 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4214 warning (_("unrecognized item \"%s\" "
4215 "in \"qSupported\" response"), p
);
4221 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4222 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4224 const struct protocol_feature
*feature
;
4227 feature
= &remote_protocol_features
[i
];
4228 feature
->func (feature
, is_supported
, value
);
4233 /* If we increased the packet size, make sure to increase the global
4234 buffer size also. We delay this until after parsing the entire
4235 qSupported packet, because this is the same buffer we were
4237 if (rs
->buf_size
< rs
->explicit_packet_size
)
4239 rs
->buf_size
= rs
->explicit_packet_size
;
4240 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4243 /* Handle the defaults for unmentioned features. */
4244 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4247 const struct protocol_feature
*feature
;
4249 feature
= &remote_protocol_features
[i
];
4250 feature
->func (feature
, feature
->default_support
, NULL
);
4254 /* Remove any of the remote.c targets from target stack. Upper targets depend
4255 on it so remove them first. */
4258 remote_unpush_target (void)
4260 pop_all_targets_above (process_stratum
- 1);
4264 remote_open_1 (char *name
, int from_tty
,
4265 struct target_ops
*target
, int extended_p
)
4267 struct remote_state
*rs
= get_remote_state ();
4270 error (_("To open a remote debug connection, you need to specify what\n"
4271 "serial device is attached to the remote system\n"
4272 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4274 /* See FIXME above. */
4275 if (!target_async_permitted
)
4276 wait_forever_enabled_p
= 1;
4278 /* If we're connected to a running target, target_preopen will kill it.
4279 Ask this question first, before target_preopen has a chance to kill
4281 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4284 && !query (_("Already connected to a remote target. Disconnect? ")))
4285 error (_("Still connected."));
4288 /* Here the possibly existing remote target gets unpushed. */
4289 target_preopen (from_tty
);
4291 /* Make sure we send the passed signals list the next time we resume. */
4292 xfree (rs
->last_pass_packet
);
4293 rs
->last_pass_packet
= NULL
;
4295 /* Make sure we send the program signals list the next time we
4297 xfree (rs
->last_program_signals_packet
);
4298 rs
->last_program_signals_packet
= NULL
;
4300 remote_fileio_reset ();
4301 reopen_exec_file ();
4304 rs
->remote_desc
= remote_serial_open (name
);
4305 if (!rs
->remote_desc
)
4306 perror_with_name (name
);
4308 if (baud_rate
!= -1)
4310 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4312 /* The requested speed could not be set. Error out to
4313 top level after closing remote_desc. Take care to
4314 set remote_desc to NULL to avoid closing remote_desc
4316 serial_close (rs
->remote_desc
);
4317 rs
->remote_desc
= NULL
;
4318 perror_with_name (name
);
4322 serial_raw (rs
->remote_desc
);
4324 /* If there is something sitting in the buffer we might take it as a
4325 response to a command, which would be bad. */
4326 serial_flush_input (rs
->remote_desc
);
4330 puts_filtered ("Remote debugging using ");
4331 puts_filtered (name
);
4332 puts_filtered ("\n");
4334 push_target (target
); /* Switch to using remote target now. */
4336 /* Register extra event sources in the event loop. */
4337 remote_async_inferior_event_token
4338 = create_async_event_handler (remote_async_inferior_event_handler
,
4340 remote_notif_register_async_event_handler ();
4342 /* Reset the target state; these things will be queried either by
4343 remote_query_supported or as they are needed. */
4344 init_all_packet_configs ();
4345 rs
->cached_wait_status
= 0;
4346 rs
->explicit_packet_size
= 0;
4348 rs
->multi_process_aware
= 0;
4349 rs
->extended
= extended_p
;
4350 rs
->non_stop_aware
= 0;
4351 rs
->waiting_for_stop_reply
= 0;
4352 rs
->ctrlc_pending_p
= 0;
4354 rs
->general_thread
= not_sent_ptid
;
4355 rs
->continue_thread
= not_sent_ptid
;
4356 rs
->remote_traceframe_number
= -1;
4358 /* Probe for ability to use "ThreadInfo" query, as required. */
4359 rs
->use_threadinfo_query
= 1;
4360 rs
->use_threadextra_query
= 1;
4362 if (target_async_permitted
)
4364 /* With this target we start out by owning the terminal. */
4365 remote_async_terminal_ours_p
= 1;
4367 /* FIXME: cagney/1999-09-23: During the initial connection it is
4368 assumed that the target is already ready and able to respond to
4369 requests. Unfortunately remote_start_remote() eventually calls
4370 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4371 around this. Eventually a mechanism that allows
4372 wait_for_inferior() to expect/get timeouts will be
4374 wait_forever_enabled_p
= 0;
4377 /* First delete any symbols previously loaded from shared libraries. */
4378 no_shared_libraries (NULL
, 0);
4381 init_thread_list ();
4383 /* Start the remote connection. If error() or QUIT, discard this
4384 target (we'd otherwise be in an inconsistent state) and then
4385 propogate the error on up the exception chain. This ensures that
4386 the caller doesn't stumble along blindly assuming that the
4387 function succeeded. The CLI doesn't have this problem but other
4388 UI's, such as MI do.
4390 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4391 this function should return an error indication letting the
4392 caller restore the previous state. Unfortunately the command
4393 ``target remote'' is directly wired to this function making that
4394 impossible. On a positive note, the CLI side of this problem has
4395 been fixed - the function set_cmd_context() makes it possible for
4396 all the ``target ....'' commands to share a common callback
4397 function. See cli-dump.c. */
4399 volatile struct gdb_exception ex
;
4401 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4403 remote_start_remote (from_tty
, target
, extended_p
);
4407 /* Pop the partially set up target - unless something else did
4408 already before throwing the exception. */
4409 if (rs
->remote_desc
!= NULL
)
4410 remote_unpush_target ();
4411 if (target_async_permitted
)
4412 wait_forever_enabled_p
= 1;
4413 throw_exception (ex
);
4417 if (target_async_permitted
)
4418 wait_forever_enabled_p
= 1;
4421 /* This takes a program previously attached to and detaches it. After
4422 this is done, GDB can be used to debug some other program. We
4423 better not have left any breakpoints in the target program or it'll
4424 die when it hits one. */
4427 remote_detach_1 (char *args
, int from_tty
, int extended
)
4429 int pid
= ptid_get_pid (inferior_ptid
);
4430 struct remote_state
*rs
= get_remote_state ();
4433 error (_("Argument given to \"detach\" when remotely debugging."));
4435 if (!target_has_execution
)
4436 error (_("No process to detach from."));
4440 char *exec_file
= get_exec_file (0);
4441 if (exec_file
== NULL
)
4443 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4444 target_pid_to_str (pid_to_ptid (pid
)));
4445 gdb_flush (gdb_stdout
);
4448 /* Tell the remote target to detach. */
4449 if (remote_multi_process_p (rs
))
4450 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4452 strcpy (rs
->buf
, "D");
4455 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4457 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4459 else if (rs
->buf
[0] == '\0')
4460 error (_("Remote doesn't know how to detach"));
4462 error (_("Can't detach process."));
4464 if (from_tty
&& !extended
)
4465 puts_filtered (_("Ending remote debugging.\n"));
4467 target_mourn_inferior ();
4471 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4473 remote_detach_1 (args
, from_tty
, 0);
4477 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4479 remote_detach_1 (args
, from_tty
, 1);
4482 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4485 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4488 error (_("Argument given to \"disconnect\" when remotely debugging."));
4490 /* Make sure we unpush even the extended remote targets; mourn
4491 won't do it. So call remote_mourn_1 directly instead of
4492 target_mourn_inferior. */
4493 remote_mourn_1 (target
);
4496 puts_filtered ("Ending remote debugging.\n");
4499 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4500 be chatty about it. */
4503 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4505 struct remote_state
*rs
= get_remote_state ();
4507 char *wait_status
= NULL
;
4509 pid
= parse_pid_to_attach (args
);
4511 /* Remote PID can be freely equal to getpid, do not check it here the same
4512 way as in other targets. */
4514 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4515 error (_("This target does not support attaching to a process"));
4519 char *exec_file
= get_exec_file (0);
4522 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4523 target_pid_to_str (pid_to_ptid (pid
)));
4525 printf_unfiltered (_("Attaching to %s\n"),
4526 target_pid_to_str (pid_to_ptid (pid
)));
4528 gdb_flush (gdb_stdout
);
4531 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4533 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4535 if (packet_ok (rs
->buf
,
4536 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4540 /* Save the reply for later. */
4541 wait_status
= alloca (strlen (rs
->buf
) + 1);
4542 strcpy (wait_status
, rs
->buf
);
4544 else if (strcmp (rs
->buf
, "OK") != 0)
4545 error (_("Attaching to %s failed with: %s"),
4546 target_pid_to_str (pid_to_ptid (pid
)),
4549 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4550 error (_("This target does not support attaching to a process"));
4552 error (_("Attaching to %s failed"),
4553 target_pid_to_str (pid_to_ptid (pid
)));
4555 set_current_inferior (remote_add_inferior (0, pid
, 1));
4557 inferior_ptid
= pid_to_ptid (pid
);
4561 struct thread_info
*thread
;
4563 /* Get list of threads. */
4564 remote_threads_info (target
);
4566 thread
= first_thread_of_process (pid
);
4568 inferior_ptid
= thread
->ptid
;
4570 inferior_ptid
= pid_to_ptid (pid
);
4572 /* Invalidate our notion of the remote current thread. */
4573 record_currthread (rs
, minus_one_ptid
);
4577 /* Now, if we have thread information, update inferior_ptid. */
4578 inferior_ptid
= remote_current_thread (inferior_ptid
);
4580 /* Add the main thread to the thread list. */
4581 add_thread_silent (inferior_ptid
);
4584 /* Next, if the target can specify a description, read it. We do
4585 this before anything involving memory or registers. */
4586 target_find_description ();
4590 /* Use the previously fetched status. */
4591 gdb_assert (wait_status
!= NULL
);
4593 if (target_can_async_p ())
4595 struct notif_event
*reply
4596 = remote_notif_parse (¬if_client_stop
, wait_status
);
4598 push_stop_reply ((struct stop_reply
*) reply
);
4600 target_async (inferior_event_handler
, 0);
4604 gdb_assert (wait_status
!= NULL
);
4605 strcpy (rs
->buf
, wait_status
);
4606 rs
->cached_wait_status
= 1;
4610 gdb_assert (wait_status
== NULL
);
4614 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4616 extended_remote_attach_1 (ops
, args
, from_tty
);
4619 /* Convert hex digit A to a number. */
4624 if (a
>= '0' && a
<= '9')
4626 else if (a
>= 'a' && a
<= 'f')
4627 return a
- 'a' + 10;
4628 else if (a
>= 'A' && a
<= 'F')
4629 return a
- 'A' + 10;
4631 error (_("Reply contains invalid hex digit %d"), a
);
4635 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4639 for (i
= 0; i
< count
; i
++)
4641 if (hex
[0] == 0 || hex
[1] == 0)
4643 /* Hex string is short, or of uneven length.
4644 Return the count that has been converted so far. */
4647 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4653 /* Convert number NIB to a hex digit. */
4661 return 'a' + nib
- 10;
4665 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4669 /* May use a length, or a nul-terminated string as input. */
4671 count
= strlen ((char *) bin
);
4673 for (i
= 0; i
< count
; i
++)
4675 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4676 *hex
++ = tohex (*bin
++ & 0xf);
4682 /* Check for the availability of vCont. This function should also check
4686 remote_vcont_probe (struct remote_state
*rs
)
4690 strcpy (rs
->buf
, "vCont?");
4692 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4695 /* Make sure that the features we assume are supported. */
4696 if (strncmp (buf
, "vCont", 5) == 0)
4699 int support_s
, support_S
, support_c
, support_C
;
4705 rs
->supports_vCont
.t
= 0;
4706 rs
->supports_vCont
.r
= 0;
4707 while (p
&& *p
== ';')
4710 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4712 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4714 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4716 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4718 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4719 rs
->supports_vCont
.t
= 1;
4720 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4721 rs
->supports_vCont
.r
= 1;
4723 p
= strchr (p
, ';');
4726 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4727 BUF will make packet_ok disable the packet. */
4728 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4732 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4735 /* Helper function for building "vCont" resumptions. Write a
4736 resumption to P. ENDP points to one-passed-the-end of the buffer
4737 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4738 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4739 resumed thread should be single-stepped and/or signalled. If PTID
4740 equals minus_one_ptid, then all threads are resumed; if PTID
4741 represents a process, then all threads of the process are resumed;
4742 the thread to be stepped and/or signalled is given in the global
4746 append_resumption (char *p
, char *endp
,
4747 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4749 struct remote_state
*rs
= get_remote_state ();
4751 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4752 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4754 /* GDB is willing to range step. */
4755 && use_range_stepping
4756 /* Target supports range stepping. */
4757 && rs
->supports_vCont
.r
4758 /* We don't currently support range stepping multiple
4759 threads with a wildcard (though the protocol allows it,
4760 so stubs shouldn't make an active effort to forbid
4762 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4764 struct thread_info
*tp
;
4766 if (ptid_equal (ptid
, minus_one_ptid
))
4768 /* If we don't know about the target thread's tid, then
4769 we're resuming magic_null_ptid (see caller). */
4770 tp
= find_thread_ptid (magic_null_ptid
);
4773 tp
= find_thread_ptid (ptid
);
4774 gdb_assert (tp
!= NULL
);
4776 if (tp
->control
.may_range_step
)
4778 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4780 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
4781 phex_nz (tp
->control
.step_range_start
,
4783 phex_nz (tp
->control
.step_range_end
,
4787 p
+= xsnprintf (p
, endp
- p
, ";s");
4790 p
+= xsnprintf (p
, endp
- p
, ";s");
4791 else if (siggnal
!= GDB_SIGNAL_0
)
4792 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4794 p
+= xsnprintf (p
, endp
- p
, ";c");
4796 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4800 /* All (-1) threads of process. */
4801 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4803 p
+= xsnprintf (p
, endp
- p
, ":");
4804 p
= write_ptid (p
, endp
, nptid
);
4806 else if (!ptid_equal (ptid
, minus_one_ptid
))
4808 p
+= xsnprintf (p
, endp
- p
, ":");
4809 p
= write_ptid (p
, endp
, ptid
);
4815 /* Append a vCont continue-with-signal action for threads that have a
4816 non-zero stop signal. */
4819 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4821 struct thread_info
*thread
;
4823 ALL_THREADS (thread
)
4824 if (ptid_match (thread
->ptid
, ptid
)
4825 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4826 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4827 && signal_pass_state (thread
->suspend
.stop_signal
))
4829 p
= append_resumption (p
, endp
, thread
->ptid
,
4830 0, thread
->suspend
.stop_signal
);
4831 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4837 /* Resume the remote inferior by using a "vCont" packet. The thread
4838 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4839 resumed thread should be single-stepped and/or signalled. If PTID
4840 equals minus_one_ptid, then all threads are resumed; the thread to
4841 be stepped and/or signalled is given in the global INFERIOR_PTID.
4842 This function returns non-zero iff it resumes the inferior.
4844 This function issues a strict subset of all possible vCont commands at the
4848 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4850 struct remote_state
*rs
= get_remote_state ();
4854 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4855 remote_vcont_probe (rs
);
4857 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4861 endp
= rs
->buf
+ get_remote_packet_size ();
4863 /* If we could generate a wider range of packets, we'd have to worry
4864 about overflowing BUF. Should there be a generic
4865 "multi-part-packet" packet? */
4867 p
+= xsnprintf (p
, endp
- p
, "vCont");
4869 if (ptid_equal (ptid
, magic_null_ptid
))
4871 /* MAGIC_NULL_PTID means that we don't have any active threads,
4872 so we don't have any TID numbers the inferior will
4873 understand. Make sure to only send forms that do not specify
4875 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4877 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4879 /* Resume all threads (of all processes, or of a single
4880 process), with preference for INFERIOR_PTID. This assumes
4881 inferior_ptid belongs to the set of all threads we are about
4883 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4885 /* Step inferior_ptid, with or without signal. */
4886 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4889 /* Also pass down any pending signaled resumption for other
4890 threads not the current. */
4891 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4893 /* And continue others without a signal. */
4894 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4898 /* Scheduler locking; resume only PTID. */
4899 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4902 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4907 /* In non-stop, the stub replies to vCont with "OK". The stop
4908 reply will be reported asynchronously by means of a `%Stop'
4910 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4911 if (strcmp (rs
->buf
, "OK") != 0)
4912 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4918 /* Tell the remote machine to resume. */
4921 remote_resume (struct target_ops
*ops
,
4922 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4924 struct remote_state
*rs
= get_remote_state ();
4927 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4928 (explained in remote-notif.c:handle_notification) so
4929 remote_notif_process is not called. We need find a place where
4930 it is safe to start a 'vNotif' sequence. It is good to do it
4931 before resuming inferior, because inferior was stopped and no RSP
4932 traffic at that moment. */
4934 remote_notif_process (¬if_client_stop
);
4936 rs
->last_sent_signal
= siggnal
;
4937 rs
->last_sent_step
= step
;
4939 /* The vCont packet doesn't need to specify threads via Hc. */
4940 /* No reverse support (yet) for vCont. */
4941 if (execution_direction
!= EXEC_REVERSE
)
4942 if (remote_vcont_resume (ptid
, step
, siggnal
))
4945 /* All other supported resume packets do use Hc, so set the continue
4947 if (ptid_equal (ptid
, minus_one_ptid
))
4948 set_continue_thread (any_thread_ptid
);
4950 set_continue_thread (ptid
);
4953 if (execution_direction
== EXEC_REVERSE
)
4955 /* We don't pass signals to the target in reverse exec mode. */
4956 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4957 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4961 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4962 error (_("Remote reverse-step not supported."));
4964 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4965 error (_("Remote reverse-continue not supported."));
4967 strcpy (buf
, step
? "bs" : "bc");
4969 else if (siggnal
!= GDB_SIGNAL_0
)
4971 buf
[0] = step
? 'S' : 'C';
4972 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4973 buf
[2] = tohex (((int) siggnal
) & 0xf);
4977 strcpy (buf
, step
? "s" : "c");
4982 /* We are about to start executing the inferior, let's register it
4983 with the event loop. NOTE: this is the one place where all the
4984 execution commands end up. We could alternatively do this in each
4985 of the execution commands in infcmd.c. */
4986 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4987 into infcmd.c in order to allow inferior function calls to work
4988 NOT asynchronously. */
4989 if (target_can_async_p ())
4990 target_async (inferior_event_handler
, 0);
4992 /* We've just told the target to resume. The remote server will
4993 wait for the inferior to stop, and then send a stop reply. In
4994 the mean time, we can't start another command/query ourselves
4995 because the stub wouldn't be ready to process it. This applies
4996 only to the base all-stop protocol, however. In non-stop (which
4997 only supports vCont), the stub replies with an "OK", and is
4998 immediate able to process further serial input. */
5000 rs
->waiting_for_stop_reply
= 1;
5004 /* Set up the signal handler for SIGINT, while the target is
5005 executing, ovewriting the 'regular' SIGINT signal handler. */
5007 async_initialize_sigint_signal_handler (void)
5009 signal (SIGINT
, async_handle_remote_sigint
);
5012 /* Signal handler for SIGINT, while the target is executing. */
5014 async_handle_remote_sigint (int sig
)
5016 signal (sig
, async_handle_remote_sigint_twice
);
5017 mark_async_signal_handler (async_sigint_remote_token
);
5020 /* Signal handler for SIGINT, installed after SIGINT has already been
5021 sent once. It will take effect the second time that the user sends
5024 async_handle_remote_sigint_twice (int sig
)
5026 signal (sig
, async_handle_remote_sigint
);
5027 mark_async_signal_handler (async_sigint_remote_twice_token
);
5030 /* Perform the real interruption of the target execution, in response
5033 async_remote_interrupt (gdb_client_data arg
)
5036 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5038 target_stop (inferior_ptid
);
5041 /* Perform interrupt, if the first attempt did not succeed. Just give
5042 up on the target alltogether. */
5044 async_remote_interrupt_twice (gdb_client_data arg
)
5047 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5052 /* Reinstall the usual SIGINT handlers, after the target has
5055 async_cleanup_sigint_signal_handler (void *dummy
)
5057 signal (SIGINT
, handle_sigint
);
5060 /* Send ^C to target to halt it. Target will respond, and send us a
5062 static void (*ofunc
) (int);
5064 /* The command line interface's stop routine. This function is installed
5065 as a signal handler for SIGINT. The first time a user requests a
5066 stop, we call remote_stop to send a break or ^C. If there is no
5067 response from the target (it didn't stop when the user requested it),
5068 we ask the user if he'd like to detach from the target. */
5070 sync_remote_interrupt (int signo
)
5072 /* If this doesn't work, try more severe steps. */
5073 signal (signo
, sync_remote_interrupt_twice
);
5075 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5078 /* The user typed ^C twice. */
5081 sync_remote_interrupt_twice (int signo
)
5083 signal (signo
, ofunc
);
5084 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5085 signal (signo
, sync_remote_interrupt
);
5088 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5089 thread, all threads of a remote process, or all threads of all
5093 remote_stop_ns (ptid_t ptid
)
5095 struct remote_state
*rs
= get_remote_state ();
5097 char *endp
= rs
->buf
+ get_remote_packet_size ();
5099 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
5100 remote_vcont_probe (rs
);
5102 if (!rs
->supports_vCont
.t
)
5103 error (_("Remote server does not support stopping threads"));
5105 if (ptid_equal (ptid
, minus_one_ptid
)
5106 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5107 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5112 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5114 if (ptid_is_pid (ptid
))
5115 /* All (-1) threads of process. */
5116 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
5119 /* Small optimization: if we already have a stop reply for
5120 this thread, no use in telling the stub we want this
5122 if (peek_stop_reply (ptid
))
5128 write_ptid (p
, endp
, nptid
);
5131 /* In non-stop, we get an immediate OK reply. The stop reply will
5132 come in asynchronously by notification. */
5134 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5135 if (strcmp (rs
->buf
, "OK") != 0)
5136 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5139 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5140 remote target. It is undefined which thread of which process
5141 reports the stop. */
5144 remote_stop_as (ptid_t ptid
)
5146 struct remote_state
*rs
= get_remote_state ();
5148 rs
->ctrlc_pending_p
= 1;
5150 /* If the inferior is stopped already, but the core didn't know
5151 about it yet, just ignore the request. The cached wait status
5152 will be collected in remote_wait. */
5153 if (rs
->cached_wait_status
)
5156 /* Send interrupt_sequence to remote target. */
5157 send_interrupt_sequence ();
5160 /* This is the generic stop called via the target vector. When a target
5161 interrupt is requested, either by the command line or the GUI, we
5162 will eventually end up here. */
5165 remote_stop (ptid_t ptid
)
5168 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5171 remote_stop_ns (ptid
);
5173 remote_stop_as (ptid
);
5176 /* Ask the user what to do when an interrupt is received. */
5179 interrupt_query (void)
5181 target_terminal_ours ();
5183 if (target_can_async_p ())
5185 signal (SIGINT
, handle_sigint
);
5190 if (query (_("Interrupted while waiting for the program.\n\
5191 Give up (and stop debugging it)? ")))
5193 remote_unpush_target ();
5198 target_terminal_inferior ();
5201 /* Enable/disable target terminal ownership. Most targets can use
5202 terminal groups to control terminal ownership. Remote targets are
5203 different in that explicit transfer of ownership to/from GDB/target
5207 remote_terminal_inferior (void)
5209 if (!target_async_permitted
)
5210 /* Nothing to do. */
5213 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5214 idempotent. The event-loop GDB talking to an asynchronous target
5215 with a synchronous command calls this function from both
5216 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5217 transfer the terminal to the target when it shouldn't this guard
5219 if (!remote_async_terminal_ours_p
)
5221 delete_file_handler (input_fd
);
5222 remote_async_terminal_ours_p
= 0;
5223 async_initialize_sigint_signal_handler ();
5224 /* NOTE: At this point we could also register our selves as the
5225 recipient of all input. Any characters typed could then be
5226 passed on down to the target. */
5230 remote_terminal_ours (void)
5232 if (!target_async_permitted
)
5233 /* Nothing to do. */
5236 /* See FIXME in remote_terminal_inferior. */
5237 if (remote_async_terminal_ours_p
)
5239 async_cleanup_sigint_signal_handler (NULL
);
5240 add_file_handler (input_fd
, stdin_event_handler
, 0);
5241 remote_async_terminal_ours_p
= 1;
5245 remote_console_output (char *msg
)
5249 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5252 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5256 fputs_unfiltered (tb
, gdb_stdtarg
);
5258 gdb_flush (gdb_stdtarg
);
5261 typedef struct cached_reg
5264 gdb_byte data
[MAX_REGISTER_SIZE
];
5267 DEF_VEC_O(cached_reg_t
);
5269 typedef struct stop_reply
5271 struct notif_event base
;
5273 /* The identifier of the thread about this event */
5276 struct target_waitstatus ws
;
5278 /* Expedited registers. This makes remote debugging a bit more
5279 efficient for those targets that provide critical registers as
5280 part of their normal status mechanism (as another roundtrip to
5281 fetch them is avoided). */
5282 VEC(cached_reg_t
) *regcache
;
5284 int stopped_by_watchpoint_p
;
5285 CORE_ADDR watch_data_address
;
5290 DECLARE_QUEUE_P (stop_reply_p
);
5291 DEFINE_QUEUE_P (stop_reply_p
);
5292 /* The list of already fetched and acknowledged stop events. This
5293 queue is used for notification Stop, and other notifications
5294 don't need queue for their events, because the notification events
5295 of Stop can't be consumed immediately, so that events should be
5296 queued first, and be consumed by remote_wait_{ns,as} one per
5297 time. Other notifications can consume their events immediately,
5298 so queue is not needed for them. */
5299 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5302 stop_reply_xfree (struct stop_reply
*r
)
5306 VEC_free (cached_reg_t
, r
->regcache
);
5312 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5313 struct notif_event
*event
)
5315 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5319 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5320 struct notif_event
*event
)
5322 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5325 putpkt ((char *) self
->ack_command
);
5327 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5328 /* We got an unknown stop reply. */
5329 error (_("Unknown stop reply"));
5331 push_stop_reply (stop_reply
);
5335 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5337 /* We can't get pending events in remote_notif_process for
5338 notification stop, and we have to do this in remote_wait_ns
5339 instead. If we fetch all queued events from stub, remote stub
5340 may exit and we have no chance to process them back in
5342 mark_async_event_handler (remote_async_inferior_event_token
);
5347 stop_reply_dtr (struct notif_event
*event
)
5349 struct stop_reply
*r
= (struct stop_reply
*) event
;
5351 VEC_free (cached_reg_t
, r
->regcache
);
5354 static struct notif_event
*
5355 remote_notif_stop_alloc_reply (void)
5357 struct notif_event
*r
5358 = (struct notif_event
*) XMALLOC (struct stop_reply
);
5360 r
->dtr
= stop_reply_dtr
;
5365 /* A client of notification Stop. */
5367 struct notif_client notif_client_stop
=
5371 remote_notif_stop_parse
,
5372 remote_notif_stop_ack
,
5373 remote_notif_stop_can_get_pending_events
,
5374 remote_notif_stop_alloc_reply
,
5378 /* A parameter to pass data in and out. */
5380 struct queue_iter_param
5383 struct stop_reply
*output
;
5386 /* Remove all queue elements meet the condition it checks. */
5389 remote_notif_remove_all (QUEUE (stop_reply_p
) *q
,
5390 QUEUE_ITER (stop_reply_p
) *iter
,
5394 struct queue_iter_param
*param
= data
;
5395 struct inferior
*inf
= param
->input
;
5397 if (inf
== NULL
|| ptid_get_pid (event
->ptid
) == inf
->pid
)
5399 stop_reply_xfree (event
);
5400 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5406 /* Discard all pending stop replies of inferior INF. If INF is NULL,
5407 discard everything. */
5410 discard_pending_stop_replies (struct inferior
*inf
)
5413 struct queue_iter_param param
;
5414 struct stop_reply
*reply
5415 = (struct stop_reply
*) notif_client_stop
.pending_event
;
5417 /* Discard the in-flight notification. */
5420 || ptid_get_pid (reply
->ptid
) == inf
->pid
))
5422 stop_reply_xfree (reply
);
5423 notif_client_stop
.pending_event
= NULL
;
5427 param
.output
= NULL
;
5428 /* Discard the stop replies we have already pulled with
5430 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5431 remote_notif_remove_all
, ¶m
);
5434 /* A parameter to pass data in and out. */
5437 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5438 QUEUE_ITER (stop_reply_p
) *iter
,
5442 struct queue_iter_param
*param
= data
;
5443 ptid_t
*ptid
= param
->input
;
5445 if (ptid_match (event
->ptid
, *ptid
))
5447 param
->output
= event
;
5448 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5455 /* Remove the first reply in 'stop_reply_queue' which matches
5458 static struct stop_reply
*
5459 remote_notif_remove_queued_reply (ptid_t ptid
)
5461 struct queue_iter_param param
;
5463 param
.input
= &ptid
;
5464 param
.output
= NULL
;
5466 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5467 remote_notif_remove_once_on_match
, ¶m
);
5469 fprintf_unfiltered (gdb_stdlog
,
5470 "notif: discard queued event: 'Stop' in %s\n",
5471 target_pid_to_str (ptid
));
5473 return param
.output
;
5476 /* Look for a queued stop reply belonging to PTID. If one is found,
5477 remove it from the queue, and return it. Returns NULL if none is
5478 found. If there are still queued events left to process, tell the
5479 event loop to get back to target_wait soon. */
5481 static struct stop_reply
*
5482 queued_stop_reply (ptid_t ptid
)
5484 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5486 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5487 /* There's still at least an event left. */
5488 mark_async_event_handler (remote_async_inferior_event_token
);
5493 /* Push a fully parsed stop reply in the stop reply queue. Since we
5494 know that we now have at least one queued event left to pass to the
5495 core side, tell the event loop to get back to target_wait soon. */
5498 push_stop_reply (struct stop_reply
*new_event
)
5500 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5503 fprintf_unfiltered (gdb_stdlog
,
5504 "notif: push 'Stop' %s to queue %d\n",
5505 target_pid_to_str (new_event
->ptid
),
5506 QUEUE_length (stop_reply_p
,
5509 mark_async_event_handler (remote_async_inferior_event_token
);
5513 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5514 QUEUE_ITER (stop_reply_p
) *iter
,
5515 struct stop_reply
*event
,
5518 ptid_t
*ptid
= data
;
5520 return !(ptid_equal (*ptid
, event
->ptid
)
5521 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5524 /* Returns true if we have a stop reply for PTID. */
5527 peek_stop_reply (ptid_t ptid
)
5529 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5530 stop_reply_match_ptid_and_ws
, &ptid
);
5533 /* Parse the stop reply in BUF. Either the function succeeds, and the
5534 result is stored in EVENT, or throws an error. */
5537 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5539 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5543 event
->ptid
= null_ptid
;
5544 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5545 event
->ws
.value
.integer
= 0;
5546 event
->stopped_by_watchpoint_p
= 0;
5547 event
->regcache
= NULL
;
5552 case 'T': /* Status with PC, SP, FP, ... */
5553 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5554 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5556 n... = register number
5557 r... = register contents
5560 p
= &buf
[3]; /* after Txx */
5568 /* If the packet contains a register number, save it in
5569 pnum and set p1 to point to the character following it.
5570 Otherwise p1 points to p. */
5572 /* If this packet is an awatch packet, don't parse the 'a'
5573 as a register number. */
5575 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5576 && strncmp (p
, "core", strlen ("core") != 0))
5578 /* Read the ``P'' register number. */
5579 pnum
= strtol (p
, &p_temp
, 16);
5585 if (p1
== p
) /* No register number present here. */
5587 p1
= strchr (p
, ':');
5589 error (_("Malformed packet(a) (missing colon): %s\n\
5592 if (strncmp (p
, "thread", p1
- p
) == 0)
5593 event
->ptid
= read_ptid (++p1
, &p
);
5594 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5595 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5596 || (strncmp (p
, "awatch", p1
- p
) == 0))
5598 event
->stopped_by_watchpoint_p
= 1;
5599 p
= unpack_varlen_hex (++p1
, &addr
);
5600 event
->watch_data_address
= (CORE_ADDR
) addr
;
5602 else if (strncmp (p
, "library", p1
- p
) == 0)
5606 while (*p_temp
&& *p_temp
!= ';')
5609 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5612 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5614 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5615 /* p1 will indicate "begin" or "end", but it makes
5616 no difference for now, so ignore it. */
5617 p_temp
= strchr (p1
+ 1, ';');
5621 else if (strncmp (p
, "core", p1
- p
) == 0)
5625 p
= unpack_varlen_hex (++p1
, &c
);
5630 /* Silently skip unknown optional info. */
5631 p_temp
= strchr (p1
+ 1, ';');
5638 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5639 cached_reg_t cached_reg
;
5644 error (_("Malformed packet(b) (missing colon): %s\n\
5650 error (_("Remote sent bad register number %s: %s\n\
5652 hex_string (pnum
), p
, buf
);
5654 cached_reg
.num
= reg
->regnum
;
5656 fieldsize
= hex2bin (p
, cached_reg
.data
,
5657 register_size (target_gdbarch (),
5660 if (fieldsize
< register_size (target_gdbarch (),
5662 warning (_("Remote reply is too short: %s"), buf
);
5664 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5668 error (_("Remote register badly formatted: %s\nhere: %s"),
5673 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5677 case 'S': /* Old style status, just signal only. */
5678 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5679 event
->ws
.value
.sig
= (enum gdb_signal
)
5680 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5682 case 'W': /* Target exited. */
5689 /* GDB used to accept only 2 hex chars here. Stubs should
5690 only send more if they detect GDB supports multi-process
5692 p
= unpack_varlen_hex (&buf
[1], &value
);
5696 /* The remote process exited. */
5697 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5698 event
->ws
.value
.integer
= value
;
5702 /* The remote process exited with a signal. */
5703 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5704 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5707 /* If no process is specified, assume inferior_ptid. */
5708 pid
= ptid_get_pid (inferior_ptid
);
5717 else if (strncmp (p
,
5718 "process:", sizeof ("process:") - 1) == 0)
5722 p
+= sizeof ("process:") - 1;
5723 unpack_varlen_hex (p
, &upid
);
5727 error (_("unknown stop reply packet: %s"), buf
);
5730 error (_("unknown stop reply packet: %s"), buf
);
5731 event
->ptid
= pid_to_ptid (pid
);
5736 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5737 error (_("No process or thread specified in stop reply: %s"), buf
);
5740 /* When the stub wants to tell GDB about a new notification reply, it
5741 sends a notification (%Stop, for example). Those can come it at
5742 any time, hence, we have to make sure that any pending
5743 putpkt/getpkt sequence we're making is finished, before querying
5744 the stub for more events with the corresponding ack command
5745 (vStopped, for example). E.g., if we started a vStopped sequence
5746 immediately upon receiving the notification, something like this
5754 1.6) <-- (registers reply to step #1.3)
5756 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5759 To solve this, whenever we parse a %Stop notification successfully,
5760 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5761 doing whatever we were doing:
5767 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5768 2.5) <-- (registers reply to step #2.3)
5770 Eventualy after step #2.5, we return to the event loop, which
5771 notices there's an event on the
5772 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5773 associated callback --- the function below. At this point, we're
5774 always safe to start a vStopped sequence. :
5777 2.7) <-- T05 thread:2
5783 remote_notif_get_pending_events (struct notif_client
*nc
)
5785 struct remote_state
*rs
= get_remote_state ();
5787 if (nc
->pending_event
)
5790 fprintf_unfiltered (gdb_stdlog
,
5791 "notif: process: '%s' ack pending event\n",
5795 nc
->ack (nc
, rs
->buf
, nc
->pending_event
);
5796 nc
->pending_event
= NULL
;
5800 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5801 if (strcmp (rs
->buf
, "OK") == 0)
5804 remote_notif_ack (nc
, rs
->buf
);
5810 fprintf_unfiltered (gdb_stdlog
,
5811 "notif: process: '%s' no pending reply\n",
5816 /* Called when it is decided that STOP_REPLY holds the info of the
5817 event that is to be returned to the core. This function always
5818 destroys STOP_REPLY. */
5821 process_stop_reply (struct stop_reply
*stop_reply
,
5822 struct target_waitstatus
*status
)
5826 *status
= stop_reply
->ws
;
5827 ptid
= stop_reply
->ptid
;
5829 /* If no thread/process was reported by the stub, assume the current
5831 if (ptid_equal (ptid
, null_ptid
))
5832 ptid
= inferior_ptid
;
5834 if (status
->kind
!= TARGET_WAITKIND_EXITED
5835 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5837 struct remote_state
*rs
= get_remote_state ();
5839 /* Expedited registers. */
5840 if (stop_reply
->regcache
)
5842 struct regcache
*regcache
5843 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5848 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5850 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5851 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5854 rs
->remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5855 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
5857 remote_notice_new_inferior (ptid
, 0);
5858 demand_private_info (ptid
)->core
= stop_reply
->core
;
5861 stop_reply_xfree (stop_reply
);
5865 /* The non-stop mode version of target_wait. */
5868 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5870 struct remote_state
*rs
= get_remote_state ();
5871 struct stop_reply
*stop_reply
;
5875 /* If in non-stop mode, get out of getpkt even if a
5876 notification is received. */
5878 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5879 0 /* forever */, &is_notif
);
5882 if (ret
!= -1 && !is_notif
)
5885 case 'E': /* Error of some sort. */
5886 /* We're out of sync with the target now. Did it continue
5887 or not? We can't tell which thread it was in non-stop,
5888 so just ignore this. */
5889 warning (_("Remote failure reply: %s"), rs
->buf
);
5891 case 'O': /* Console output. */
5892 remote_console_output (rs
->buf
+ 1);
5895 warning (_("Invalid remote reply: %s"), rs
->buf
);
5899 /* Acknowledge a pending stop reply that may have arrived in the
5901 if (notif_client_stop
.pending_event
!= NULL
)
5902 remote_notif_get_pending_events (¬if_client_stop
);
5904 /* If indeed we noticed a stop reply, we're done. */
5905 stop_reply
= queued_stop_reply (ptid
);
5906 if (stop_reply
!= NULL
)
5907 return process_stop_reply (stop_reply
, status
);
5909 /* Still no event. If we're just polling for an event, then
5910 return to the event loop. */
5911 if (options
& TARGET_WNOHANG
)
5913 status
->kind
= TARGET_WAITKIND_IGNORE
;
5914 return minus_one_ptid
;
5917 /* Otherwise do a blocking wait. */
5918 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5919 1 /* forever */, &is_notif
);
5923 /* Wait until the remote machine stops, then return, storing status in
5924 STATUS just as `wait' would. */
5927 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5929 struct remote_state
*rs
= get_remote_state ();
5930 ptid_t event_ptid
= null_ptid
;
5932 struct stop_reply
*stop_reply
;
5936 status
->kind
= TARGET_WAITKIND_IGNORE
;
5937 status
->value
.integer
= 0;
5939 stop_reply
= queued_stop_reply (ptid
);
5940 if (stop_reply
!= NULL
)
5941 return process_stop_reply (stop_reply
, status
);
5943 if (rs
->cached_wait_status
)
5944 /* Use the cached wait status, but only once. */
5945 rs
->cached_wait_status
= 0;
5951 if (!target_is_async_p ())
5953 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
5954 /* If the user hit C-c before this packet, or between packets,
5955 pretend that it was hit right here. */
5956 if (check_quit_flag ())
5959 sync_remote_interrupt (SIGINT
);
5963 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5964 _never_ wait for ever -> test on target_is_async_p().
5965 However, before we do that we need to ensure that the caller
5966 knows how to take the target into/out of async mode. */
5967 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5968 wait_forever_enabled_p
, &is_notif
);
5970 if (!target_is_async_p ())
5971 signal (SIGINT
, ofunc
);
5973 /* GDB gets a notification. Return to core as this event is
5975 if (ret
!= -1 && is_notif
)
5976 return minus_one_ptid
;
5981 rs
->remote_stopped_by_watchpoint_p
= 0;
5983 /* We got something. */
5984 rs
->waiting_for_stop_reply
= 0;
5986 /* Assume that the target has acknowledged Ctrl-C unless we receive
5987 an 'F' or 'O' packet. */
5988 if (buf
[0] != 'F' && buf
[0] != 'O')
5989 rs
->ctrlc_pending_p
= 0;
5993 case 'E': /* Error of some sort. */
5994 /* We're out of sync with the target now. Did it continue or
5995 not? Not is more likely, so report a stop. */
5996 warning (_("Remote failure reply: %s"), buf
);
5997 status
->kind
= TARGET_WAITKIND_STOPPED
;
5998 status
->value
.sig
= GDB_SIGNAL_0
;
6000 case 'F': /* File-I/O request. */
6001 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6002 rs
->ctrlc_pending_p
= 0;
6004 case 'T': case 'S': case 'X': case 'W':
6006 struct stop_reply
*stop_reply
6007 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6010 event_ptid
= process_stop_reply (stop_reply
, status
);
6013 case 'O': /* Console output. */
6014 remote_console_output (buf
+ 1);
6016 /* The target didn't really stop; keep waiting. */
6017 rs
->waiting_for_stop_reply
= 1;
6021 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6023 /* Zero length reply means that we tried 'S' or 'C' and the
6024 remote system doesn't support it. */
6025 target_terminal_ours_for_output ();
6027 ("Can't send signals to this remote system. %s not sent.\n",
6028 gdb_signal_to_name (rs
->last_sent_signal
));
6029 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6030 target_terminal_inferior ();
6032 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6033 putpkt ((char *) buf
);
6035 /* We just told the target to resume, so a stop reply is in
6037 rs
->waiting_for_stop_reply
= 1;
6040 /* else fallthrough */
6042 warning (_("Invalid remote reply: %s"), buf
);
6044 rs
->waiting_for_stop_reply
= 1;
6048 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6050 /* Nothing interesting happened. If we're doing a non-blocking
6051 poll, we're done. Otherwise, go back to waiting. */
6052 if (options
& TARGET_WNOHANG
)
6053 return minus_one_ptid
;
6057 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6058 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6060 if (!ptid_equal (event_ptid
, null_ptid
))
6061 record_currthread (rs
, event_ptid
);
6063 event_ptid
= inferior_ptid
;
6066 /* A process exit. Invalidate our notion of current thread. */
6067 record_currthread (rs
, minus_one_ptid
);
6072 /* Wait until the remote machine stops, then return, storing status in
6073 STATUS just as `wait' would. */
6076 remote_wait (struct target_ops
*ops
,
6077 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6082 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6084 event_ptid
= remote_wait_as (ptid
, status
, options
);
6086 if (target_can_async_p ())
6088 /* If there are are events left in the queue tell the event loop
6090 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6091 mark_async_event_handler (remote_async_inferior_event_token
);
6097 /* Fetch a single register using a 'p' packet. */
6100 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6102 struct remote_state
*rs
= get_remote_state ();
6104 char regp
[MAX_REGISTER_SIZE
];
6107 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
6110 if (reg
->pnum
== -1)
6115 p
+= hexnumstr (p
, reg
->pnum
);
6118 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6122 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6126 case PACKET_UNKNOWN
:
6129 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6130 gdbarch_register_name (get_regcache_arch (regcache
),
6135 /* If this register is unfetchable, tell the regcache. */
6138 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6142 /* Otherwise, parse and supply the value. */
6148 error (_("fetch_register_using_p: early buf termination"));
6150 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6153 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6157 /* Fetch the registers included in the target's 'g' packet. */
6160 send_g_packet (void)
6162 struct remote_state
*rs
= get_remote_state ();
6165 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6166 remote_send (&rs
->buf
, &rs
->buf_size
);
6168 /* We can get out of synch in various cases. If the first character
6169 in the buffer is not a hex character, assume that has happened
6170 and try to fetch another packet to read. */
6171 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6172 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6173 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6174 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6177 fprintf_unfiltered (gdb_stdlog
,
6178 "Bad register packet; fetching a new packet\n");
6179 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6182 buf_len
= strlen (rs
->buf
);
6184 /* Sanity check the received packet. */
6185 if (buf_len
% 2 != 0)
6186 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6192 process_g_packet (struct regcache
*regcache
)
6194 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6195 struct remote_state
*rs
= get_remote_state ();
6196 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6201 buf_len
= strlen (rs
->buf
);
6203 /* Further sanity checks, with knowledge of the architecture. */
6204 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6205 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6207 /* Save the size of the packet sent to us by the target. It is used
6208 as a heuristic when determining the max size of packets that the
6209 target can safely receive. */
6210 if (rsa
->actual_register_packet_size
== 0)
6211 rsa
->actual_register_packet_size
= buf_len
;
6213 /* If this is smaller than we guessed the 'g' packet would be,
6214 update our records. A 'g' reply that doesn't include a register's
6215 value implies either that the register is not available, or that
6216 the 'p' packet must be used. */
6217 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6219 rsa
->sizeof_g_packet
= buf_len
/ 2;
6221 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6223 if (rsa
->regs
[i
].pnum
== -1)
6226 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6227 rsa
->regs
[i
].in_g_packet
= 0;
6229 rsa
->regs
[i
].in_g_packet
= 1;
6233 regs
= alloca (rsa
->sizeof_g_packet
);
6235 /* Unimplemented registers read as all bits zero. */
6236 memset (regs
, 0, rsa
->sizeof_g_packet
);
6238 /* Reply describes registers byte by byte, each byte encoded as two
6239 hex characters. Suck them all up, then supply them to the
6240 register cacheing/storage mechanism. */
6243 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6245 if (p
[0] == 0 || p
[1] == 0)
6246 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6247 internal_error (__FILE__
, __LINE__
,
6248 _("unexpected end of 'g' packet reply"));
6250 if (p
[0] == 'x' && p
[1] == 'x')
6251 regs
[i
] = 0; /* 'x' */
6253 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6257 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6259 struct packet_reg
*r
= &rsa
->regs
[i
];
6263 if (r
->offset
* 2 >= strlen (rs
->buf
))
6264 /* This shouldn't happen - we adjusted in_g_packet above. */
6265 internal_error (__FILE__
, __LINE__
,
6266 _("unexpected end of 'g' packet reply"));
6267 else if (rs
->buf
[r
->offset
* 2] == 'x')
6269 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6270 /* The register isn't available, mark it as such (at
6271 the same time setting the value to zero). */
6272 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6275 regcache_raw_supply (regcache
, r
->regnum
,
6282 fetch_registers_using_g (struct regcache
*regcache
)
6285 process_g_packet (regcache
);
6288 /* Make the remote selected traceframe match GDB's selected
6292 set_remote_traceframe (void)
6295 struct remote_state
*rs
= get_remote_state ();
6297 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6300 /* Avoid recursion, remote_trace_find calls us again. */
6301 rs
->remote_traceframe_number
= get_traceframe_number ();
6303 newnum
= target_trace_find (tfind_number
,
6304 get_traceframe_number (), 0, 0, NULL
);
6306 /* Should not happen. If it does, all bets are off. */
6307 if (newnum
!= get_traceframe_number ())
6308 warning (_("could not set remote traceframe"));
6312 remote_fetch_registers (struct target_ops
*ops
,
6313 struct regcache
*regcache
, int regnum
)
6315 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6318 set_remote_traceframe ();
6319 set_general_thread (inferior_ptid
);
6323 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6325 gdb_assert (reg
!= NULL
);
6327 /* If this register might be in the 'g' packet, try that first -
6328 we are likely to read more than one register. If this is the
6329 first 'g' packet, we might be overly optimistic about its
6330 contents, so fall back to 'p'. */
6331 if (reg
->in_g_packet
)
6333 fetch_registers_using_g (regcache
);
6334 if (reg
->in_g_packet
)
6338 if (fetch_register_using_p (regcache
, reg
))
6341 /* This register is not available. */
6342 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6347 fetch_registers_using_g (regcache
);
6349 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6350 if (!rsa
->regs
[i
].in_g_packet
)
6351 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6353 /* This register is not available. */
6354 regcache_raw_supply (regcache
, i
, NULL
);
6358 /* Prepare to store registers. Since we may send them all (using a
6359 'G' request), we have to read out the ones we don't want to change
6363 remote_prepare_to_store (struct regcache
*regcache
)
6365 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6367 gdb_byte buf
[MAX_REGISTER_SIZE
];
6369 /* Make sure the entire registers array is valid. */
6370 switch (remote_protocol_packets
[PACKET_P
].support
)
6372 case PACKET_DISABLE
:
6373 case PACKET_SUPPORT_UNKNOWN
:
6374 /* Make sure all the necessary registers are cached. */
6375 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6376 if (rsa
->regs
[i
].in_g_packet
)
6377 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6384 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6385 packet was not recognized. */
6388 store_register_using_P (const struct regcache
*regcache
,
6389 struct packet_reg
*reg
)
6391 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6392 struct remote_state
*rs
= get_remote_state ();
6393 /* Try storing a single register. */
6394 char *buf
= rs
->buf
;
6395 gdb_byte regp
[MAX_REGISTER_SIZE
];
6398 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
6401 if (reg
->pnum
== -1)
6404 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6405 p
= buf
+ strlen (buf
);
6406 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6407 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6409 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6411 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6416 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6417 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6418 case PACKET_UNKNOWN
:
6421 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6425 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6426 contents of the register cache buffer. FIXME: ignores errors. */
6429 store_registers_using_G (const struct regcache
*regcache
)
6431 struct remote_state
*rs
= get_remote_state ();
6432 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6436 /* Extract all the registers in the regcache copying them into a
6441 regs
= alloca (rsa
->sizeof_g_packet
);
6442 memset (regs
, 0, rsa
->sizeof_g_packet
);
6443 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6445 struct packet_reg
*r
= &rsa
->regs
[i
];
6448 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6452 /* Command describes registers byte by byte,
6453 each byte encoded as two hex characters. */
6456 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6458 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6460 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6461 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6462 error (_("Could not write registers; remote failure reply '%s'"),
6466 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6467 of the register cache buffer. FIXME: ignores errors. */
6470 remote_store_registers (struct target_ops
*ops
,
6471 struct regcache
*regcache
, int regnum
)
6473 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6476 set_remote_traceframe ();
6477 set_general_thread (inferior_ptid
);
6481 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6483 gdb_assert (reg
!= NULL
);
6485 /* Always prefer to store registers using the 'P' packet if
6486 possible; we often change only a small number of registers.
6487 Sometimes we change a larger number; we'd need help from a
6488 higher layer to know to use 'G'. */
6489 if (store_register_using_P (regcache
, reg
))
6492 /* For now, don't complain if we have no way to write the
6493 register. GDB loses track of unavailable registers too
6494 easily. Some day, this may be an error. We don't have
6495 any way to read the register, either... */
6496 if (!reg
->in_g_packet
)
6499 store_registers_using_G (regcache
);
6503 store_registers_using_G (regcache
);
6505 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6506 if (!rsa
->regs
[i
].in_g_packet
)
6507 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6508 /* See above for why we do not issue an error here. */
6513 /* Return the number of hex digits in num. */
6516 hexnumlen (ULONGEST num
)
6520 for (i
= 0; num
!= 0; i
++)
6526 /* Set BUF to the minimum number of hex digits representing NUM. */
6529 hexnumstr (char *buf
, ULONGEST num
)
6531 int len
= hexnumlen (num
);
6533 return hexnumnstr (buf
, num
, len
);
6537 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6540 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6546 for (i
= width
- 1; i
>= 0; i
--)
6548 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6555 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6558 remote_address_masked (CORE_ADDR addr
)
6560 unsigned int address_size
= remote_address_size
;
6562 /* If "remoteaddresssize" was not set, default to target address size. */
6564 address_size
= gdbarch_addr_bit (target_gdbarch ());
6566 if (address_size
> 0
6567 && address_size
< (sizeof (ULONGEST
) * 8))
6569 /* Only create a mask when that mask can safely be constructed
6570 in a ULONGEST variable. */
6573 mask
= (mask
<< address_size
) - 1;
6579 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6580 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6581 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6582 (which may be more than *OUT_LEN due to escape characters). The
6583 total number of bytes in the output buffer will be at most
6587 remote_escape_output (const gdb_byte
*buffer
, int len
,
6588 gdb_byte
*out_buf
, int *out_len
,
6591 int input_index
, output_index
;
6594 for (input_index
= 0; input_index
< len
; input_index
++)
6596 gdb_byte b
= buffer
[input_index
];
6598 if (b
== '$' || b
== '#' || b
== '}')
6600 /* These must be escaped. */
6601 if (output_index
+ 2 > out_maxlen
)
6603 out_buf
[output_index
++] = '}';
6604 out_buf
[output_index
++] = b
^ 0x20;
6608 if (output_index
+ 1 > out_maxlen
)
6610 out_buf
[output_index
++] = b
;
6614 *out_len
= input_index
;
6615 return output_index
;
6618 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6619 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6620 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6622 This function reverses remote_escape_output. It allows more
6623 escaped characters than that function does, in particular because
6624 '*' must be escaped to avoid the run-length encoding processing
6625 in reading packets. */
6628 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6629 gdb_byte
*out_buf
, int out_maxlen
)
6631 int input_index
, output_index
;
6636 for (input_index
= 0; input_index
< len
; input_index
++)
6638 gdb_byte b
= buffer
[input_index
];
6640 if (output_index
+ 1 > out_maxlen
)
6642 warning (_("Received too much data from remote target;"
6643 " ignoring overflow."));
6644 return output_index
;
6649 out_buf
[output_index
++] = b
^ 0x20;
6655 out_buf
[output_index
++] = b
;
6659 error (_("Unmatched escape character in target response."));
6661 return output_index
;
6664 /* Determine whether the remote target supports binary downloading.
6665 This is accomplished by sending a no-op memory write of zero length
6666 to the target at the specified address. It does not suffice to send
6667 the whole packet, since many stubs strip the eighth bit and
6668 subsequently compute a wrong checksum, which causes real havoc with
6671 NOTE: This can still lose if the serial line is not eight-bit
6672 clean. In cases like this, the user should clear "remote
6676 check_binary_download (CORE_ADDR addr
)
6678 struct remote_state
*rs
= get_remote_state ();
6680 switch (remote_protocol_packets
[PACKET_X
].support
)
6682 case PACKET_DISABLE
:
6686 case PACKET_SUPPORT_UNKNOWN
:
6692 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6694 p
+= hexnumstr (p
, (ULONGEST
) 0);
6698 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6699 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6701 if (rs
->buf
[0] == '\0')
6704 fprintf_unfiltered (gdb_stdlog
,
6705 "binary downloading NOT "
6706 "supported by target\n");
6707 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6712 fprintf_unfiltered (gdb_stdlog
,
6713 "binary downloading supported by target\n");
6714 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6721 /* Write memory data directly to the remote machine.
6722 This does not inform the data cache; the data cache uses this.
6723 HEADER is the starting part of the packet.
6724 MEMADDR is the address in the remote memory space.
6725 MYADDR is the address of the buffer in our space.
6726 LEN is the number of bytes.
6727 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6728 should send data as binary ('X'), or hex-encoded ('M').
6730 The function creates packet of the form
6731 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6733 where encoding of <DATA> is termined by PACKET_FORMAT.
6735 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6738 Returns the number of bytes transferred, or a negative value (an
6739 'enum target_xfer_error' value) for error. Only transfer a single
6743 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6744 const gdb_byte
*myaddr
, ssize_t len
,
6745 char packet_format
, int use_length
)
6747 struct remote_state
*rs
= get_remote_state ();
6757 if (packet_format
!= 'X' && packet_format
!= 'M')
6758 internal_error (__FILE__
, __LINE__
,
6759 _("remote_write_bytes_aux: bad packet format"));
6764 payload_size
= get_memory_write_packet_size ();
6766 /* The packet buffer will be large enough for the payload;
6767 get_memory_packet_size ensures this. */
6770 /* Compute the size of the actual payload by subtracting out the
6771 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6773 payload_size
-= strlen ("$,:#NN");
6775 /* The comma won't be used. */
6777 header_length
= strlen (header
);
6778 payload_size
-= header_length
;
6779 payload_size
-= hexnumlen (memaddr
);
6781 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6783 strcat (rs
->buf
, header
);
6784 p
= rs
->buf
+ strlen (header
);
6786 /* Compute a best guess of the number of bytes actually transfered. */
6787 if (packet_format
== 'X')
6789 /* Best guess at number of bytes that will fit. */
6790 todo
= min (len
, payload_size
);
6792 payload_size
-= hexnumlen (todo
);
6793 todo
= min (todo
, payload_size
);
6797 /* Num bytes that will fit. */
6798 todo
= min (len
, payload_size
/ 2);
6800 payload_size
-= hexnumlen (todo
);
6801 todo
= min (todo
, payload_size
/ 2);
6805 internal_error (__FILE__
, __LINE__
,
6806 _("minimum packet size too small to write data"));
6808 /* If we already need another packet, then try to align the end
6809 of this packet to a useful boundary. */
6810 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6811 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6813 /* Append "<memaddr>". */
6814 memaddr
= remote_address_masked (memaddr
);
6815 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6822 /* Append <len>. Retain the location/size of <len>. It may need to
6823 be adjusted once the packet body has been created. */
6825 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6833 /* Append the packet body. */
6834 if (packet_format
== 'X')
6836 /* Binary mode. Send target system values byte by byte, in
6837 increasing byte addresses. Only escape certain critical
6839 payload_length
= remote_escape_output (myaddr
, todo
, (gdb_byte
*) p
,
6840 &nr_bytes
, payload_size
);
6842 /* If not all TODO bytes fit, then we'll need another packet. Make
6843 a second try to keep the end of the packet aligned. Don't do
6844 this if the packet is tiny. */
6845 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6849 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6851 if (new_nr_bytes
!= nr_bytes
)
6852 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6853 (gdb_byte
*) p
, &nr_bytes
,
6857 p
+= payload_length
;
6858 if (use_length
&& nr_bytes
< todo
)
6860 /* Escape chars have filled up the buffer prematurely,
6861 and we have actually sent fewer bytes than planned.
6862 Fix-up the length field of the packet. Use the same
6863 number of characters as before. */
6864 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6865 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6870 /* Normal mode: Send target system values byte by byte, in
6871 increasing byte addresses. Each byte is encoded as a two hex
6873 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6877 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6878 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6880 if (rs
->buf
[0] == 'E')
6881 return TARGET_XFER_E_IO
;
6883 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6884 fewer bytes than we'd planned. */
6888 /* Write memory data directly to the remote machine.
6889 This does not inform the data cache; the data cache uses this.
6890 MEMADDR is the address in the remote memory space.
6891 MYADDR is the address of the buffer in our space.
6892 LEN is the number of bytes.
6894 Returns number of bytes transferred, or a negative value (an 'enum
6895 target_xfer_error' value) for error. Only transfer a single
6899 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
6901 char *packet_format
= 0;
6903 /* Check whether the target supports binary download. */
6904 check_binary_download (memaddr
);
6906 switch (remote_protocol_packets
[PACKET_X
].support
)
6909 packet_format
= "X";
6911 case PACKET_DISABLE
:
6912 packet_format
= "M";
6914 case PACKET_SUPPORT_UNKNOWN
:
6915 internal_error (__FILE__
, __LINE__
,
6916 _("remote_write_bytes: bad internal state"));
6918 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6921 return remote_write_bytes_aux (packet_format
,
6922 memaddr
, myaddr
, len
, packet_format
[0], 1);
6925 /* Read memory data directly from the remote machine.
6926 This does not use the data cache; the data cache uses this.
6927 MEMADDR is the address in the remote memory space.
6928 MYADDR is the address of the buffer in our space.
6929 LEN is the number of bytes.
6931 Returns number of bytes transferred, or a negative value (an 'enum
6932 target_xfer_error' value) for error. */
6935 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6937 struct remote_state
*rs
= get_remote_state ();
6938 int max_buf_size
; /* Max size of packet output buffer. */
6946 max_buf_size
= get_memory_read_packet_size ();
6947 /* The packet buffer will be large enough for the payload;
6948 get_memory_packet_size ensures this. */
6950 /* Number if bytes that will fit. */
6951 todo
= min (len
, max_buf_size
/ 2);
6953 /* Construct "m"<memaddr>","<len>". */
6954 memaddr
= remote_address_masked (memaddr
);
6957 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6959 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6962 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6963 if (rs
->buf
[0] == 'E'
6964 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6965 && rs
->buf
[3] == '\0')
6966 return TARGET_XFER_E_IO
;
6967 /* Reply describes memory byte by byte, each byte encoded as two hex
6970 i
= hex2bin (p
, myaddr
, todo
);
6971 /* Return what we have. Let higher layers handle partial reads. */
6977 /* Sends a packet with content determined by the printf format string
6978 FORMAT and the remaining arguments, then gets the reply. Returns
6979 whether the packet was a success, a failure, or unknown. */
6981 static enum packet_result
6982 remote_send_printf (const char *format
, ...)
6984 struct remote_state
*rs
= get_remote_state ();
6985 int max_size
= get_remote_packet_size ();
6988 va_start (ap
, format
);
6991 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6992 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6994 if (putpkt (rs
->buf
) < 0)
6995 error (_("Communication problem with target."));
6998 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7000 return packet_check_result (rs
->buf
);
7004 restore_remote_timeout (void *p
)
7006 int value
= *(int *)p
;
7008 remote_timeout
= value
;
7011 /* Flash writing can take quite some time. We'll set
7012 effectively infinite timeout for flash operations.
7013 In future, we'll need to decide on a better approach. */
7014 static const int remote_flash_timeout
= 1000;
7017 remote_flash_erase (struct target_ops
*ops
,
7018 ULONGEST address
, LONGEST length
)
7020 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7021 int saved_remote_timeout
= remote_timeout
;
7022 enum packet_result ret
;
7023 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7024 &saved_remote_timeout
);
7026 remote_timeout
= remote_flash_timeout
;
7028 ret
= remote_send_printf ("vFlashErase:%s,%s",
7029 phex (address
, addr_size
),
7033 case PACKET_UNKNOWN
:
7034 error (_("Remote target does not support flash erase"));
7036 error (_("Error erasing flash with vFlashErase packet"));
7041 do_cleanups (back_to
);
7045 remote_flash_write (struct target_ops
*ops
,
7046 ULONGEST address
, LONGEST length
,
7047 const gdb_byte
*data
)
7049 int saved_remote_timeout
= remote_timeout
;
7051 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7052 &saved_remote_timeout
);
7054 remote_timeout
= remote_flash_timeout
;
7055 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
7056 do_cleanups (back_to
);
7062 remote_flash_done (struct target_ops
*ops
)
7064 int saved_remote_timeout
= remote_timeout
;
7066 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7067 &saved_remote_timeout
);
7069 remote_timeout
= remote_flash_timeout
;
7070 ret
= remote_send_printf ("vFlashDone");
7071 do_cleanups (back_to
);
7075 case PACKET_UNKNOWN
:
7076 error (_("Remote target does not support vFlashDone"));
7078 error (_("Error finishing flash operation"));
7085 remote_files_info (struct target_ops
*ignore
)
7087 puts_filtered ("Debugging a target over a serial line.\n");
7090 /* Stuff for dealing with the packets which are part of this protocol.
7091 See comment at top of file for details. */
7093 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7094 error to higher layers. Called when a serial error is detected.
7095 The exception message is STRING, followed by a colon and a blank,
7096 the system error message for errno at function entry and final dot
7097 for output compatibility with throw_perror_with_name. */
7100 unpush_and_perror (const char *string
)
7102 int saved_errno
= errno
;
7104 remote_unpush_target ();
7105 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7106 safe_strerror (saved_errno
));
7109 /* Read a single character from the remote end. */
7112 readchar (int timeout
)
7115 struct remote_state
*rs
= get_remote_state ();
7117 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7122 switch ((enum serial_rc
) ch
)
7125 remote_unpush_target ();
7126 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7129 unpush_and_perror (_("Remote communication error. "
7130 "Target disconnected."));
7132 case SERIAL_TIMEOUT
:
7138 /* Wrapper for serial_write that closes the target and throws if
7142 remote_serial_write (const char *str
, int len
)
7144 struct remote_state
*rs
= get_remote_state ();
7146 if (serial_write (rs
->remote_desc
, str
, len
))
7148 unpush_and_perror (_("Remote communication error. "
7149 "Target disconnected."));
7153 /* Send the command in *BUF to the remote machine, and read the reply
7154 into *BUF. Report an error if we get an error reply. Resize
7155 *BUF using xrealloc if necessary to hold the result, and update
7159 remote_send (char **buf
,
7163 getpkt (buf
, sizeof_buf
, 0);
7165 if ((*buf
)[0] == 'E')
7166 error (_("Remote failure reply: %s"), *buf
);
7169 /* Return a pointer to an xmalloc'ed string representing an escaped
7170 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7171 etc. The caller is responsible for releasing the returned
7175 escape_buffer (const char *buf
, int n
)
7177 struct cleanup
*old_chain
;
7178 struct ui_file
*stb
;
7181 stb
= mem_fileopen ();
7182 old_chain
= make_cleanup_ui_file_delete (stb
);
7184 fputstrn_unfiltered (buf
, n
, 0, stb
);
7185 str
= ui_file_xstrdup (stb
, NULL
);
7186 do_cleanups (old_chain
);
7190 /* Display a null-terminated packet on stdout, for debugging, using C
7194 print_packet (char *buf
)
7196 puts_filtered ("\"");
7197 fputstr_filtered (buf
, '"', gdb_stdout
);
7198 puts_filtered ("\"");
7204 return putpkt_binary (buf
, strlen (buf
));
7207 /* Send a packet to the remote machine, with error checking. The data
7208 of the packet is in BUF. The string in BUF can be at most
7209 get_remote_packet_size () - 5 to account for the $, # and checksum,
7210 and for a possible /0 if we are debugging (remote_debug) and want
7211 to print the sent packet as a string. */
7214 putpkt_binary (char *buf
, int cnt
)
7216 struct remote_state
*rs
= get_remote_state ();
7218 unsigned char csum
= 0;
7219 char *buf2
= alloca (cnt
+ 6);
7226 /* Catch cases like trying to read memory or listing threads while
7227 we're waiting for a stop reply. The remote server wouldn't be
7228 ready to handle this request, so we'd hang and timeout. We don't
7229 have to worry about this in synchronous mode, because in that
7230 case it's not possible to issue a command while the target is
7231 running. This is not a problem in non-stop mode, because in that
7232 case, the stub is always ready to process serial input. */
7233 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
7234 error (_("Cannot execute this command while the target is running."));
7236 /* We're sending out a new packet. Make sure we don't look at a
7237 stale cached response. */
7238 rs
->cached_wait_status
= 0;
7240 /* Copy the packet into buffer BUF2, encapsulating it
7241 and giving it a checksum. */
7246 for (i
= 0; i
< cnt
; i
++)
7252 *p
++ = tohex ((csum
>> 4) & 0xf);
7253 *p
++ = tohex (csum
& 0xf);
7255 /* Send it over and over until we get a positive ack. */
7259 int started_error_output
= 0;
7263 struct cleanup
*old_chain
;
7267 str
= escape_buffer (buf2
, p
- buf2
);
7268 old_chain
= make_cleanup (xfree
, str
);
7269 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7270 gdb_flush (gdb_stdlog
);
7271 do_cleanups (old_chain
);
7273 remote_serial_write (buf2
, p
- buf2
);
7275 /* If this is a no acks version of the remote protocol, send the
7276 packet and move on. */
7280 /* Read until either a timeout occurs (-2) or '+' is read.
7281 Handle any notification that arrives in the mean time. */
7284 ch
= readchar (remote_timeout
);
7292 case SERIAL_TIMEOUT
:
7295 if (started_error_output
)
7297 putchar_unfiltered ('\n');
7298 started_error_output
= 0;
7307 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7311 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7313 case SERIAL_TIMEOUT
:
7317 break; /* Retransmit buffer. */
7321 fprintf_unfiltered (gdb_stdlog
,
7322 "Packet instead of Ack, ignoring it\n");
7323 /* It's probably an old response sent because an ACK
7324 was lost. Gobble up the packet and ack it so it
7325 doesn't get retransmitted when we resend this
7328 remote_serial_write ("+", 1);
7329 continue; /* Now, go look for +. */
7336 /* If we got a notification, handle it, and go back to looking
7338 /* We've found the start of a notification. Now
7339 collect the data. */
7340 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7345 struct cleanup
*old_chain
;
7348 str
= escape_buffer (rs
->buf
, val
);
7349 old_chain
= make_cleanup (xfree
, str
);
7350 fprintf_unfiltered (gdb_stdlog
,
7351 " Notification received: %s\n",
7353 do_cleanups (old_chain
);
7355 handle_notification (rs
->buf
);
7356 /* We're in sync now, rewait for the ack. */
7363 if (!started_error_output
)
7365 started_error_output
= 1;
7366 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7368 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7369 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7378 if (!started_error_output
)
7380 started_error_output
= 1;
7381 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7383 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7387 break; /* Here to retransmit. */
7391 /* This is wrong. If doing a long backtrace, the user should be
7392 able to get out next time we call QUIT, without anything as
7393 violent as interrupt_query. If we want to provide a way out of
7394 here without getting to the next QUIT, it should be based on
7395 hitting ^C twice as in remote_wait. */
7406 /* Come here after finding the start of a frame when we expected an
7407 ack. Do our best to discard the rest of this packet. */
7416 c
= readchar (remote_timeout
);
7419 case SERIAL_TIMEOUT
:
7420 /* Nothing we can do. */
7423 /* Discard the two bytes of checksum and stop. */
7424 c
= readchar (remote_timeout
);
7426 c
= readchar (remote_timeout
);
7429 case '*': /* Run length encoding. */
7430 /* Discard the repeat count. */
7431 c
= readchar (remote_timeout
);
7436 /* A regular character. */
7442 /* Come here after finding the start of the frame. Collect the rest
7443 into *BUF, verifying the checksum, length, and handling run-length
7444 compression. NUL terminate the buffer. If there is not enough room,
7445 expand *BUF using xrealloc.
7447 Returns -1 on error, number of characters in buffer (ignoring the
7448 trailing NULL) on success. (could be extended to return one of the
7449 SERIAL status indications). */
7452 read_frame (char **buf_p
,
7459 struct remote_state
*rs
= get_remote_state ();
7466 c
= readchar (remote_timeout
);
7469 case SERIAL_TIMEOUT
:
7471 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7475 fputs_filtered ("Saw new packet start in middle of old one\n",
7477 return -1; /* Start a new packet, count retries. */
7480 unsigned char pktcsum
;
7486 check_0
= readchar (remote_timeout
);
7488 check_1
= readchar (remote_timeout
);
7490 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7493 fputs_filtered ("Timeout in checksum, retrying\n",
7497 else if (check_0
< 0 || check_1
< 0)
7500 fputs_filtered ("Communication error in checksum\n",
7505 /* Don't recompute the checksum; with no ack packets we
7506 don't have any way to indicate a packet retransmission
7511 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7512 if (csum
== pktcsum
)
7517 struct cleanup
*old_chain
;
7520 str
= escape_buffer (buf
, bc
);
7521 old_chain
= make_cleanup (xfree
, str
);
7522 fprintf_unfiltered (gdb_stdlog
,
7523 "Bad checksum, sentsum=0x%x, "
7524 "csum=0x%x, buf=%s\n",
7525 pktcsum
, csum
, str
);
7526 do_cleanups (old_chain
);
7528 /* Number of characters in buffer ignoring trailing
7532 case '*': /* Run length encoding. */
7537 c
= readchar (remote_timeout
);
7539 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7541 /* The character before ``*'' is repeated. */
7543 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7545 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7547 /* Make some more room in the buffer. */
7548 *sizeof_buf
+= repeat
;
7549 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7553 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7559 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7563 if (bc
>= *sizeof_buf
- 1)
7565 /* Make some more room in the buffer. */
7567 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7578 /* Read a packet from the remote machine, with error checking, and
7579 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7580 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7581 rather than timing out; this is used (in synchronous mode) to wait
7582 for a target that is is executing user code to stop. */
7583 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7584 don't have to change all the calls to getpkt to deal with the
7585 return value, because at the moment I don't know what the right
7586 thing to do it for those. */
7594 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7598 /* Read a packet from the remote machine, with error checking, and
7599 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7600 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7601 rather than timing out; this is used (in synchronous mode) to wait
7602 for a target that is is executing user code to stop. If FOREVER ==
7603 0, this function is allowed to time out gracefully and return an
7604 indication of this to the caller. Otherwise return the number of
7605 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7606 enough reason to return to the caller. *IS_NOTIF is an output
7607 boolean that indicates whether *BUF holds a notification or not
7608 (a regular packet). */
7611 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7612 int expecting_notif
, int *is_notif
)
7614 struct remote_state
*rs
= get_remote_state ();
7620 /* We're reading a new response. Make sure we don't look at a
7621 previously cached response. */
7622 rs
->cached_wait_status
= 0;
7624 strcpy (*buf
, "timeout");
7627 timeout
= watchdog
> 0 ? watchdog
: -1;
7628 else if (expecting_notif
)
7629 timeout
= 0; /* There should already be a char in the buffer. If
7632 timeout
= remote_timeout
;
7636 /* Process any number of notifications, and then return when
7640 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7642 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7644 /* This can loop forever if the remote side sends us
7645 characters continuously, but if it pauses, we'll get
7646 SERIAL_TIMEOUT from readchar because of timeout. Then
7647 we'll count that as a retry.
7649 Note that even when forever is set, we will only wait
7650 forever prior to the start of a packet. After that, we
7651 expect characters to arrive at a brisk pace. They should
7652 show up within remote_timeout intervals. */
7654 c
= readchar (timeout
);
7655 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7657 if (c
== SERIAL_TIMEOUT
)
7659 if (expecting_notif
)
7660 return -1; /* Don't complain, it's normal to not get
7661 anything in this case. */
7663 if (forever
) /* Watchdog went off? Kill the target. */
7666 remote_unpush_target ();
7667 throw_error (TARGET_CLOSE_ERROR
,
7668 _("Watchdog timeout has expired. "
7669 "Target detached."));
7672 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7676 /* We've found the start of a packet or notification.
7677 Now collect the data. */
7678 val
= read_frame (buf
, sizeof_buf
);
7683 remote_serial_write ("-", 1);
7686 if (tries
> MAX_TRIES
)
7688 /* We have tried hard enough, and just can't receive the
7689 packet/notification. Give up. */
7690 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7692 /* Skip the ack char if we're in no-ack mode. */
7693 if (!rs
->noack_mode
)
7694 remote_serial_write ("+", 1);
7698 /* If we got an ordinary packet, return that to our caller. */
7703 struct cleanup
*old_chain
;
7706 str
= escape_buffer (*buf
, val
);
7707 old_chain
= make_cleanup (xfree
, str
);
7708 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7709 do_cleanups (old_chain
);
7712 /* Skip the ack char if we're in no-ack mode. */
7713 if (!rs
->noack_mode
)
7714 remote_serial_write ("+", 1);
7715 if (is_notif
!= NULL
)
7720 /* If we got a notification, handle it, and go back to looking
7724 gdb_assert (c
== '%');
7728 struct cleanup
*old_chain
;
7731 str
= escape_buffer (*buf
, val
);
7732 old_chain
= make_cleanup (xfree
, str
);
7733 fprintf_unfiltered (gdb_stdlog
,
7734 " Notification received: %s\n",
7736 do_cleanups (old_chain
);
7738 if (is_notif
!= NULL
)
7741 handle_notification (*buf
);
7743 /* Notifications require no acknowledgement. */
7745 if (expecting_notif
)
7752 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7754 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7758 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7761 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7766 /* A helper function that just calls putpkt; for type correctness. */
7769 putpkt_for_catch_errors (void *arg
)
7771 return putpkt (arg
);
7775 remote_kill (struct target_ops
*ops
)
7777 /* Use catch_errors so the user can quit from gdb even when we
7778 aren't on speaking terms with the remote system. */
7779 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7781 /* Don't wait for it to die. I'm not really sure it matters whether
7782 we do or not. For the existing stubs, kill is a noop. */
7783 target_mourn_inferior ();
7787 remote_vkill (int pid
, struct remote_state
*rs
)
7789 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7792 /* Tell the remote target to detach. */
7793 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7795 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7797 if (packet_ok (rs
->buf
,
7798 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7800 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7807 extended_remote_kill (struct target_ops
*ops
)
7810 int pid
= ptid_get_pid (inferior_ptid
);
7811 struct remote_state
*rs
= get_remote_state ();
7813 res
= remote_vkill (pid
, rs
);
7814 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7816 /* Don't try 'k' on a multi-process aware stub -- it has no way
7817 to specify the pid. */
7821 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7822 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7825 /* Don't wait for it to die. I'm not really sure it matters whether
7826 we do or not. For the existing stubs, kill is a noop. */
7832 error (_("Can't kill process"));
7834 target_mourn_inferior ();
7838 remote_mourn (struct target_ops
*ops
)
7840 remote_mourn_1 (ops
);
7843 /* Worker function for remote_mourn. */
7845 remote_mourn_1 (struct target_ops
*target
)
7847 unpush_target (target
);
7849 /* remote_close takes care of doing most of the clean up. */
7850 generic_mourn_inferior ();
7854 extended_remote_mourn_1 (struct target_ops
*target
)
7856 struct remote_state
*rs
= get_remote_state ();
7858 /* In case we got here due to an error, but we're going to stay
7860 rs
->waiting_for_stop_reply
= 0;
7862 /* If the current general thread belonged to the process we just
7863 detached from or has exited, the remote side current general
7864 thread becomes undefined. Considering a case like this:
7866 - We just got here due to a detach.
7867 - The process that we're detaching from happens to immediately
7868 report a global breakpoint being hit in non-stop mode, in the
7869 same thread we had selected before.
7870 - GDB attaches to this process again.
7871 - This event happens to be the next event we handle.
7873 GDB would consider that the current general thread didn't need to
7874 be set on the stub side (with Hg), since for all it knew,
7875 GENERAL_THREAD hadn't changed.
7877 Notice that although in all-stop mode, the remote server always
7878 sets the current thread to the thread reporting the stop event,
7879 that doesn't happen in non-stop mode; in non-stop, the stub *must
7880 not* change the current thread when reporting a breakpoint hit,
7881 due to the decoupling of event reporting and event handling.
7883 To keep things simple, we always invalidate our notion of the
7885 record_currthread (rs
, minus_one_ptid
);
7887 /* Unlike "target remote", we do not want to unpush the target; then
7888 the next time the user says "run", we won't be connected. */
7890 /* Call common code to mark the inferior as not running. */
7891 generic_mourn_inferior ();
7893 if (!have_inferiors ())
7895 if (!remote_multi_process_p (rs
))
7897 /* Check whether the target is running now - some remote stubs
7898 automatically restart after kill. */
7900 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7902 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7904 /* Assume that the target has been restarted. Set
7905 inferior_ptid so that bits of core GDB realizes
7906 there's something here, e.g., so that the user can
7907 say "kill" again. */
7908 inferior_ptid
= magic_null_ptid
;
7915 extended_remote_mourn (struct target_ops
*ops
)
7917 extended_remote_mourn_1 (ops
);
7921 extended_remote_supports_disable_randomization (void)
7923 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7928 extended_remote_disable_randomization (int val
)
7930 struct remote_state
*rs
= get_remote_state ();
7933 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
7936 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7938 error (_("Target does not support QDisableRandomization."));
7939 if (strcmp (reply
, "OK") != 0)
7940 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7944 extended_remote_run (char *args
)
7946 struct remote_state
*rs
= get_remote_state ();
7949 /* If the user has disabled vRun support, or we have detected that
7950 support is not available, do not try it. */
7951 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7954 strcpy (rs
->buf
, "vRun;");
7955 len
= strlen (rs
->buf
);
7957 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7958 error (_("Remote file name too long for run packet"));
7959 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7961 gdb_assert (args
!= NULL
);
7964 struct cleanup
*back_to
;
7968 argv
= gdb_buildargv (args
);
7969 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7970 for (i
= 0; argv
[i
] != NULL
; i
++)
7972 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7973 error (_("Argument list too long for run packet"));
7974 rs
->buf
[len
++] = ';';
7975 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7977 do_cleanups (back_to
);
7980 rs
->buf
[len
++] = '\0';
7983 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7985 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7987 /* We have a wait response. All is well. */
7990 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7991 /* It wasn't disabled before, but it is now. */
7995 if (remote_exec_file
[0] == '\0')
7996 error (_("Running the default executable on the remote target failed; "
7997 "try \"set remote exec-file\"?"));
7999 error (_("Running \"%s\" on the remote target failed"),
8004 /* In the extended protocol we want to be able to do things like
8005 "run" and have them basically work as expected. So we need
8006 a special create_inferior function. We support changing the
8007 executable file and the command line arguments, but not the
8011 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
8012 char **env
, int from_tty
)
8016 struct remote_state
*rs
= get_remote_state ();
8018 /* If running asynchronously, register the target file descriptor
8019 with the event loop. */
8020 if (target_can_async_p ())
8021 target_async (inferior_event_handler
, 0);
8023 /* Disable address space randomization if requested (and supported). */
8024 if (extended_remote_supports_disable_randomization ())
8025 extended_remote_disable_randomization (disable_randomization
);
8027 /* Now restart the remote server. */
8028 run_worked
= extended_remote_run (args
) != -1;
8031 /* vRun was not supported. Fail if we need it to do what the
8033 if (remote_exec_file
[0])
8034 error (_("Remote target does not support \"set remote exec-file\""));
8036 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8038 /* Fall back to "R". */
8039 extended_remote_restart ();
8042 if (!have_inferiors ())
8044 /* Clean up from the last time we ran, before we mark the target
8045 running again. This will mark breakpoints uninserted, and
8046 get_offsets may insert breakpoints. */
8047 init_thread_list ();
8048 init_wait_for_inferior ();
8051 /* vRun's success return is a stop reply. */
8052 stop_reply
= run_worked
? rs
->buf
: NULL
;
8053 add_current_inferior_and_thread (stop_reply
);
8055 /* Get updated offsets, if the stub uses qOffsets. */
8060 extended_remote_create_inferior (struct target_ops
*ops
,
8061 char *exec_file
, char *args
,
8062 char **env
, int from_tty
)
8064 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
8068 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8069 the list of conditions (in agent expression bytecode format), if any, the
8070 target needs to evaluate. The output is placed into the packet buffer
8071 started from BUF and ended at BUF_END. */
8074 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8075 struct bp_target_info
*bp_tgt
, char *buf
,
8078 struct agent_expr
*aexpr
= NULL
;
8081 char *buf_start
= buf
;
8083 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8086 buf
+= strlen (buf
);
8087 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8090 /* Send conditions to the target and free the vector. */
8092 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8095 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8096 buf
+= strlen (buf
);
8097 for (i
= 0; i
< aexpr
->len
; ++i
)
8098 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8102 VEC_free (agent_expr_p
, bp_tgt
->conditions
);
8107 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8108 struct bp_target_info
*bp_tgt
, char *buf
)
8110 struct agent_expr
*aexpr
= NULL
;
8113 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8116 buf
+= strlen (buf
);
8118 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8119 buf
+= strlen (buf
);
8121 /* Concatenate all the agent expressions that are commands into the
8124 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8127 sprintf (buf
, "X%x,", aexpr
->len
);
8128 buf
+= strlen (buf
);
8129 for (i
= 0; i
< aexpr
->len
; ++i
)
8130 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8134 VEC_free (agent_expr_p
, bp_tgt
->tcommands
);
8137 /* Insert a breakpoint. On targets that have software breakpoint
8138 support, we ask the remote target to do the work; on targets
8139 which don't, we insert a traditional memory breakpoint. */
8142 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
8143 struct bp_target_info
*bp_tgt
)
8145 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8146 If it succeeds, then set the support to PACKET_ENABLE. If it
8147 fails, and the user has explicitly requested the Z support then
8148 report an error, otherwise, mark it disabled and go on. */
8150 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8152 CORE_ADDR addr
= bp_tgt
->placed_address
;
8153 struct remote_state
*rs
;
8156 struct condition_list
*cond
= NULL
;
8158 /* Make sure the remote is pointing at the right process, if
8160 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8161 set_general_process ();
8163 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8165 rs
= get_remote_state ();
8167 endbuf
= rs
->buf
+ get_remote_packet_size ();
8172 addr
= (ULONGEST
) remote_address_masked (addr
);
8173 p
+= hexnumstr (p
, addr
);
8174 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8176 if (remote_supports_cond_breakpoints ())
8177 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8179 if (remote_can_run_breakpoint_commands ())
8180 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8183 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8185 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8190 bp_tgt
->placed_address
= addr
;
8191 bp_tgt
->placed_size
= bpsize
;
8193 case PACKET_UNKNOWN
:
8198 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
8202 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
8203 struct bp_target_info
*bp_tgt
)
8205 CORE_ADDR addr
= bp_tgt
->placed_address
;
8206 struct remote_state
*rs
= get_remote_state ();
8208 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8211 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8213 /* Make sure the remote is pointing at the right process, if
8215 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8216 set_general_process ();
8222 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8223 p
+= hexnumstr (p
, addr
);
8224 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8227 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8229 return (rs
->buf
[0] == 'E');
8232 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
8236 watchpoint_to_Z_packet (int type
)
8241 return Z_PACKET_WRITE_WP
;
8244 return Z_PACKET_READ_WP
;
8247 return Z_PACKET_ACCESS_WP
;
8250 internal_error (__FILE__
, __LINE__
,
8251 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8256 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
8257 struct expression
*cond
)
8259 struct remote_state
*rs
= get_remote_state ();
8260 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8262 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8264 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8267 /* Make sure the remote is pointing at the right process, if
8269 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8270 set_general_process ();
8272 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8273 p
= strchr (rs
->buf
, '\0');
8274 addr
= remote_address_masked (addr
);
8275 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8276 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8279 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8281 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8285 case PACKET_UNKNOWN
:
8290 internal_error (__FILE__
, __LINE__
,
8291 _("remote_insert_watchpoint: reached end of function"));
8295 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8296 CORE_ADDR start
, int length
)
8298 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8300 return diff
< length
;
8305 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
8306 struct expression
*cond
)
8308 struct remote_state
*rs
= get_remote_state ();
8309 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8311 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8313 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8316 /* Make sure the remote is pointing at the right process, if
8318 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8319 set_general_process ();
8321 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8322 p
= strchr (rs
->buf
, '\0');
8323 addr
= remote_address_masked (addr
);
8324 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8325 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8327 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8329 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8332 case PACKET_UNKNOWN
:
8337 internal_error (__FILE__
, __LINE__
,
8338 _("remote_remove_watchpoint: reached end of function"));
8342 int remote_hw_watchpoint_limit
= -1;
8343 int remote_hw_watchpoint_length_limit
= -1;
8344 int remote_hw_breakpoint_limit
= -1;
8347 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
8349 if (remote_hw_watchpoint_length_limit
== 0)
8351 else if (remote_hw_watchpoint_length_limit
< 0)
8353 else if (len
<= remote_hw_watchpoint_length_limit
)
8360 remote_check_watch_resources (int type
, int cnt
, int ot
)
8362 if (type
== bp_hardware_breakpoint
)
8364 if (remote_hw_breakpoint_limit
== 0)
8366 else if (remote_hw_breakpoint_limit
< 0)
8368 else if (cnt
<= remote_hw_breakpoint_limit
)
8373 if (remote_hw_watchpoint_limit
== 0)
8375 else if (remote_hw_watchpoint_limit
< 0)
8379 else if (cnt
<= remote_hw_watchpoint_limit
)
8386 remote_stopped_by_watchpoint (void)
8388 struct remote_state
*rs
= get_remote_state ();
8390 return rs
->remote_stopped_by_watchpoint_p
;
8394 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8396 struct remote_state
*rs
= get_remote_state ();
8399 if (remote_stopped_by_watchpoint ())
8401 *addr_p
= rs
->remote_watch_data_address
;
8410 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
8411 struct bp_target_info
*bp_tgt
)
8414 struct remote_state
*rs
;
8418 /* The length field should be set to the size of a breakpoint
8419 instruction, even though we aren't inserting one ourselves. */
8421 gdbarch_remote_breakpoint_from_pc
8422 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
8424 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8427 /* Make sure the remote is pointing at the right process, if
8429 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8430 set_general_process ();
8432 rs
= get_remote_state ();
8434 endbuf
= rs
->buf
+ get_remote_packet_size ();
8440 addr
= remote_address_masked (bp_tgt
->placed_address
);
8441 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8442 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8444 if (remote_supports_cond_breakpoints ())
8445 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8447 if (remote_can_run_breakpoint_commands ())
8448 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8451 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8453 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8456 if (rs
->buf
[1] == '.')
8458 message
= strchr (rs
->buf
+ 2, '.');
8460 error (_("Remote failure reply: %s"), message
+ 1);
8463 case PACKET_UNKNOWN
:
8468 internal_error (__FILE__
, __LINE__
,
8469 _("remote_insert_hw_breakpoint: reached end of function"));
8474 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
8475 struct bp_target_info
*bp_tgt
)
8478 struct remote_state
*rs
= get_remote_state ();
8480 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8482 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8485 /* Make sure the remote is pointing at the right process, if
8487 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8488 set_general_process ();
8494 addr
= remote_address_masked (bp_tgt
->placed_address
);
8495 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8496 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8499 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8501 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8504 case PACKET_UNKNOWN
:
8509 internal_error (__FILE__
, __LINE__
,
8510 _("remote_remove_hw_breakpoint: reached end of function"));
8513 /* Verify memory using the "qCRC:" request. */
8516 remote_verify_memory (struct target_ops
*ops
,
8517 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8519 struct remote_state
*rs
= get_remote_state ();
8520 unsigned long host_crc
, target_crc
;
8523 /* Make sure the remote is pointing at the right process. */
8524 set_general_process ();
8526 /* FIXME: assumes lma can fit into long. */
8527 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8528 (long) lma
, (long) size
);
8531 /* Be clever; compute the host_crc before waiting for target
8533 host_crc
= xcrc32 (data
, size
, 0xffffffff);
8535 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8536 if (rs
->buf
[0] == 'E')
8539 if (rs
->buf
[0] != 'C')
8540 error (_("remote target does not support this operation"));
8542 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8543 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8545 return (host_crc
== target_crc
);
8548 /* compare-sections command
8550 With no arguments, compares each loadable section in the exec bfd
8551 with the same memory range on the target, and reports mismatches.
8552 Useful for verifying the image on the target against the exec file. */
8555 compare_sections_command (char *args
, int from_tty
)
8558 struct cleanup
*old_chain
;
8560 const char *sectname
;
8568 error (_("command cannot be used without an exec file"));
8570 /* Make sure the remote is pointing at the right process. */
8571 set_general_process ();
8573 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8575 if (!(s
->flags
& SEC_LOAD
))
8576 continue; /* Skip non-loadable section. */
8578 size
= bfd_get_section_size (s
);
8580 continue; /* Skip zero-length section. */
8582 sectname
= bfd_get_section_name (exec_bfd
, s
);
8583 if (args
&& strcmp (args
, sectname
) != 0)
8584 continue; /* Not the section selected by user. */
8586 matched
= 1; /* Do this section. */
8589 sectdata
= xmalloc (size
);
8590 old_chain
= make_cleanup (xfree
, sectdata
);
8591 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8593 res
= target_verify_memory (sectdata
, lma
, size
);
8596 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8597 paddress (target_gdbarch (), lma
),
8598 paddress (target_gdbarch (), lma
+ size
));
8600 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8601 paddress (target_gdbarch (), lma
),
8602 paddress (target_gdbarch (), lma
+ size
));
8604 printf_filtered ("matched.\n");
8607 printf_filtered ("MIS-MATCHED!\n");
8611 do_cleanups (old_chain
);
8614 warning (_("One or more sections of the remote executable does not match\n\
8615 the loaded file\n"));
8616 if (args
&& !matched
)
8617 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8620 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8621 into remote target. The number of bytes written to the remote
8622 target is returned, or -1 for error. */
8625 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8626 const char *annex
, const gdb_byte
*writebuf
,
8627 ULONGEST offset
, LONGEST len
,
8628 struct packet_config
*packet
)
8632 struct remote_state
*rs
= get_remote_state ();
8633 int max_size
= get_memory_write_packet_size ();
8635 if (packet
->support
== PACKET_DISABLE
)
8638 /* Insert header. */
8639 i
= snprintf (rs
->buf
, max_size
,
8640 "qXfer:%s:write:%s:%s:",
8641 object_name
, annex
? annex
: "",
8642 phex_nz (offset
, sizeof offset
));
8643 max_size
-= (i
+ 1);
8645 /* Escape as much data as fits into rs->buf. */
8646 buf_len
= remote_escape_output
8647 (writebuf
, len
, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
8649 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8650 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8651 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8654 unpack_varlen_hex (rs
->buf
, &n
);
8658 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8659 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8660 number of bytes read is returned, or 0 for EOF, or -1 for error.
8661 The number of bytes read may be less than LEN without indicating an
8662 EOF. PACKET is checked and updated to indicate whether the remote
8663 target supports this object. */
8666 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8668 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8669 struct packet_config
*packet
)
8671 struct remote_state
*rs
= get_remote_state ();
8672 LONGEST i
, n
, packet_len
;
8674 if (packet
->support
== PACKET_DISABLE
)
8677 /* Check whether we've cached an end-of-object packet that matches
8679 if (rs
->finished_object
)
8681 if (strcmp (object_name
, rs
->finished_object
) == 0
8682 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
8683 && offset
== rs
->finished_offset
)
8686 /* Otherwise, we're now reading something different. Discard
8688 xfree (rs
->finished_object
);
8689 xfree (rs
->finished_annex
);
8690 rs
->finished_object
= NULL
;
8691 rs
->finished_annex
= NULL
;
8694 /* Request only enough to fit in a single packet. The actual data
8695 may not, since we don't know how much of it will need to be escaped;
8696 the target is free to respond with slightly less data. We subtract
8697 five to account for the response type and the protocol frame. */
8698 n
= min (get_remote_packet_size () - 5, len
);
8699 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8700 object_name
, annex
? annex
: "",
8701 phex_nz (offset
, sizeof offset
),
8702 phex_nz (n
, sizeof n
));
8703 i
= putpkt (rs
->buf
);
8708 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8709 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8712 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8713 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8715 /* 'm' means there is (or at least might be) more data after this
8716 batch. That does not make sense unless there's at least one byte
8717 of data in this reply. */
8718 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8719 error (_("Remote qXfer reply contained no data."));
8721 /* Got some data. */
8722 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
8723 packet_len
- 1, readbuf
, n
);
8725 /* 'l' is an EOF marker, possibly including a final block of data,
8726 or possibly empty. If we have the final block of a non-empty
8727 object, record this fact to bypass a subsequent partial read. */
8728 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8730 rs
->finished_object
= xstrdup (object_name
);
8731 rs
->finished_annex
= xstrdup (annex
? annex
: "");
8732 rs
->finished_offset
= offset
+ i
;
8739 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8740 const char *annex
, gdb_byte
*readbuf
,
8741 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8743 struct remote_state
*rs
;
8748 set_remote_traceframe ();
8749 set_general_thread (inferior_ptid
);
8751 rs
= get_remote_state ();
8753 /* Handle memory using the standard memory routines. */
8754 if (object
== TARGET_OBJECT_MEMORY
)
8758 /* If the remote target is connected but not running, we should
8759 pass this request down to a lower stratum (e.g. the executable
8761 if (!target_has_execution
)
8764 if (writebuf
!= NULL
)
8765 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8767 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8772 /* Handle SPU memory using qxfer packets. */
8773 if (object
== TARGET_OBJECT_SPU
)
8776 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8777 &remote_protocol_packets
8778 [PACKET_qXfer_spu_read
]);
8780 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8781 &remote_protocol_packets
8782 [PACKET_qXfer_spu_write
]);
8785 /* Handle extra signal info using qxfer packets. */
8786 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8789 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8790 &remote_protocol_packets
8791 [PACKET_qXfer_siginfo_read
]);
8793 return remote_write_qxfer (ops
, "siginfo", annex
,
8794 writebuf
, offset
, len
,
8795 &remote_protocol_packets
8796 [PACKET_qXfer_siginfo_write
]);
8799 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8802 return remote_read_qxfer (ops
, "statictrace", annex
,
8803 readbuf
, offset
, len
,
8804 &remote_protocol_packets
8805 [PACKET_qXfer_statictrace_read
]);
8810 /* Only handle flash writes. */
8811 if (writebuf
!= NULL
)
8817 case TARGET_OBJECT_FLASH
:
8818 return remote_flash_write (ops
, offset
, len
, writebuf
);
8825 /* Map pre-existing objects onto letters. DO NOT do this for new
8826 objects!!! Instead specify new query packets. */
8829 case TARGET_OBJECT_AVR
:
8833 case TARGET_OBJECT_AUXV
:
8834 gdb_assert (annex
== NULL
);
8835 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8836 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8838 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8839 return remote_read_qxfer
8840 (ops
, "features", annex
, readbuf
, offset
, len
,
8841 &remote_protocol_packets
[PACKET_qXfer_features
]);
8843 case TARGET_OBJECT_LIBRARIES
:
8844 return remote_read_qxfer
8845 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8846 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8848 case TARGET_OBJECT_LIBRARIES_SVR4
:
8849 return remote_read_qxfer
8850 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8851 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8853 case TARGET_OBJECT_MEMORY_MAP
:
8854 gdb_assert (annex
== NULL
);
8855 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8856 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8858 case TARGET_OBJECT_OSDATA
:
8859 /* Should only get here if we're connected. */
8860 gdb_assert (rs
->remote_desc
);
8861 return remote_read_qxfer
8862 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8863 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8865 case TARGET_OBJECT_THREADS
:
8866 gdb_assert (annex
== NULL
);
8867 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8868 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8870 case TARGET_OBJECT_TRACEFRAME_INFO
:
8871 gdb_assert (annex
== NULL
);
8872 return remote_read_qxfer
8873 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8874 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8876 case TARGET_OBJECT_FDPIC
:
8877 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8878 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8880 case TARGET_OBJECT_OPENVMS_UIB
:
8881 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
8882 &remote_protocol_packets
[PACKET_qXfer_uib
]);
8884 case TARGET_OBJECT_BTRACE
:
8885 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
8886 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
8892 /* Note: a zero OFFSET and LEN can be used to query the minimum
8894 if (offset
== 0 && len
== 0)
8895 return (get_remote_packet_size ());
8896 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8897 large enough let the caller deal with it. */
8898 if (len
< get_remote_packet_size ())
8900 len
= get_remote_packet_size ();
8902 /* Except for querying the minimum buffer size, target must be open. */
8903 if (!rs
->remote_desc
)
8904 error (_("remote query is only available after target open"));
8906 gdb_assert (annex
!= NULL
);
8907 gdb_assert (readbuf
!= NULL
);
8913 /* We used one buffer char for the remote protocol q command and
8914 another for the query type. As the remote protocol encapsulation
8915 uses 4 chars plus one extra in case we are debugging
8916 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8919 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8921 /* Bad caller may have sent forbidden characters. */
8922 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8927 gdb_assert (annex
[i
] == '\0');
8929 i
= putpkt (rs
->buf
);
8933 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8934 strcpy ((char *) readbuf
, rs
->buf
);
8936 return strlen ((char *) readbuf
);
8940 remote_search_memory (struct target_ops
* ops
,
8941 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8942 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8943 CORE_ADDR
*found_addrp
)
8945 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8946 struct remote_state
*rs
= get_remote_state ();
8947 int max_size
= get_memory_write_packet_size ();
8948 struct packet_config
*packet
=
8949 &remote_protocol_packets
[PACKET_qSearch_memory
];
8950 /* Number of packet bytes used to encode the pattern;
8951 this could be more than PATTERN_LEN due to escape characters. */
8952 int escaped_pattern_len
;
8953 /* Amount of pattern that was encodable in the packet. */
8954 int used_pattern_len
;
8957 ULONGEST found_addr
;
8959 /* Don't go to the target if we don't have to.
8960 This is done before checking packet->support to avoid the possibility that
8961 a success for this edge case means the facility works in general. */
8962 if (pattern_len
> search_space_len
)
8964 if (pattern_len
== 0)
8966 *found_addrp
= start_addr
;
8970 /* If we already know the packet isn't supported, fall back to the simple
8971 way of searching memory. */
8973 if (packet
->support
== PACKET_DISABLE
)
8975 /* Target doesn't provided special support, fall back and use the
8976 standard support (copy memory and do the search here). */
8977 return simple_search_memory (ops
, start_addr
, search_space_len
,
8978 pattern
, pattern_len
, found_addrp
);
8981 /* Make sure the remote is pointing at the right process. */
8982 set_general_process ();
8984 /* Insert header. */
8985 i
= snprintf (rs
->buf
, max_size
,
8986 "qSearch:memory:%s;%s;",
8987 phex_nz (start_addr
, addr_size
),
8988 phex_nz (search_space_len
, sizeof (search_space_len
)));
8989 max_size
-= (i
+ 1);
8991 /* Escape as much data as fits into rs->buf. */
8992 escaped_pattern_len
=
8993 remote_escape_output (pattern
, pattern_len
, (gdb_byte
*) rs
->buf
+ i
,
8994 &used_pattern_len
, max_size
);
8996 /* Bail if the pattern is too large. */
8997 if (used_pattern_len
!= pattern_len
)
8998 error (_("Pattern is too large to transmit to remote target."));
9000 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9001 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9002 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9004 /* The request may not have worked because the command is not
9005 supported. If so, fall back to the simple way. */
9006 if (packet
->support
== PACKET_DISABLE
)
9008 return simple_search_memory (ops
, start_addr
, search_space_len
,
9009 pattern
, pattern_len
, found_addrp
);
9014 if (rs
->buf
[0] == '0')
9016 else if (rs
->buf
[0] == '1')
9019 if (rs
->buf
[1] != ',')
9020 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9021 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9022 *found_addrp
= found_addr
;
9025 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9031 remote_rcmd (char *command
,
9032 struct ui_file
*outbuf
)
9034 struct remote_state
*rs
= get_remote_state ();
9037 if (!rs
->remote_desc
)
9038 error (_("remote rcmd is only available after target open"));
9040 /* Send a NULL command across as an empty command. */
9041 if (command
== NULL
)
9044 /* The query prefix. */
9045 strcpy (rs
->buf
, "qRcmd,");
9046 p
= strchr (rs
->buf
, '\0');
9048 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9049 > get_remote_packet_size ())
9050 error (_("\"monitor\" command ``%s'' is too long."), command
);
9052 /* Encode the actual command. */
9053 bin2hex ((gdb_byte
*) command
, p
, 0);
9055 if (putpkt (rs
->buf
) < 0)
9056 error (_("Communication problem with target."));
9058 /* get/display the response */
9063 /* XXX - see also remote_get_noisy_reply(). */
9064 QUIT
; /* Allow user to bail out with ^C. */
9066 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9068 /* Timeout. Continue to (try to) read responses.
9069 This is better than stopping with an error, assuming the stub
9070 is still executing the (long) monitor command.
9071 If needed, the user can interrupt gdb using C-c, obtaining
9072 an effect similar to stop on timeout. */
9077 error (_("Target does not support this command."));
9078 if (buf
[0] == 'O' && buf
[1] != 'K')
9080 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9083 if (strcmp (buf
, "OK") == 0)
9085 if (strlen (buf
) == 3 && buf
[0] == 'E'
9086 && isdigit (buf
[1]) && isdigit (buf
[2]))
9088 error (_("Protocol error with Rcmd"));
9090 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9092 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9094 fputc_unfiltered (c
, outbuf
);
9100 static VEC(mem_region_s
) *
9101 remote_memory_map (struct target_ops
*ops
)
9103 VEC(mem_region_s
) *result
= NULL
;
9104 char *text
= target_read_stralloc (¤t_target
,
9105 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9109 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9111 result
= parse_memory_map (text
);
9112 do_cleanups (back_to
);
9119 packet_command (char *args
, int from_tty
)
9121 struct remote_state
*rs
= get_remote_state ();
9123 if (!rs
->remote_desc
)
9124 error (_("command can only be used with remote target"));
9127 error (_("remote-packet command requires packet text as argument"));
9129 puts_filtered ("sending: ");
9130 print_packet (args
);
9131 puts_filtered ("\n");
9134 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9135 puts_filtered ("received: ");
9136 print_packet (rs
->buf
);
9137 puts_filtered ("\n");
9141 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9143 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9145 static void threadset_test_cmd (char *cmd
, int tty
);
9147 static void threadalive_test (char *cmd
, int tty
);
9149 static void threadlist_test_cmd (char *cmd
, int tty
);
9151 int get_and_display_threadinfo (threadref
*ref
);
9153 static void threadinfo_test_cmd (char *cmd
, int tty
);
9155 static int thread_display_step (threadref
*ref
, void *context
);
9157 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9159 static void init_remote_threadtests (void);
9161 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9164 threadset_test_cmd (char *cmd
, int tty
)
9166 int sample_thread
= SAMPLE_THREAD
;
9168 printf_filtered (_("Remote threadset test\n"));
9169 set_general_thread (sample_thread
);
9174 threadalive_test (char *cmd
, int tty
)
9176 int sample_thread
= SAMPLE_THREAD
;
9177 int pid
= ptid_get_pid (inferior_ptid
);
9178 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
9180 if (remote_thread_alive (ptid
))
9181 printf_filtered ("PASS: Thread alive test\n");
9183 printf_filtered ("FAIL: Thread alive test\n");
9186 void output_threadid (char *title
, threadref
*ref
);
9189 output_threadid (char *title
, threadref
*ref
)
9193 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9195 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9199 threadlist_test_cmd (char *cmd
, int tty
)
9202 threadref nextthread
;
9203 int done
, result_count
;
9204 threadref threadlist
[3];
9206 printf_filtered ("Remote Threadlist test\n");
9207 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9208 &result_count
, &threadlist
[0]))
9209 printf_filtered ("FAIL: threadlist test\n");
9212 threadref
*scan
= threadlist
;
9213 threadref
*limit
= scan
+ result_count
;
9215 while (scan
< limit
)
9216 output_threadid (" thread ", scan
++);
9221 display_thread_info (struct gdb_ext_thread_info
*info
)
9223 output_threadid ("Threadid: ", &info
->threadid
);
9224 printf_filtered ("Name: %s\n ", info
->shortname
);
9225 printf_filtered ("State: %s\n", info
->display
);
9226 printf_filtered ("other: %s\n\n", info
->more_display
);
9230 get_and_display_threadinfo (threadref
*ref
)
9234 struct gdb_ext_thread_info threadinfo
;
9236 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9237 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9238 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9239 display_thread_info (&threadinfo
);
9244 threadinfo_test_cmd (char *cmd
, int tty
)
9246 int athread
= SAMPLE_THREAD
;
9250 int_to_threadref (&thread
, athread
);
9251 printf_filtered ("Remote Threadinfo test\n");
9252 if (!get_and_display_threadinfo (&thread
))
9253 printf_filtered ("FAIL cannot get thread info\n");
9257 thread_display_step (threadref
*ref
, void *context
)
9259 /* output_threadid(" threadstep ",ref); *//* simple test */
9260 return get_and_display_threadinfo (ref
);
9264 threadlist_update_test_cmd (char *cmd
, int tty
)
9266 printf_filtered ("Remote Threadlist update test\n");
9267 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9271 init_remote_threadtests (void)
9273 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9274 _("Fetch and print the remote list of "
9275 "thread identifiers, one pkt only"));
9276 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9277 _("Fetch and display info about one thread"));
9278 add_com ("tset", class_obscure
, threadset_test_cmd
,
9279 _("Test setting to a different thread"));
9280 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9281 _("Iterate through updating all remote thread info"));
9282 add_com ("talive", class_obscure
, threadalive_test
,
9283 _(" Remote thread alive test "));
9288 /* Convert a thread ID to a string. Returns the string in a static
9292 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9294 static char buf
[64];
9295 struct remote_state
*rs
= get_remote_state ();
9297 if (ptid_equal (ptid
, null_ptid
))
9298 return normal_pid_to_str (ptid
);
9299 else if (ptid_is_pid (ptid
))
9301 /* Printing an inferior target id. */
9303 /* When multi-process extensions are off, there's no way in the
9304 remote protocol to know the remote process id, if there's any
9305 at all. There's one exception --- when we're connected with
9306 target extended-remote, and we manually attached to a process
9307 with "attach PID". We don't record anywhere a flag that
9308 allows us to distinguish that case from the case of
9309 connecting with extended-remote and the stub already being
9310 attached to a process, and reporting yes to qAttached, hence
9311 no smart special casing here. */
9312 if (!remote_multi_process_p (rs
))
9314 xsnprintf (buf
, sizeof buf
, "Remote target");
9318 return normal_pid_to_str (ptid
);
9322 if (ptid_equal (magic_null_ptid
, ptid
))
9323 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9324 else if (rs
->extended
&& remote_multi_process_p (rs
))
9325 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9326 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
9328 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9329 ptid_get_tid (ptid
));
9334 /* Get the address of the thread local variable in OBJFILE which is
9335 stored at OFFSET within the thread local storage for thread PTID. */
9338 remote_get_thread_local_address (struct target_ops
*ops
,
9339 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9341 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
9343 struct remote_state
*rs
= get_remote_state ();
9345 char *endp
= rs
->buf
+ get_remote_packet_size ();
9346 enum packet_result result
;
9348 strcpy (p
, "qGetTLSAddr:");
9350 p
= write_ptid (p
, endp
, ptid
);
9352 p
+= hexnumstr (p
, offset
);
9354 p
+= hexnumstr (p
, lm
);
9358 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9359 result
= packet_ok (rs
->buf
,
9360 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9361 if (result
== PACKET_OK
)
9365 unpack_varlen_hex (rs
->buf
, &result
);
9368 else if (result
== PACKET_UNKNOWN
)
9369 throw_error (TLS_GENERIC_ERROR
,
9370 _("Remote target doesn't support qGetTLSAddr packet"));
9372 throw_error (TLS_GENERIC_ERROR
,
9373 _("Remote target failed to process qGetTLSAddr request"));
9376 throw_error (TLS_GENERIC_ERROR
,
9377 _("TLS not supported or disabled on this target"));
9382 /* Provide thread local base, i.e. Thread Information Block address.
9383 Returns 1 if ptid is found and thread_local_base is non zero. */
9386 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
9388 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
9390 struct remote_state
*rs
= get_remote_state ();
9392 char *endp
= rs
->buf
+ get_remote_packet_size ();
9393 enum packet_result result
;
9395 strcpy (p
, "qGetTIBAddr:");
9397 p
= write_ptid (p
, endp
, ptid
);
9401 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9402 result
= packet_ok (rs
->buf
,
9403 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9404 if (result
== PACKET_OK
)
9408 unpack_varlen_hex (rs
->buf
, &result
);
9410 *addr
= (CORE_ADDR
) result
;
9413 else if (result
== PACKET_UNKNOWN
)
9414 error (_("Remote target doesn't support qGetTIBAddr packet"));
9416 error (_("Remote target failed to process qGetTIBAddr request"));
9419 error (_("qGetTIBAddr not supported or disabled on this target"));
9424 /* Support for inferring a target description based on the current
9425 architecture and the size of a 'g' packet. While the 'g' packet
9426 can have any size (since optional registers can be left off the
9427 end), some sizes are easily recognizable given knowledge of the
9428 approximate architecture. */
9430 struct remote_g_packet_guess
9433 const struct target_desc
*tdesc
;
9435 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9436 DEF_VEC_O(remote_g_packet_guess_s
);
9438 struct remote_g_packet_data
9440 VEC(remote_g_packet_guess_s
) *guesses
;
9443 static struct gdbarch_data
*remote_g_packet_data_handle
;
9446 remote_g_packet_data_init (struct obstack
*obstack
)
9448 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9452 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9453 const struct target_desc
*tdesc
)
9455 struct remote_g_packet_data
*data
9456 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9457 struct remote_g_packet_guess new_guess
, *guess
;
9460 gdb_assert (tdesc
!= NULL
);
9463 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9465 if (guess
->bytes
== bytes
)
9466 internal_error (__FILE__
, __LINE__
,
9467 _("Duplicate g packet description added for size %d"),
9470 new_guess
.bytes
= bytes
;
9471 new_guess
.tdesc
= tdesc
;
9472 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9475 /* Return 1 if remote_read_description would do anything on this target
9476 and architecture, 0 otherwise. */
9479 remote_read_description_p (struct target_ops
*target
)
9481 struct remote_g_packet_data
*data
9482 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9484 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9490 static const struct target_desc
*
9491 remote_read_description (struct target_ops
*target
)
9493 struct remote_g_packet_data
*data
9494 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9496 /* Do not try this during initial connection, when we do not know
9497 whether there is a running but stopped thread. */
9498 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9501 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9503 struct remote_g_packet_guess
*guess
;
9505 int bytes
= send_g_packet ();
9508 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9510 if (guess
->bytes
== bytes
)
9511 return guess
->tdesc
;
9513 /* We discard the g packet. A minor optimization would be to
9514 hold on to it, and fill the register cache once we have selected
9515 an architecture, but it's too tricky to do safely. */
9521 /* Remote file transfer support. This is host-initiated I/O, not
9522 target-initiated; for target-initiated, see remote-fileio.c. */
9524 /* If *LEFT is at least the length of STRING, copy STRING to
9525 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9526 decrease *LEFT. Otherwise raise an error. */
9529 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9531 int len
= strlen (string
);
9534 error (_("Packet too long for target."));
9536 memcpy (*buffer
, string
, len
);
9540 /* NUL-terminate the buffer as a convenience, if there is
9546 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9547 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9548 decrease *LEFT. Otherwise raise an error. */
9551 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9554 if (2 * len
> *left
)
9555 error (_("Packet too long for target."));
9557 bin2hex (bytes
, *buffer
, len
);
9561 /* NUL-terminate the buffer as a convenience, if there is
9567 /* If *LEFT is large enough, convert VALUE to hex and add it to
9568 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9569 decrease *LEFT. Otherwise raise an error. */
9572 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9574 int len
= hexnumlen (value
);
9577 error (_("Packet too long for target."));
9579 hexnumstr (*buffer
, value
);
9583 /* NUL-terminate the buffer as a convenience, if there is
9589 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9590 value, *REMOTE_ERRNO to the remote error number or zero if none
9591 was included, and *ATTACHMENT to point to the start of the annex
9592 if any. The length of the packet isn't needed here; there may
9593 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9595 Return 0 if the packet could be parsed, -1 if it could not. If
9596 -1 is returned, the other variables may not be initialized. */
9599 remote_hostio_parse_result (char *buffer
, int *retcode
,
9600 int *remote_errno
, char **attachment
)
9607 if (buffer
[0] != 'F')
9611 *retcode
= strtol (&buffer
[1], &p
, 16);
9612 if (errno
!= 0 || p
== &buffer
[1])
9615 /* Check for ",errno". */
9619 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9620 if (errno
!= 0 || p
+ 1 == p2
)
9625 /* Check for ";attachment". If there is no attachment, the
9626 packet should end here. */
9629 *attachment
= p
+ 1;
9632 else if (*p
== '\0')
9638 /* Send a prepared I/O packet to the target and read its response.
9639 The prepared packet is in the global RS->BUF before this function
9640 is called, and the answer is there when we return.
9642 COMMAND_BYTES is the length of the request to send, which may include
9643 binary data. WHICH_PACKET is the packet configuration to check
9644 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9645 is set to the error number and -1 is returned. Otherwise the value
9646 returned by the function is returned.
9648 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9649 attachment is expected; an error will be reported if there's a
9650 mismatch. If one is found, *ATTACHMENT will be set to point into
9651 the packet buffer and *ATTACHMENT_LEN will be set to the
9652 attachment's length. */
9655 remote_hostio_send_command (int command_bytes
, int which_packet
,
9656 int *remote_errno
, char **attachment
,
9657 int *attachment_len
)
9659 struct remote_state
*rs
= get_remote_state ();
9660 int ret
, bytes_read
;
9661 char *attachment_tmp
;
9663 if (!rs
->remote_desc
9664 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9666 *remote_errno
= FILEIO_ENOSYS
;
9670 putpkt_binary (rs
->buf
, command_bytes
);
9671 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9673 /* If it timed out, something is wrong. Don't try to parse the
9677 *remote_errno
= FILEIO_EINVAL
;
9681 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9684 *remote_errno
= FILEIO_EINVAL
;
9686 case PACKET_UNKNOWN
:
9687 *remote_errno
= FILEIO_ENOSYS
;
9693 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9696 *remote_errno
= FILEIO_EINVAL
;
9700 /* Make sure we saw an attachment if and only if we expected one. */
9701 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9702 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9704 *remote_errno
= FILEIO_EINVAL
;
9708 /* If an attachment was found, it must point into the packet buffer;
9709 work out how many bytes there were. */
9710 if (attachment_tmp
!= NULL
)
9712 *attachment
= attachment_tmp
;
9713 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9719 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9720 remote file descriptor, or -1 if an error occurs (and set
9724 remote_hostio_open (const char *filename
, int flags
, int mode
,
9727 struct remote_state
*rs
= get_remote_state ();
9729 int left
= get_remote_packet_size () - 1;
9731 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9733 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9735 remote_buffer_add_string (&p
, &left
, ",");
9737 remote_buffer_add_int (&p
, &left
, flags
);
9738 remote_buffer_add_string (&p
, &left
, ",");
9740 remote_buffer_add_int (&p
, &left
, mode
);
9742 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9743 remote_errno
, NULL
, NULL
);
9746 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9747 Return the number of bytes written, or -1 if an error occurs (and
9748 set *REMOTE_ERRNO). */
9751 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9752 ULONGEST offset
, int *remote_errno
)
9754 struct remote_state
*rs
= get_remote_state ();
9756 int left
= get_remote_packet_size ();
9759 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9761 remote_buffer_add_int (&p
, &left
, fd
);
9762 remote_buffer_add_string (&p
, &left
, ",");
9764 remote_buffer_add_int (&p
, &left
, offset
);
9765 remote_buffer_add_string (&p
, &left
, ",");
9767 p
+= remote_escape_output (write_buf
, len
, (gdb_byte
*) p
, &out_len
,
9768 get_remote_packet_size () - (p
- rs
->buf
));
9770 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9771 remote_errno
, NULL
, NULL
);
9774 /* Read up to LEN bytes FD on the remote target into READ_BUF
9775 Return the number of bytes read, or -1 if an error occurs (and
9776 set *REMOTE_ERRNO). */
9779 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9780 ULONGEST offset
, int *remote_errno
)
9782 struct remote_state
*rs
= get_remote_state ();
9785 int left
= get_remote_packet_size ();
9786 int ret
, attachment_len
;
9789 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9791 remote_buffer_add_int (&p
, &left
, fd
);
9792 remote_buffer_add_string (&p
, &left
, ",");
9794 remote_buffer_add_int (&p
, &left
, len
);
9795 remote_buffer_add_string (&p
, &left
, ",");
9797 remote_buffer_add_int (&p
, &left
, offset
);
9799 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9800 remote_errno
, &attachment
,
9806 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9808 if (read_len
!= ret
)
9809 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9814 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9815 (and set *REMOTE_ERRNO). */
9818 remote_hostio_close (int fd
, int *remote_errno
)
9820 struct remote_state
*rs
= get_remote_state ();
9822 int left
= get_remote_packet_size () - 1;
9824 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9826 remote_buffer_add_int (&p
, &left
, fd
);
9828 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9829 remote_errno
, NULL
, NULL
);
9832 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9833 occurs (and set *REMOTE_ERRNO). */
9836 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9838 struct remote_state
*rs
= get_remote_state ();
9840 int left
= get_remote_packet_size () - 1;
9842 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9844 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9847 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9848 remote_errno
, NULL
, NULL
);
9851 /* Read value of symbolic link FILENAME on the remote target. Return
9852 a null-terminated string allocated via xmalloc, or NULL if an error
9853 occurs (and set *REMOTE_ERRNO). */
9856 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9858 struct remote_state
*rs
= get_remote_state ();
9861 int left
= get_remote_packet_size ();
9862 int len
, attachment_len
;
9866 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9868 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9871 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9872 remote_errno
, &attachment
,
9878 ret
= xmalloc (len
+ 1);
9880 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9881 (gdb_byte
*) ret
, len
);
9882 if (read_len
!= len
)
9883 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9890 remote_fileio_errno_to_host (int errnum
)
9914 case FILEIO_ENOTDIR
:
9934 case FILEIO_ENAMETOOLONG
:
9935 return ENAMETOOLONG
;
9941 remote_hostio_error (int errnum
)
9943 int host_error
= remote_fileio_errno_to_host (errnum
);
9945 if (host_error
== -1)
9946 error (_("Unknown remote I/O error %d"), errnum
);
9948 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9952 remote_hostio_close_cleanup (void *opaque
)
9954 int fd
= *(int *) opaque
;
9957 remote_hostio_close (fd
, &remote_errno
);
9962 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9964 const char *filename
= bfd_get_filename (abfd
);
9965 int fd
, remote_errno
;
9968 gdb_assert (remote_filename_p (filename
));
9970 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9973 errno
= remote_fileio_errno_to_host (remote_errno
);
9974 bfd_set_error (bfd_error_system_call
);
9978 stream
= xmalloc (sizeof (int));
9984 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9986 int fd
= *(int *)stream
;
9991 /* Ignore errors on close; these may happen if the remote
9992 connection was already torn down. */
9993 remote_hostio_close (fd
, &remote_errno
);
9995 /* Zero means success. */
10000 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
10001 file_ptr nbytes
, file_ptr offset
)
10003 int fd
= *(int *)stream
;
10005 file_ptr pos
, bytes
;
10008 while (nbytes
> pos
)
10010 bytes
= remote_hostio_pread (fd
, (gdb_byte
*) buf
+ pos
, nbytes
- pos
,
10011 offset
+ pos
, &remote_errno
);
10013 /* Success, but no bytes, means end-of-file. */
10017 errno
= remote_fileio_errno_to_host (remote_errno
);
10018 bfd_set_error (bfd_error_system_call
);
10029 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
10031 /* FIXME: We should probably implement remote_hostio_stat. */
10032 sb
->st_size
= INT_MAX
;
10037 remote_filename_p (const char *filename
)
10039 return strncmp (filename
,
10040 REMOTE_SYSROOT_PREFIX
,
10041 sizeof (REMOTE_SYSROOT_PREFIX
) - 1) == 0;
10045 remote_bfd_open (const char *remote_file
, const char *target
)
10047 bfd
*abfd
= gdb_bfd_openr_iovec (remote_file
, target
,
10048 remote_bfd_iovec_open
, NULL
,
10049 remote_bfd_iovec_pread
,
10050 remote_bfd_iovec_close
,
10051 remote_bfd_iovec_stat
);
10057 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10059 struct cleanup
*back_to
, *close_cleanup
;
10060 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10063 int bytes_in_buffer
;
10066 struct remote_state
*rs
= get_remote_state ();
10068 if (!rs
->remote_desc
)
10069 error (_("command can only be used with remote target"));
10071 file
= gdb_fopen_cloexec (local_file
, "rb");
10073 perror_with_name (local_file
);
10074 back_to
= make_cleanup_fclose (file
);
10076 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10078 0700, &remote_errno
);
10080 remote_hostio_error (remote_errno
);
10082 /* Send up to this many bytes at once. They won't all fit in the
10083 remote packet limit, so we'll transfer slightly fewer. */
10084 io_size
= get_remote_packet_size ();
10085 buffer
= xmalloc (io_size
);
10086 make_cleanup (xfree
, buffer
);
10088 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10090 bytes_in_buffer
= 0;
10093 while (bytes_in_buffer
|| !saw_eof
)
10097 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10098 io_size
- bytes_in_buffer
,
10103 error (_("Error reading %s."), local_file
);
10106 /* EOF. Unless there is something still in the
10107 buffer from the last iteration, we are done. */
10109 if (bytes_in_buffer
== 0)
10117 bytes
+= bytes_in_buffer
;
10118 bytes_in_buffer
= 0;
10120 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
10121 offset
, &remote_errno
);
10124 remote_hostio_error (remote_errno
);
10125 else if (retcode
== 0)
10126 error (_("Remote write of %d bytes returned 0!"), bytes
);
10127 else if (retcode
< bytes
)
10129 /* Short write. Save the rest of the read data for the next
10131 bytes_in_buffer
= bytes
- retcode
;
10132 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10138 discard_cleanups (close_cleanup
);
10139 if (remote_hostio_close (fd
, &remote_errno
))
10140 remote_hostio_error (remote_errno
);
10143 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10144 do_cleanups (back_to
);
10148 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10150 struct cleanup
*back_to
, *close_cleanup
;
10151 int fd
, remote_errno
, bytes
, io_size
;
10155 struct remote_state
*rs
= get_remote_state ();
10157 if (!rs
->remote_desc
)
10158 error (_("command can only be used with remote target"));
10160 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10162 remote_hostio_error (remote_errno
);
10164 file
= gdb_fopen_cloexec (local_file
, "wb");
10166 perror_with_name (local_file
);
10167 back_to
= make_cleanup_fclose (file
);
10169 /* Send up to this many bytes at once. They won't all fit in the
10170 remote packet limit, so we'll transfer slightly fewer. */
10171 io_size
= get_remote_packet_size ();
10172 buffer
= xmalloc (io_size
);
10173 make_cleanup (xfree
, buffer
);
10175 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10180 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
10182 /* Success, but no bytes, means end-of-file. */
10185 remote_hostio_error (remote_errno
);
10189 bytes
= fwrite (buffer
, 1, bytes
, file
);
10191 perror_with_name (local_file
);
10194 discard_cleanups (close_cleanup
);
10195 if (remote_hostio_close (fd
, &remote_errno
))
10196 remote_hostio_error (remote_errno
);
10199 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10200 do_cleanups (back_to
);
10204 remote_file_delete (const char *remote_file
, int from_tty
)
10206 int retcode
, remote_errno
;
10207 struct remote_state
*rs
= get_remote_state ();
10209 if (!rs
->remote_desc
)
10210 error (_("command can only be used with remote target"));
10212 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
10214 remote_hostio_error (remote_errno
);
10217 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10221 remote_put_command (char *args
, int from_tty
)
10223 struct cleanup
*back_to
;
10227 error_no_arg (_("file to put"));
10229 argv
= gdb_buildargv (args
);
10230 back_to
= make_cleanup_freeargv (argv
);
10231 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10232 error (_("Invalid parameters to remote put"));
10234 remote_file_put (argv
[0], argv
[1], from_tty
);
10236 do_cleanups (back_to
);
10240 remote_get_command (char *args
, int from_tty
)
10242 struct cleanup
*back_to
;
10246 error_no_arg (_("file to get"));
10248 argv
= gdb_buildargv (args
);
10249 back_to
= make_cleanup_freeargv (argv
);
10250 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10251 error (_("Invalid parameters to remote get"));
10253 remote_file_get (argv
[0], argv
[1], from_tty
);
10255 do_cleanups (back_to
);
10259 remote_delete_command (char *args
, int from_tty
)
10261 struct cleanup
*back_to
;
10265 error_no_arg (_("file to delete"));
10267 argv
= gdb_buildargv (args
);
10268 back_to
= make_cleanup_freeargv (argv
);
10269 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10270 error (_("Invalid parameters to remote delete"));
10272 remote_file_delete (argv
[0], from_tty
);
10274 do_cleanups (back_to
);
10278 remote_command (char *args
, int from_tty
)
10280 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
10284 remote_can_execute_reverse (void)
10286 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
10287 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
10294 remote_supports_non_stop (void)
10300 remote_supports_disable_randomization (void)
10302 /* Only supported in extended mode. */
10307 remote_supports_multi_process (void)
10309 struct remote_state
*rs
= get_remote_state ();
10311 /* Only extended-remote handles being attached to multiple
10312 processes, even though plain remote can use the multi-process
10313 thread id extensions, so that GDB knows the target process's
10315 return rs
->extended
&& remote_multi_process_p (rs
);
10319 remote_supports_cond_tracepoints (void)
10321 struct remote_state
*rs
= get_remote_state ();
10323 return rs
->cond_tracepoints
;
10327 remote_supports_cond_breakpoints (void)
10329 struct remote_state
*rs
= get_remote_state ();
10331 return rs
->cond_breakpoints
;
10335 remote_supports_fast_tracepoints (void)
10337 struct remote_state
*rs
= get_remote_state ();
10339 return rs
->fast_tracepoints
;
10343 remote_supports_static_tracepoints (void)
10345 struct remote_state
*rs
= get_remote_state ();
10347 return rs
->static_tracepoints
;
10351 remote_supports_install_in_trace (void)
10353 struct remote_state
*rs
= get_remote_state ();
10355 return rs
->install_in_trace
;
10359 remote_supports_enable_disable_tracepoint (void)
10361 struct remote_state
*rs
= get_remote_state ();
10363 return rs
->enable_disable_tracepoints
;
10367 remote_supports_string_tracing (void)
10369 struct remote_state
*rs
= get_remote_state ();
10371 return rs
->string_tracing
;
10375 remote_can_run_breakpoint_commands (void)
10377 struct remote_state
*rs
= get_remote_state ();
10379 return rs
->breakpoint_commands
;
10383 remote_trace_init (void)
10386 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10387 if (strcmp (target_buf
, "OK") != 0)
10388 error (_("Target does not support this command."));
10391 static void free_actions_list (char **actions_list
);
10392 static void free_actions_list_cleanup_wrapper (void *);
10394 free_actions_list_cleanup_wrapper (void *al
)
10396 free_actions_list (al
);
10400 free_actions_list (char **actions_list
)
10404 if (actions_list
== 0)
10407 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10408 xfree (actions_list
[ndx
]);
10410 xfree (actions_list
);
10413 /* Recursive routine to walk through command list including loops, and
10414 download packets for each command. */
10417 remote_download_command_source (int num
, ULONGEST addr
,
10418 struct command_line
*cmds
)
10420 struct remote_state
*rs
= get_remote_state ();
10421 struct command_line
*cmd
;
10423 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10425 QUIT
; /* Allow user to bail out with ^C. */
10426 strcpy (rs
->buf
, "QTDPsrc:");
10427 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10428 rs
->buf
+ strlen (rs
->buf
),
10429 rs
->buf_size
- strlen (rs
->buf
));
10431 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10432 if (strcmp (target_buf
, "OK"))
10433 warning (_("Target does not support source download."));
10435 if (cmd
->control_type
== while_control
10436 || cmd
->control_type
== while_stepping_control
)
10438 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10440 QUIT
; /* Allow user to bail out with ^C. */
10441 strcpy (rs
->buf
, "QTDPsrc:");
10442 encode_source_string (num
, addr
, "cmd", "end",
10443 rs
->buf
+ strlen (rs
->buf
),
10444 rs
->buf_size
- strlen (rs
->buf
));
10446 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10447 if (strcmp (target_buf
, "OK"))
10448 warning (_("Target does not support source download."));
10454 remote_download_tracepoint (struct bp_location
*loc
)
10456 #define BUF_SIZE 2048
10460 char buf
[BUF_SIZE
];
10461 char **tdp_actions
;
10462 char **stepping_actions
;
10464 struct cleanup
*old_chain
= NULL
;
10465 struct agent_expr
*aexpr
;
10466 struct cleanup
*aexpr_chain
= NULL
;
10468 struct breakpoint
*b
= loc
->owner
;
10469 struct tracepoint
*t
= (struct tracepoint
*) b
;
10471 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
10472 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10474 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10477 tpaddr
= loc
->address
;
10478 sprintf_vma (addrbuf
, tpaddr
);
10479 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10480 addrbuf
, /* address */
10481 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10482 t
->step_count
, t
->pass_count
);
10483 /* Fast tracepoints are mostly handled by the target, but we can
10484 tell the target how big of an instruction block should be moved
10486 if (b
->type
== bp_fast_tracepoint
)
10488 /* Only test for support at download time; we may not know
10489 target capabilities at definition time. */
10490 if (remote_supports_fast_tracepoints ())
10494 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10495 tpaddr
, &isize
, NULL
))
10496 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10499 /* If it passed validation at definition but fails now,
10500 something is very wrong. */
10501 internal_error (__FILE__
, __LINE__
,
10502 _("Fast tracepoint not "
10503 "valid during download"));
10506 /* Fast tracepoints are functionally identical to regular
10507 tracepoints, so don't take lack of support as a reason to
10508 give up on the trace run. */
10509 warning (_("Target does not support fast tracepoints, "
10510 "downloading %d as regular tracepoint"), b
->number
);
10512 else if (b
->type
== bp_static_tracepoint
)
10514 /* Only test for support at download time; we may not know
10515 target capabilities at definition time. */
10516 if (remote_supports_static_tracepoints ())
10518 struct static_tracepoint_marker marker
;
10520 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10521 strcat (buf
, ":S");
10523 error (_("Static tracepoint not valid during download"));
10526 /* Fast tracepoints are functionally identical to regular
10527 tracepoints, so don't take lack of support as a reason
10528 to give up on the trace run. */
10529 error (_("Target does not support static tracepoints"));
10531 /* If the tracepoint has a conditional, make it into an agent
10532 expression and append to the definition. */
10535 /* Only test support at download time, we may not know target
10536 capabilities at definition time. */
10537 if (remote_supports_cond_tracepoints ())
10539 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10540 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10541 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10543 pkt
= buf
+ strlen (buf
);
10544 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10545 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10547 do_cleanups (aexpr_chain
);
10550 warning (_("Target does not support conditional tracepoints, "
10551 "ignoring tp %d cond"), b
->number
);
10554 if (b
->commands
|| *default_collect
)
10557 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10558 if (strcmp (target_buf
, "OK"))
10559 error (_("Target does not support tracepoints."));
10561 /* do_single_steps (t); */
10564 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10566 QUIT
; /* Allow user to bail out with ^C. */
10567 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10568 b
->number
, addrbuf
, /* address */
10570 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10573 remote_get_noisy_reply (&target_buf
,
10575 if (strcmp (target_buf
, "OK"))
10576 error (_("Error on target while setting tracepoints."));
10579 if (stepping_actions
)
10581 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10583 QUIT
; /* Allow user to bail out with ^C. */
10584 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10585 b
->number
, addrbuf
, /* address */
10586 ((ndx
== 0) ? "S" : ""),
10587 stepping_actions
[ndx
],
10588 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10590 remote_get_noisy_reply (&target_buf
,
10592 if (strcmp (target_buf
, "OK"))
10593 error (_("Error on target while setting tracepoints."));
10597 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10600 if (b
->addr_string
)
10602 strcpy (buf
, "QTDPsrc:");
10603 encode_source_string (b
->number
, loc
->address
,
10604 "at", b
->addr_string
, buf
+ strlen (buf
),
10605 2048 - strlen (buf
));
10608 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10609 if (strcmp (target_buf
, "OK"))
10610 warning (_("Target does not support source download."));
10612 if (b
->cond_string
)
10614 strcpy (buf
, "QTDPsrc:");
10615 encode_source_string (b
->number
, loc
->address
,
10616 "cond", b
->cond_string
, buf
+ strlen (buf
),
10617 2048 - strlen (buf
));
10619 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10620 if (strcmp (target_buf
, "OK"))
10621 warning (_("Target does not support source download."));
10623 remote_download_command_source (b
->number
, loc
->address
,
10624 breakpoint_commands (b
));
10627 do_cleanups (old_chain
);
10631 remote_can_download_tracepoint (void)
10633 struct remote_state
*rs
= get_remote_state ();
10634 struct trace_status
*ts
;
10637 /* Don't try to install tracepoints until we've relocated our
10638 symbols, and fetched and merged the target's tracepoint list with
10640 if (rs
->starting_up
)
10643 ts
= current_trace_status ();
10644 status
= remote_get_trace_status (ts
);
10646 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10649 /* If we are in a tracing experiment, but remote stub doesn't support
10650 installing tracepoint in trace, we have to return. */
10651 if (!remote_supports_install_in_trace ())
10659 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10661 struct remote_state
*rs
= get_remote_state ();
10664 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10665 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10667 p
= rs
->buf
+ strlen (rs
->buf
);
10668 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10669 error (_("Trace state variable name too long for tsv definition packet"));
10670 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10673 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10674 if (*target_buf
== '\0')
10675 error (_("Target does not support this command."));
10676 if (strcmp (target_buf
, "OK") != 0)
10677 error (_("Error on target while downloading trace state variable."));
10681 remote_enable_tracepoint (struct bp_location
*location
)
10683 struct remote_state
*rs
= get_remote_state ();
10686 sprintf_vma (addr_buf
, location
->address
);
10687 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10688 location
->owner
->number
, addr_buf
);
10690 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10691 if (*rs
->buf
== '\0')
10692 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10693 if (strcmp (rs
->buf
, "OK") != 0)
10694 error (_("Error on target while enabling tracepoint."));
10698 remote_disable_tracepoint (struct bp_location
*location
)
10700 struct remote_state
*rs
= get_remote_state ();
10703 sprintf_vma (addr_buf
, location
->address
);
10704 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10705 location
->owner
->number
, addr_buf
);
10707 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10708 if (*rs
->buf
== '\0')
10709 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10710 if (strcmp (rs
->buf
, "OK") != 0)
10711 error (_("Error on target while disabling tracepoint."));
10715 remote_trace_set_readonly_regions (void)
10719 bfd_size_type size
;
10725 return; /* No information to give. */
10727 strcpy (target_buf
, "QTro");
10728 offset
= strlen (target_buf
);
10729 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10731 char tmp1
[40], tmp2
[40];
10734 if ((s
->flags
& SEC_LOAD
) == 0 ||
10735 /* (s->flags & SEC_CODE) == 0 || */
10736 (s
->flags
& SEC_READONLY
) == 0)
10740 vma
= bfd_get_section_vma (abfd
, s
);
10741 size
= bfd_get_section_size (s
);
10742 sprintf_vma (tmp1
, vma
);
10743 sprintf_vma (tmp2
, vma
+ size
);
10744 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10745 if (offset
+ sec_length
+ 1 > target_buf_size
)
10747 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10750 Too many sections for read-only sections definition packet."));
10753 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10755 offset
+= sec_length
;
10759 putpkt (target_buf
);
10760 getpkt (&target_buf
, &target_buf_size
, 0);
10765 remote_trace_start (void)
10767 putpkt ("QTStart");
10768 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10769 if (*target_buf
== '\0')
10770 error (_("Target does not support this command."));
10771 if (strcmp (target_buf
, "OK") != 0)
10772 error (_("Bogus reply from target: %s"), target_buf
);
10776 remote_get_trace_status (struct trace_status
*ts
)
10778 /* Initialize it just to avoid a GCC false warning. */
10780 /* FIXME we need to get register block size some other way. */
10781 extern int trace_regblock_size
;
10782 volatile struct gdb_exception ex
;
10783 enum packet_result result
;
10785 if (remote_protocol_packets
[PACKET_qTStatus
].support
== PACKET_DISABLE
)
10788 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10790 putpkt ("qTStatus");
10792 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10794 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10798 if (ex
.error
!= TARGET_CLOSE_ERROR
)
10800 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10803 throw_exception (ex
);
10806 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
10808 /* If the remote target doesn't do tracing, flag it. */
10809 if (result
== PACKET_UNKNOWN
)
10812 /* We're working with a live target. */
10813 ts
->filename
= NULL
;
10816 error (_("Bogus trace status reply from target: %s"), target_buf
);
10818 /* Function 'parse_trace_status' sets default value of each field of
10819 'ts' at first, so we don't have to do it here. */
10820 parse_trace_status (p
, ts
);
10822 return ts
->running
;
10826 remote_get_tracepoint_status (struct breakpoint
*bp
,
10827 struct uploaded_tp
*utp
)
10829 struct remote_state
*rs
= get_remote_state ();
10831 struct bp_location
*loc
;
10832 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10833 size_t size
= get_remote_packet_size ();
10837 tp
->base
.hit_count
= 0;
10838 tp
->traceframe_usage
= 0;
10839 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10841 /* If the tracepoint was never downloaded, don't go asking for
10843 if (tp
->number_on_target
== 0)
10845 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10846 phex_nz (loc
->address
, 0));
10848 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10849 if (reply
&& *reply
)
10852 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10858 utp
->hit_count
= 0;
10859 utp
->traceframe_usage
= 0;
10860 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10861 phex_nz (utp
->addr
, 0));
10863 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10864 if (reply
&& *reply
)
10867 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10873 remote_trace_stop (void)
10876 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10877 if (*target_buf
== '\0')
10878 error (_("Target does not support this command."));
10879 if (strcmp (target_buf
, "OK") != 0)
10880 error (_("Bogus reply from target: %s"), target_buf
);
10884 remote_trace_find (enum trace_find_type type
, int num
,
10885 CORE_ADDR addr1
, CORE_ADDR addr2
,
10888 struct remote_state
*rs
= get_remote_state ();
10889 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10891 int target_frameno
= -1, target_tracept
= -1;
10893 /* Lookups other than by absolute frame number depend on the current
10894 trace selected, so make sure it is correct on the remote end
10896 if (type
!= tfind_number
)
10897 set_remote_traceframe ();
10900 strcpy (p
, "QTFrame:");
10901 p
= strchr (p
, '\0');
10905 xsnprintf (p
, endbuf
- p
, "%x", num
);
10908 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
10911 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
10914 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
10915 phex_nz (addr2
, 0));
10917 case tfind_outside
:
10918 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
10919 phex_nz (addr2
, 0));
10922 error (_("Unknown trace find type %d"), type
);
10926 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
10927 if (*reply
== '\0')
10928 error (_("Target does not support this command."));
10930 while (reply
&& *reply
)
10935 target_frameno
= (int) strtol (p
, &reply
, 16);
10937 error (_("Unable to parse trace frame number"));
10938 /* Don't update our remote traceframe number cache on failure
10939 to select a remote traceframe. */
10940 if (target_frameno
== -1)
10945 target_tracept
= (int) strtol (p
, &reply
, 16);
10947 error (_("Unable to parse tracepoint number"));
10949 case 'O': /* "OK"? */
10950 if (reply
[1] == 'K' && reply
[2] == '\0')
10953 error (_("Bogus reply from target: %s"), reply
);
10956 error (_("Bogus reply from target: %s"), reply
);
10959 *tpp
= target_tracept
;
10961 rs
->remote_traceframe_number
= target_frameno
;
10962 return target_frameno
;
10966 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10968 struct remote_state
*rs
= get_remote_state ();
10972 set_remote_traceframe ();
10974 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
10976 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10977 if (reply
&& *reply
)
10981 unpack_varlen_hex (reply
+ 1, &uval
);
10982 *val
= (LONGEST
) uval
;
10990 remote_save_trace_data (const char *filename
)
10992 struct remote_state
*rs
= get_remote_state ();
10996 strcpy (p
, "QTSave:");
10998 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10999 error (_("Remote file name too long for trace save packet"));
11000 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
11003 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11004 if (*reply
== '\0')
11005 error (_("Target does not support this command."));
11006 if (strcmp (reply
, "OK") != 0)
11007 error (_("Bogus reply from target: %s"), reply
);
11011 /* This is basically a memory transfer, but needs to be its own packet
11012 because we don't know how the target actually organizes its trace
11013 memory, plus we want to be able to ask for as much as possible, but
11014 not be unhappy if we don't get as much as we ask for. */
11017 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11019 struct remote_state
*rs
= get_remote_state ();
11025 strcpy (p
, "qTBuffer:");
11027 p
+= hexnumstr (p
, offset
);
11029 p
+= hexnumstr (p
, len
);
11033 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11034 if (reply
&& *reply
)
11036 /* 'l' by itself means we're at the end of the buffer and
11037 there is nothing more to get. */
11041 /* Convert the reply into binary. Limit the number of bytes to
11042 convert according to our passed-in buffer size, rather than
11043 what was returned in the packet; if the target is
11044 unexpectedly generous and gives us a bigger reply than we
11045 asked for, we don't want to crash. */
11046 rslt
= hex2bin (target_buf
, buf
, len
);
11050 /* Something went wrong, flag as an error. */
11055 remote_set_disconnected_tracing (int val
)
11057 struct remote_state
*rs
= get_remote_state ();
11059 if (rs
->disconnected_tracing
)
11063 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11065 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11066 if (*reply
== '\0')
11067 error (_("Target does not support this command."));
11068 if (strcmp (reply
, "OK") != 0)
11069 error (_("Bogus reply from target: %s"), reply
);
11072 warning (_("Target does not support disconnected tracing."));
11076 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11078 struct thread_info
*info
= find_thread_ptid (ptid
);
11080 if (info
&& info
->private)
11081 return info
->private->core
;
11086 remote_set_circular_trace_buffer (int val
)
11088 struct remote_state
*rs
= get_remote_state ();
11091 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11093 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11094 if (*reply
== '\0')
11095 error (_("Target does not support this command."));
11096 if (strcmp (reply
, "OK") != 0)
11097 error (_("Bogus reply from target: %s"), reply
);
11100 static struct traceframe_info
*
11101 remote_traceframe_info (void)
11105 text
= target_read_stralloc (¤t_target
,
11106 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11109 struct traceframe_info
*info
;
11110 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11112 info
= parse_traceframe_info (text
);
11113 do_cleanups (back_to
);
11120 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11121 instruction on which a fast tracepoint may be placed. Returns -1
11122 if the packet is not supported, and 0 if the minimum instruction
11123 length is unknown. */
11126 remote_get_min_fast_tracepoint_insn_len (void)
11128 struct remote_state
*rs
= get_remote_state ();
11131 /* If we're not debugging a process yet, the IPA can't be
11133 if (!target_has_execution
)
11136 /* Make sure the remote is pointing at the right process. */
11137 set_general_process ();
11139 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11141 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11142 if (*reply
== '\0')
11146 ULONGEST min_insn_len
;
11148 unpack_varlen_hex (reply
, &min_insn_len
);
11150 return (int) min_insn_len
;
11155 remote_set_trace_buffer_size (LONGEST val
)
11157 if (remote_protocol_packets
[PACKET_QTBuffer_size
].support
11160 struct remote_state
*rs
= get_remote_state ();
11161 char *buf
= rs
->buf
;
11162 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11163 enum packet_result result
;
11165 gdb_assert (val
>= 0 || val
== -1);
11166 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11167 /* Send -1 as literal "-1" to avoid host size dependency. */
11171 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11174 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11177 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11178 result
= packet_ok (rs
->buf
,
11179 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11181 if (result
!= PACKET_OK
)
11182 warning (_("Bogus reply from target: %s"), rs
->buf
);
11187 remote_set_trace_notes (const char *user
, const char *notes
,
11188 const char *stop_notes
)
11190 struct remote_state
*rs
= get_remote_state ();
11192 char *buf
= rs
->buf
;
11193 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11196 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11199 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11200 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, 0);
11206 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11207 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, 0);
11213 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11214 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, 0);
11218 /* Ensure the buffer is terminated. */
11222 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11223 if (*reply
== '\0')
11226 if (strcmp (reply
, "OK") != 0)
11227 error (_("Bogus reply from target: %s"), reply
);
11233 remote_use_agent (int use
)
11235 if (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
)
11237 struct remote_state
*rs
= get_remote_state ();
11239 /* If the stub supports QAgent. */
11240 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11242 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11244 if (strcmp (rs
->buf
, "OK") == 0)
11255 remote_can_use_agent (void)
11257 return (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
);
11260 struct btrace_target_info
11262 /* The ptid of the traced thread. */
11266 /* Check whether the target supports branch tracing. */
11269 remote_supports_btrace (void)
11271 if (remote_protocol_packets
[PACKET_Qbtrace_off
].support
!= PACKET_ENABLE
)
11273 if (remote_protocol_packets
[PACKET_Qbtrace_bts
].support
!= PACKET_ENABLE
)
11275 if (remote_protocol_packets
[PACKET_qXfer_btrace
].support
!= PACKET_ENABLE
)
11281 /* Enable branch tracing. */
11283 static struct btrace_target_info
*
11284 remote_enable_btrace (ptid_t ptid
)
11286 struct btrace_target_info
*tinfo
= NULL
;
11287 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
11288 struct remote_state
*rs
= get_remote_state ();
11289 char *buf
= rs
->buf
;
11290 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11292 if (packet
->support
!= PACKET_ENABLE
)
11293 error (_("Target does not support branch tracing."));
11295 set_general_thread (ptid
);
11297 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11299 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11301 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11303 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11304 error (_("Could not enable branch tracing for %s: %s"),
11305 target_pid_to_str (ptid
), rs
->buf
+ 2);
11307 error (_("Could not enable branch tracing for %s."),
11308 target_pid_to_str (ptid
));
11311 tinfo
= xzalloc (sizeof (*tinfo
));
11312 tinfo
->ptid
= ptid
;
11317 /* Disable branch tracing. */
11320 remote_disable_btrace (struct btrace_target_info
*tinfo
)
11322 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
11323 struct remote_state
*rs
= get_remote_state ();
11324 char *buf
= rs
->buf
;
11325 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11327 if (packet
->support
!= PACKET_ENABLE
)
11328 error (_("Target does not support branch tracing."));
11330 set_general_thread (tinfo
->ptid
);
11332 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11334 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11336 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11338 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11339 error (_("Could not disable branch tracing for %s: %s"),
11340 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
11342 error (_("Could not disable branch tracing for %s."),
11343 target_pid_to_str (tinfo
->ptid
));
11349 /* Teardown branch tracing. */
11352 remote_teardown_btrace (struct btrace_target_info
*tinfo
)
11354 /* We must not talk to the target during teardown. */
11358 /* Read the branch trace. */
11360 static VEC (btrace_block_s
) *
11361 remote_read_btrace (struct btrace_target_info
*tinfo
,
11362 enum btrace_read_type type
)
11364 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
11365 struct remote_state
*rs
= get_remote_state ();
11366 VEC (btrace_block_s
) *btrace
= NULL
;
11370 if (packet
->support
!= PACKET_ENABLE
)
11371 error (_("Target does not support branch tracing."));
11373 #if !defined(HAVE_LIBEXPAT)
11374 error (_("Cannot process branch tracing result. XML parsing not supported."));
11379 case btrace_read_all
:
11382 case btrace_read_new
:
11386 internal_error (__FILE__
, __LINE__
,
11387 _("Bad branch tracing read type: %u."),
11388 (unsigned int) type
);
11391 xml
= target_read_stralloc (¤t_target
,
11392 TARGET_OBJECT_BTRACE
, annex
);
11395 struct cleanup
*cleanup
= make_cleanup (xfree
, xml
);
11397 btrace
= parse_xml_btrace (xml
);
11398 do_cleanups (cleanup
);
11405 remote_augmented_libraries_svr4_read (void)
11407 struct remote_state
*rs
= get_remote_state ();
11409 return rs
->augmented_libraries_svr4_read
;
11413 init_remote_ops (void)
11415 remote_ops
.to_shortname
= "remote";
11416 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11417 remote_ops
.to_doc
=
11418 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11419 Specify the serial device it is connected to\n\
11420 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11421 remote_ops
.to_open
= remote_open
;
11422 remote_ops
.to_close
= remote_close
;
11423 remote_ops
.to_detach
= remote_detach
;
11424 remote_ops
.to_disconnect
= remote_disconnect
;
11425 remote_ops
.to_resume
= remote_resume
;
11426 remote_ops
.to_wait
= remote_wait
;
11427 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11428 remote_ops
.to_store_registers
= remote_store_registers
;
11429 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11430 remote_ops
.to_files_info
= remote_files_info
;
11431 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11432 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11433 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11434 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11435 remote_ops
.to_watchpoint_addr_within_range
=
11436 remote_watchpoint_addr_within_range
;
11437 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11438 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11439 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11440 remote_ops
.to_region_ok_for_hw_watchpoint
11441 = remote_region_ok_for_hw_watchpoint
;
11442 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11443 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11444 remote_ops
.to_kill
= remote_kill
;
11445 remote_ops
.to_load
= generic_load
;
11446 remote_ops
.to_mourn_inferior
= remote_mourn
;
11447 remote_ops
.to_pass_signals
= remote_pass_signals
;
11448 remote_ops
.to_program_signals
= remote_program_signals
;
11449 remote_ops
.to_thread_alive
= remote_thread_alive
;
11450 remote_ops
.to_find_new_threads
= remote_threads_info
;
11451 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11452 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11453 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11454 remote_ops
.to_stop
= remote_stop
;
11455 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11456 remote_ops
.to_rcmd
= remote_rcmd
;
11457 remote_ops
.to_log_command
= serial_log_command
;
11458 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11459 remote_ops
.to_stratum
= process_stratum
;
11460 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11461 remote_ops
.to_has_memory
= default_child_has_memory
;
11462 remote_ops
.to_has_stack
= default_child_has_stack
;
11463 remote_ops
.to_has_registers
= default_child_has_registers
;
11464 remote_ops
.to_has_execution
= default_child_has_execution
;
11465 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11466 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11467 remote_ops
.to_magic
= OPS_MAGIC
;
11468 remote_ops
.to_memory_map
= remote_memory_map
;
11469 remote_ops
.to_flash_erase
= remote_flash_erase
;
11470 remote_ops
.to_flash_done
= remote_flash_done
;
11471 remote_ops
.to_read_description
= remote_read_description
;
11472 remote_ops
.to_search_memory
= remote_search_memory
;
11473 remote_ops
.to_can_async_p
= remote_can_async_p
;
11474 remote_ops
.to_is_async_p
= remote_is_async_p
;
11475 remote_ops
.to_async
= remote_async
;
11476 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11477 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11478 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11479 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11480 remote_ops
.to_supports_disable_randomization
11481 = remote_supports_disable_randomization
;
11482 remote_ops
.to_fileio_open
= remote_hostio_open
;
11483 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11484 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11485 remote_ops
.to_fileio_close
= remote_hostio_close
;
11486 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11487 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11488 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11489 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11490 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11491 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11492 remote_ops
.to_trace_init
= remote_trace_init
;
11493 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11494 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11495 remote_ops
.to_download_trace_state_variable
11496 = remote_download_trace_state_variable
;
11497 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11498 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11499 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11500 remote_ops
.to_trace_start
= remote_trace_start
;
11501 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11502 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11503 remote_ops
.to_trace_stop
= remote_trace_stop
;
11504 remote_ops
.to_trace_find
= remote_trace_find
;
11505 remote_ops
.to_get_trace_state_variable_value
11506 = remote_get_trace_state_variable_value
;
11507 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11508 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11509 remote_ops
.to_upload_trace_state_variables
11510 = remote_upload_trace_state_variables
;
11511 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11512 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11513 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11514 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11515 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
11516 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11517 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11518 remote_ops
.to_verify_memory
= remote_verify_memory
;
11519 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11520 remote_ops
.to_set_permissions
= remote_set_permissions
;
11521 remote_ops
.to_static_tracepoint_marker_at
11522 = remote_static_tracepoint_marker_at
;
11523 remote_ops
.to_static_tracepoint_markers_by_strid
11524 = remote_static_tracepoint_markers_by_strid
;
11525 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11526 remote_ops
.to_use_agent
= remote_use_agent
;
11527 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11528 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
11529 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
11530 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
11531 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
11532 remote_ops
.to_read_btrace
= remote_read_btrace
;
11533 remote_ops
.to_augmented_libraries_svr4_read
=
11534 remote_augmented_libraries_svr4_read
;
11537 /* Set up the extended remote vector by making a copy of the standard
11538 remote vector and adding to it. */
11541 init_extended_remote_ops (void)
11543 extended_remote_ops
= remote_ops
;
11545 extended_remote_ops
.to_shortname
= "extended-remote";
11546 extended_remote_ops
.to_longname
=
11547 "Extended remote serial target in gdb-specific protocol";
11548 extended_remote_ops
.to_doc
=
11549 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11550 Specify the serial device it is connected to (e.g. /dev/ttya).";
11551 extended_remote_ops
.to_open
= extended_remote_open
;
11552 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11553 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11554 extended_remote_ops
.to_detach
= extended_remote_detach
;
11555 extended_remote_ops
.to_attach
= extended_remote_attach
;
11556 extended_remote_ops
.to_kill
= extended_remote_kill
;
11557 extended_remote_ops
.to_supports_disable_randomization
11558 = extended_remote_supports_disable_randomization
;
11562 remote_can_async_p (void)
11564 struct remote_state
*rs
= get_remote_state ();
11566 if (!target_async_permitted
)
11567 /* We only enable async when the user specifically asks for it. */
11570 /* We're async whenever the serial device is. */
11571 return serial_can_async_p (rs
->remote_desc
);
11575 remote_is_async_p (void)
11577 struct remote_state
*rs
= get_remote_state ();
11579 if (!target_async_permitted
)
11580 /* We only enable async when the user specifically asks for it. */
11583 /* We're async whenever the serial device is. */
11584 return serial_is_async_p (rs
->remote_desc
);
11587 /* Pass the SERIAL event on and up to the client. One day this code
11588 will be able to delay notifying the client of an event until the
11589 point where an entire packet has been received. */
11591 static serial_event_ftype remote_async_serial_handler
;
11594 remote_async_serial_handler (struct serial
*scb
, void *context
)
11596 struct remote_state
*rs
= context
;
11598 /* Don't propogate error information up to the client. Instead let
11599 the client find out about the error by querying the target. */
11600 rs
->async_client_callback (INF_REG_EVENT
, rs
->async_client_context
);
11604 remote_async_inferior_event_handler (gdb_client_data data
)
11606 inferior_event_handler (INF_REG_EVENT
, NULL
);
11610 remote_async (void (*callback
) (enum inferior_event_type event_type
,
11611 void *context
), void *context
)
11613 struct remote_state
*rs
= get_remote_state ();
11615 if (callback
!= NULL
)
11617 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
11618 rs
->async_client_callback
= callback
;
11619 rs
->async_client_context
= context
;
11622 serial_async (rs
->remote_desc
, NULL
, NULL
);
11626 set_remote_cmd (char *args
, int from_tty
)
11628 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
11632 show_remote_cmd (char *args
, int from_tty
)
11634 /* We can't just use cmd_show_list here, because we want to skip
11635 the redundant "show remote Z-packet" and the legacy aliases. */
11636 struct cleanup
*showlist_chain
;
11637 struct cmd_list_element
*list
= remote_show_cmdlist
;
11638 struct ui_out
*uiout
= current_uiout
;
11640 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11641 for (; list
!= NULL
; list
= list
->next
)
11642 if (strcmp (list
->name
, "Z-packet") == 0)
11644 else if (list
->type
== not_set_cmd
)
11645 /* Alias commands are exactly like the original, except they
11646 don't have the normal type. */
11650 struct cleanup
*option_chain
11651 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11653 ui_out_field_string (uiout
, "name", list
->name
);
11654 ui_out_text (uiout
, ": ");
11655 if (list
->type
== show_cmd
)
11656 do_show_command ((char *) NULL
, from_tty
, list
);
11658 cmd_func (list
, NULL
, from_tty
);
11659 /* Close the tuple. */
11660 do_cleanups (option_chain
);
11663 /* Close the tuple. */
11664 do_cleanups (showlist_chain
);
11668 /* Function to be called whenever a new objfile (shlib) is detected. */
11670 remote_new_objfile (struct objfile
*objfile
)
11672 struct remote_state
*rs
= get_remote_state ();
11674 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
11675 remote_check_symbols ();
11678 /* Pull all the tracepoints defined on the target and create local
11679 data structures representing them. We don't want to create real
11680 tracepoints yet, we don't want to mess up the user's existing
11684 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
11686 struct remote_state
*rs
= get_remote_state ();
11689 /* Ask for a first packet of tracepoint definition. */
11691 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11693 while (*p
&& *p
!= 'l')
11695 parse_tracepoint_definition (p
, utpp
);
11696 /* Ask for another packet of tracepoint definition. */
11698 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11705 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
11707 struct remote_state
*rs
= get_remote_state ();
11710 /* Ask for a first packet of variable definition. */
11712 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11714 while (*p
&& *p
!= 'l')
11716 parse_tsv_definition (p
, utsvp
);
11717 /* Ask for another packet of variable definition. */
11719 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11725 /* The "set/show range-stepping" show hook. */
11728 show_range_stepping (struct ui_file
*file
, int from_tty
,
11729 struct cmd_list_element
*c
,
11732 fprintf_filtered (file
,
11733 _("Debugger's willingness to use range stepping "
11734 "is %s.\n"), value
);
11737 /* The "set/show range-stepping" set hook. */
11740 set_range_stepping (char *ignore_args
, int from_tty
,
11741 struct cmd_list_element
*c
)
11743 struct remote_state
*rs
= get_remote_state ();
11745 /* Whene enabling, check whether range stepping is actually
11746 supported by the target, and warn if not. */
11747 if (use_range_stepping
)
11749 if (rs
->remote_desc
!= NULL
)
11751 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
11752 remote_vcont_probe (rs
);
11754 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_ENABLE
11755 && rs
->supports_vCont
.r
)
11759 warning (_("Range stepping is not supported by the current target"));
11764 _initialize_remote (void)
11766 struct remote_state
*rs
;
11767 struct cmd_list_element
*cmd
;
11768 const char *cmd_name
;
11770 /* architecture specific data */
11771 remote_gdbarch_data_handle
=
11772 gdbarch_data_register_post_init (init_remote_state
);
11773 remote_g_packet_data_handle
=
11774 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
11776 /* Initialize the per-target state. At the moment there is only one
11777 of these, not one per target. Only one target is active at a
11779 remote_state
= new_remote_state ();
11781 init_remote_ops ();
11782 add_target (&remote_ops
);
11784 init_extended_remote_ops ();
11785 add_target (&extended_remote_ops
);
11787 /* Hook into new objfile notification. */
11788 observer_attach_new_objfile (remote_new_objfile
);
11789 /* We're no longer interested in notification events of an inferior
11791 observer_attach_inferior_exit (discard_pending_stop_replies
);
11793 /* Set up signal handlers. */
11794 async_sigint_remote_token
=
11795 create_async_signal_handler (async_remote_interrupt
, NULL
);
11796 async_sigint_remote_twice_token
=
11797 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11800 init_remote_threadtests ();
11803 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
11804 /* set/show remote ... */
11806 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11807 Remote protocol specific variables\n\
11808 Configure various remote-protocol specific variables such as\n\
11809 the packets being used"),
11810 &remote_set_cmdlist
, "set remote ",
11811 0 /* allow-unknown */, &setlist
);
11812 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11813 Remote protocol specific variables\n\
11814 Configure various remote-protocol specific variables such as\n\
11815 the packets being used"),
11816 &remote_show_cmdlist
, "show remote ",
11817 0 /* allow-unknown */, &showlist
);
11819 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11820 Compare section data on target to the exec file.\n\
11821 Argument is a single section name (default: all loaded sections)."),
11824 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11825 Send an arbitrary packet to a remote target.\n\
11826 maintenance packet TEXT\n\
11827 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11828 this command sends the string TEXT to the inferior, and displays the\n\
11829 response packet. GDB supplies the initial `$' character, and the\n\
11830 terminating `#' character and checksum."),
11833 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11834 Set whether to send break if interrupted."), _("\
11835 Show whether to send break if interrupted."), _("\
11836 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11837 set_remotebreak
, show_remotebreak
,
11838 &setlist
, &showlist
);
11839 cmd_name
= "remotebreak";
11840 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11841 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11842 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11843 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11844 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11846 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11847 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11849 Set interrupt sequence to remote target."), _("\
11850 Show interrupt sequence to remote target."), _("\
11851 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11852 NULL
, show_interrupt_sequence
,
11853 &remote_set_cmdlist
,
11854 &remote_show_cmdlist
);
11856 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11857 &interrupt_on_connect
, _("\
11858 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11859 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11860 If set, interrupt sequence is sent to remote target."),
11862 &remote_set_cmdlist
, &remote_show_cmdlist
);
11864 /* Install commands for configuring memory read/write packets. */
11866 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11867 Set the maximum number of bytes per memory write packet (deprecated)."),
11869 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11870 Show the maximum number of bytes per memory write packet (deprecated)."),
11872 add_cmd ("memory-write-packet-size", no_class
,
11873 set_memory_write_packet_size
, _("\
11874 Set the maximum number of bytes per memory-write packet.\n\
11875 Specify the number of bytes in a packet or 0 (zero) for the\n\
11876 default packet size. The actual limit is further reduced\n\
11877 dependent on the target. Specify ``fixed'' to disable the\n\
11878 further restriction and ``limit'' to enable that restriction."),
11879 &remote_set_cmdlist
);
11880 add_cmd ("memory-read-packet-size", no_class
,
11881 set_memory_read_packet_size
, _("\
11882 Set the maximum number of bytes per memory-read packet.\n\
11883 Specify the number of bytes in a packet or 0 (zero) for the\n\
11884 default packet size. The actual limit is further reduced\n\
11885 dependent on the target. Specify ``fixed'' to disable the\n\
11886 further restriction and ``limit'' to enable that restriction."),
11887 &remote_set_cmdlist
);
11888 add_cmd ("memory-write-packet-size", no_class
,
11889 show_memory_write_packet_size
,
11890 _("Show the maximum number of bytes per memory-write packet."),
11891 &remote_show_cmdlist
);
11892 add_cmd ("memory-read-packet-size", no_class
,
11893 show_memory_read_packet_size
,
11894 _("Show the maximum number of bytes per memory-read packet."),
11895 &remote_show_cmdlist
);
11897 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11898 &remote_hw_watchpoint_limit
, _("\
11899 Set the maximum number of target hardware watchpoints."), _("\
11900 Show the maximum number of target hardware watchpoints."), _("\
11901 Specify a negative limit for unlimited."),
11902 NULL
, NULL
, /* FIXME: i18n: The maximum
11903 number of target hardware
11904 watchpoints is %s. */
11905 &remote_set_cmdlist
, &remote_show_cmdlist
);
11906 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11907 &remote_hw_watchpoint_length_limit
, _("\
11908 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11909 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11910 Specify a negative limit for unlimited."),
11911 NULL
, NULL
, /* FIXME: i18n: The maximum
11912 length (in bytes) of a target
11913 hardware watchpoint is %s. */
11914 &remote_set_cmdlist
, &remote_show_cmdlist
);
11915 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11916 &remote_hw_breakpoint_limit
, _("\
11917 Set the maximum number of target hardware breakpoints."), _("\
11918 Show the maximum number of target hardware breakpoints."), _("\
11919 Specify a negative limit for unlimited."),
11920 NULL
, NULL
, /* FIXME: i18n: The maximum
11921 number of target hardware
11922 breakpoints is %s. */
11923 &remote_set_cmdlist
, &remote_show_cmdlist
);
11925 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
11926 &remote_address_size
, _("\
11927 Set the maximum size of the address (in bits) in a memory packet."), _("\
11928 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11930 NULL
, /* FIXME: i18n: */
11931 &setlist
, &showlist
);
11933 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11934 "X", "binary-download", 1);
11936 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11937 "vCont", "verbose-resume", 0);
11939 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11940 "QPassSignals", "pass-signals", 0);
11942 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
11943 "QProgramSignals", "program-signals", 0);
11945 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11946 "qSymbol", "symbol-lookup", 0);
11948 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11949 "P", "set-register", 1);
11951 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11952 "p", "fetch-register", 1);
11954 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11955 "Z0", "software-breakpoint", 0);
11957 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11958 "Z1", "hardware-breakpoint", 0);
11960 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11961 "Z2", "write-watchpoint", 0);
11963 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11964 "Z3", "read-watchpoint", 0);
11966 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11967 "Z4", "access-watchpoint", 0);
11969 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11970 "qXfer:auxv:read", "read-aux-vector", 0);
11972 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11973 "qXfer:features:read", "target-features", 0);
11975 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11976 "qXfer:libraries:read", "library-info", 0);
11978 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11979 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11981 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11982 "qXfer:memory-map:read", "memory-map", 0);
11984 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11985 "qXfer:spu:read", "read-spu-object", 0);
11987 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11988 "qXfer:spu:write", "write-spu-object", 0);
11990 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11991 "qXfer:osdata:read", "osdata", 0);
11993 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11994 "qXfer:threads:read", "threads", 0);
11996 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11997 "qXfer:siginfo:read", "read-siginfo-object", 0);
11999 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
12000 "qXfer:siginfo:write", "write-siginfo-object", 0);
12002 add_packet_config_cmd
12003 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
12004 "qXfer:traceframe-info:read", "traceframe-info", 0);
12006 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
12007 "qXfer:uib:read", "unwind-info-block", 0);
12009 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
12010 "qGetTLSAddr", "get-thread-local-storage-address",
12013 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
12014 "qGetTIBAddr", "get-thread-information-block-address",
12017 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
12018 "bc", "reverse-continue", 0);
12020 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
12021 "bs", "reverse-step", 0);
12023 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
12024 "qSupported", "supported-packets", 0);
12026 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
12027 "qSearch:memory", "search-memory", 0);
12029 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
12030 "qTStatus", "trace-status", 0);
12032 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
12033 "vFile:open", "hostio-open", 0);
12035 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
12036 "vFile:pread", "hostio-pread", 0);
12038 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
12039 "vFile:pwrite", "hostio-pwrite", 0);
12041 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
12042 "vFile:close", "hostio-close", 0);
12044 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
12045 "vFile:unlink", "hostio-unlink", 0);
12047 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
12048 "vFile:readlink", "hostio-readlink", 0);
12050 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
12051 "vAttach", "attach", 0);
12053 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
12056 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
12057 "QStartNoAckMode", "noack", 0);
12059 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
12060 "vKill", "kill", 0);
12062 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
12063 "qAttached", "query-attached", 0);
12065 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
12066 "ConditionalTracepoints",
12067 "conditional-tracepoints", 0);
12069 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
12070 "ConditionalBreakpoints",
12071 "conditional-breakpoints", 0);
12073 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
12074 "BreakpointCommands",
12075 "breakpoint-commands", 0);
12077 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
12078 "FastTracepoints", "fast-tracepoints", 0);
12080 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
12081 "TracepointSource", "TracepointSource", 0);
12083 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
12084 "QAllow", "allow", 0);
12086 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
12087 "StaticTracepoints", "static-tracepoints", 0);
12089 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
12090 "InstallInTrace", "install-in-trace", 0);
12092 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
12093 "qXfer:statictrace:read", "read-sdata-object", 0);
12095 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
12096 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12098 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
12099 "QDisableRandomization", "disable-randomization", 0);
12101 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
12102 "QAgent", "agent", 0);
12104 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
12105 "QTBuffer:size", "trace-buffer-size", 0);
12107 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
12108 "Qbtrace:off", "disable-btrace", 0);
12110 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12111 "Qbtrace:bts", "enable-btrace", 0);
12113 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12114 "qXfer:btrace", "read-btrace", 0);
12116 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12117 Z sub-packet has its own set and show commands, but users may
12118 have sets to this variable in their .gdbinit files (or in their
12120 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
12121 &remote_Z_packet_detect
, _("\
12122 Set use of remote protocol `Z' packets"), _("\
12123 Show use of remote protocol `Z' packets "), _("\
12124 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12126 set_remote_protocol_Z_packet_cmd
,
12127 show_remote_protocol_Z_packet_cmd
,
12128 /* FIXME: i18n: Use of remote protocol
12129 `Z' packets is %s. */
12130 &remote_set_cmdlist
, &remote_show_cmdlist
);
12132 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
12133 Manipulate files on the remote system\n\
12134 Transfer files to and from the remote target system."),
12135 &remote_cmdlist
, "remote ",
12136 0 /* allow-unknown */, &cmdlist
);
12138 add_cmd ("put", class_files
, remote_put_command
,
12139 _("Copy a local file to the remote system."),
12142 add_cmd ("get", class_files
, remote_get_command
,
12143 _("Copy a remote file to the local system."),
12146 add_cmd ("delete", class_files
, remote_delete_command
,
12147 _("Delete a remote file."),
12150 remote_exec_file
= xstrdup ("");
12151 add_setshow_string_noescape_cmd ("exec-file", class_files
,
12152 &remote_exec_file
, _("\
12153 Set the remote pathname for \"run\""), _("\
12154 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
12155 &remote_set_cmdlist
, &remote_show_cmdlist
);
12157 add_setshow_boolean_cmd ("range-stepping", class_run
,
12158 &use_range_stepping
, _("\
12159 Enable or disable range stepping."), _("\
12160 Show whether target-assisted range stepping is enabled."), _("\
12161 If on, and the target supports it, when stepping a source line, GDB\n\
12162 tells the target to step the corresponding range of addresses itself instead\n\
12163 of issuing multiple single-steps. This speeds up source level\n\
12164 stepping. If off, GDB always issues single-steps, even if range\n\
12165 stepping is supported by the target. The default is on."),
12166 set_range_stepping
,
12167 show_range_stepping
,
12171 /* Eventually initialize fileio. See fileio.c */
12172 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
12174 /* Take advantage of the fact that the LWP field is not used, to tag
12175 special ptids with it set to != 0. */
12176 magic_null_ptid
= ptid_build (42000, 1, -1);
12177 not_sent_ptid
= ptid_build (42000, 1, -2);
12178 any_thread_ptid
= ptid_build (42000, 1, 0);
12180 target_buf_size
= 2048;
12181 target_buf
= xmalloc (target_buf_size
);