1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2014 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. */
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"
51 #include "event-loop.h"
52 #include "event-top.h"
58 #include "gdbcore.h" /* for exec_bfd */
60 #include "remote-fileio.h"
61 #include "gdb/fileio.h"
63 #include "xml-support.h"
65 #include "memory-map.h"
67 #include "tracepoint.h"
73 /* Temp hacks for tracepoint encoding migration. */
74 static char *target_buf
;
75 static long target_buf_size
;
77 /* The size to align memory write packets, when practical. The protocol
78 does not guarantee any alignment, and gdb will generate short
79 writes and unaligned writes, but even as a best-effort attempt this
80 can improve bulk transfers. For instance, if a write is misaligned
81 relative to the target's data bus, the stub may need to make an extra
82 round trip fetching data from the target. This doesn't make a
83 huge difference, but it's easy to do, so we try to be helpful.
85 The alignment chosen is arbitrary; usually data bus width is
86 important here, not the possibly larger cache line size. */
87 enum { REMOTE_ALIGN_WRITES
= 16 };
89 /* Prototypes for local functions. */
90 static void async_cleanup_sigint_signal_handler (void *dummy
);
91 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
92 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
93 int forever
, int *is_notif
);
95 static void async_handle_remote_sigint (int);
96 static void async_handle_remote_sigint_twice (int);
98 static void remote_files_info (struct target_ops
*ignore
);
100 static void remote_prepare_to_store (struct regcache
*regcache
);
102 static void remote_open (char *name
, int from_tty
);
104 static void extended_remote_open (char *name
, int from_tty
);
106 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
108 static void remote_close (void);
110 static void remote_mourn (struct target_ops
*ops
);
112 static void extended_remote_restart (void);
114 static void extended_remote_mourn (struct target_ops
*);
116 static void remote_mourn_1 (struct target_ops
*);
118 static void remote_send (char **buf
, long *sizeof_buf_p
);
120 static int readchar (int timeout
);
122 static void remote_serial_write (const char *str
, int len
);
124 static void remote_kill (struct target_ops
*ops
);
126 static int tohex (int nib
);
128 static int remote_can_async_p (void);
130 static int remote_is_async_p (void);
132 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
133 void *context
), void *context
);
135 static void sync_remote_interrupt_twice (int signo
);
137 static void interrupt_query (void);
139 static void set_general_thread (struct ptid ptid
);
140 static void set_continue_thread (struct ptid ptid
);
142 static void get_offsets (void);
144 static void skip_frame (void);
146 static long read_frame (char **buf_p
, long *sizeof_buf
);
148 static int hexnumlen (ULONGEST num
);
150 static void init_remote_ops (void);
152 static void init_extended_remote_ops (void);
154 static void remote_stop (ptid_t
);
156 static int ishex (int ch
, int *val
);
158 static int stubhex (int ch
);
160 static int hexnumstr (char *, ULONGEST
);
162 static int hexnumnstr (char *, ULONGEST
, int);
164 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
166 static void print_packet (char *);
168 static void compare_sections_command (char *, int);
170 static void packet_command (char *, int);
172 static int stub_unpack_int (char *buff
, int fieldlength
);
174 static ptid_t
remote_current_thread (ptid_t oldptid
);
176 static void remote_find_new_threads (void);
178 static int fromhex (int a
);
180 static int putpkt_binary (char *buf
, int cnt
);
182 static void check_binary_download (CORE_ADDR addr
);
184 struct packet_config
;
186 static void show_packet_config_cmd (struct packet_config
*config
);
188 static void update_packet_config (struct packet_config
*config
);
190 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
191 struct cmd_list_element
*c
);
193 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
195 struct cmd_list_element
*c
,
198 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
199 static ptid_t
read_ptid (char *buf
, char **obuf
);
201 static void remote_set_permissions (void);
204 static int remote_get_trace_status (struct trace_status
*ts
);
206 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
208 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
210 static void remote_query_supported (void);
212 static void remote_check_symbols (void);
214 void _initialize_remote (void);
217 static void stop_reply_xfree (struct stop_reply
*);
218 static void remote_parse_stop_reply (char *, struct stop_reply
*);
219 static void push_stop_reply (struct stop_reply
*);
220 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
221 static int peek_stop_reply (ptid_t ptid
);
223 static void remote_async_inferior_event_handler (gdb_client_data
);
225 static void remote_terminal_ours (void);
227 static int remote_read_description_p (struct target_ops
*target
);
229 static void remote_console_output (char *msg
);
231 static int remote_supports_cond_breakpoints (void);
233 static int remote_can_run_breakpoint_commands (void);
237 static struct cmd_list_element
*remote_cmdlist
;
239 /* For "set remote" and "show remote". */
241 static struct cmd_list_element
*remote_set_cmdlist
;
242 static struct cmd_list_element
*remote_show_cmdlist
;
244 /* Stub vCont actions support.
246 Each field is a boolean flag indicating whether the stub reports
247 support for the corresponding action. */
249 struct vCont_action_support
258 /* Controls whether GDB is willing to use range stepping. */
260 static int use_range_stepping
= 1;
262 #define OPAQUETHREADBYTES 8
264 /* a 64 bit opaque identifier */
265 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
267 /* About this many threadisds fit in a packet. */
269 #define MAXTHREADLISTRESULTS 32
271 /* Description of the remote protocol state for the currently
272 connected target. This is per-target state, and independent of the
273 selected architecture. */
277 /* A buffer to use for incoming packets, and its current size. The
278 buffer is grown dynamically for larger incoming packets.
279 Outgoing packets may also be constructed in this buffer.
280 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
281 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
286 /* True if we're going through initial connection setup (finding out
287 about the remote side's threads, relocating symbols, etc.). */
290 /* If we negotiated packet size explicitly (and thus can bypass
291 heuristics for the largest packet size that will not overflow
292 a buffer in the stub), this will be set to that packet size.
293 Otherwise zero, meaning to use the guessed size. */
294 long explicit_packet_size
;
296 /* remote_wait is normally called when the target is running and
297 waits for a stop reply packet. But sometimes we need to call it
298 when the target is already stopped. We can send a "?" packet
299 and have remote_wait read the response. Or, if we already have
300 the response, we can stash it in BUF and tell remote_wait to
301 skip calling getpkt. This flag is set when BUF contains a
302 stop reply packet and the target is not waiting. */
303 int cached_wait_status
;
305 /* True, if in no ack mode. That is, neither GDB nor the stub will
306 expect acks from each other. The connection is assumed to be
310 /* True if we're connected in extended remote mode. */
313 /* True if the stub reported support for multi-process
315 int multi_process_aware
;
317 /* True if we resumed the target and we're waiting for the target to
318 stop. In the mean time, we can't start another command/query.
319 The remote server wouldn't be ready to process it, so we'd
320 timeout waiting for a reply that would never come and eventually
321 we'd close the connection. This can happen in asynchronous mode
322 because we allow GDB commands while the target is running. */
323 int waiting_for_stop_reply
;
325 /* True if the stub reports support for non-stop mode. */
328 /* The status of the stub support for the various vCont actions. */
329 struct vCont_action_support supports_vCont
;
331 /* True if the stub reports support for conditional tracepoints. */
332 int cond_tracepoints
;
334 /* True if the stub reports support for target-side breakpoint
336 int cond_breakpoints
;
338 /* True if the stub reports support for target-side breakpoint
340 int breakpoint_commands
;
342 /* True if the stub reports support for fast tracepoints. */
343 int fast_tracepoints
;
345 /* True if the stub reports support for static tracepoints. */
346 int static_tracepoints
;
348 /* True if the stub reports support for installing tracepoint while
350 int install_in_trace
;
352 /* True if the stub can continue running a trace while GDB is
354 int disconnected_tracing
;
356 /* True if the stub reports support for enabling and disabling
357 tracepoints while a trace experiment is running. */
358 int enable_disable_tracepoints
;
360 /* True if the stub can collect strings using tracenz bytecode. */
363 /* True if the stub supports qXfer:libraries-svr4:read with a
365 int augmented_libraries_svr4_read
;
367 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
368 responded to that. */
371 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
372 remote_open knows that we don't have a file open when the program
374 struct serial
*remote_desc
;
376 /* These are the threads which we last sent to the remote system. The
377 TID member will be -1 for all or -2 for not sent yet. */
378 ptid_t general_thread
;
379 ptid_t continue_thread
;
381 /* This is the traceframe which we last selected on the remote system.
382 It will be -1 if no traceframe is selected. */
383 int remote_traceframe_number
;
385 char *last_pass_packet
;
387 /* The last QProgramSignals packet sent to the target. We bypass
388 sending a new program signals list down to the target if the new
389 packet is exactly the same as the last we sent. IOW, we only let
390 the target know about program signals list changes. */
391 char *last_program_signals_packet
;
393 enum gdb_signal last_sent_signal
;
397 char *finished_object
;
398 char *finished_annex
;
399 ULONGEST finished_offset
;
401 /* Should we try the 'ThreadInfo' query packet?
403 This variable (NOT available to the user: auto-detect only!)
404 determines whether GDB will use the new, simpler "ThreadInfo"
405 query or the older, more complex syntax for thread queries.
406 This is an auto-detect variable (set to true at each connect,
407 and set to false when the target fails to recognize it). */
408 int use_threadinfo_query
;
409 int use_threadextra_query
;
411 void (*async_client_callback
) (enum inferior_event_type event_type
,
413 void *async_client_context
;
415 /* This is set to the data address of the access causing the target
416 to stop for a watchpoint. */
417 CORE_ADDR remote_watch_data_address
;
419 /* This is non-zero if target stopped for a watchpoint. */
420 int remote_stopped_by_watchpoint_p
;
422 threadref echo_nextthread
;
423 threadref nextthread
;
424 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
426 /* The state of remote notification. */
427 struct remote_notif_state
*notif_state
;
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
)
1564 struct remote_state
*rs
= get_remote_state ();
1566 /* GDB historically didn't pull threads in the initial connection
1567 setup. If the remote target doesn't even have a concept of
1568 threads (e.g., a bare-metal target), even if internally we
1569 consider that a single-threaded target, mentioning a new thread
1570 might be confusing to the user. Be silent then, preserving the
1571 age old behavior. */
1572 if (rs
->starting_up
)
1573 add_thread_silent (ptid
);
1577 set_executing (ptid
, running
);
1578 set_running (ptid
, running
);
1581 /* Come here when we learn about a thread id from the remote target.
1582 It may be the first time we hear about such thread, so take the
1583 opportunity to add it to GDB's thread list. In case this is the
1584 first time we're noticing its corresponding inferior, add it to
1585 GDB's inferior list as well. */
1588 remote_notice_new_inferior (ptid_t currthread
, int running
)
1590 /* If this is a new thread, add it to GDB's thread list.
1591 If we leave it up to WFI to do this, bad things will happen. */
1593 if (in_thread_list (currthread
) && is_exited (currthread
))
1595 /* We're seeing an event on a thread id we knew had exited.
1596 This has to be a new thread reusing the old id. Add it. */
1597 remote_add_thread (currthread
, running
);
1601 if (!in_thread_list (currthread
))
1603 struct inferior
*inf
= NULL
;
1604 int pid
= ptid_get_pid (currthread
);
1606 if (ptid_is_pid (inferior_ptid
)
1607 && pid
== ptid_get_pid (inferior_ptid
))
1609 /* inferior_ptid has no thread member yet. This can happen
1610 with the vAttach -> remote_wait,"TAAthread:" path if the
1611 stub doesn't support qC. This is the first stop reported
1612 after an attach, so this is the main thread. Update the
1613 ptid in the thread list. */
1614 if (in_thread_list (pid_to_ptid (pid
)))
1615 thread_change_ptid (inferior_ptid
, currthread
);
1618 remote_add_thread (currthread
, running
);
1619 inferior_ptid
= currthread
;
1624 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1626 /* inferior_ptid is not set yet. This can happen with the
1627 vRun -> remote_wait,"TAAthread:" path if the stub
1628 doesn't support qC. This is the first stop reported
1629 after an attach, so this is the main thread. Update the
1630 ptid in the thread list. */
1631 thread_change_ptid (inferior_ptid
, currthread
);
1635 /* When connecting to a target remote, or to a target
1636 extended-remote which already was debugging an inferior, we
1637 may not know about it yet. Add it before adding its child
1638 thread, so notifications are emitted in a sensible order. */
1639 if (!in_inferior_list (ptid_get_pid (currthread
)))
1641 struct remote_state
*rs
= get_remote_state ();
1642 int fake_pid_p
= !remote_multi_process_p (rs
);
1644 inf
= remote_add_inferior (fake_pid_p
,
1645 ptid_get_pid (currthread
), -1);
1648 /* This is really a new thread. Add it. */
1649 remote_add_thread (currthread
, running
);
1651 /* If we found a new inferior, let the common code do whatever
1652 it needs to with it (e.g., read shared libraries, insert
1653 breakpoints), unless we're just setting up an all-stop
1657 struct remote_state
*rs
= get_remote_state ();
1659 if (non_stop
|| !rs
->starting_up
)
1660 notice_new_inferior (currthread
, running
, 0);
1665 /* Return the private thread data, creating it if necessary. */
1667 static struct private_thread_info
*
1668 demand_private_info (ptid_t ptid
)
1670 struct thread_info
*info
= find_thread_ptid (ptid
);
1676 info
->private = xmalloc (sizeof (*(info
->private)));
1677 info
->private_dtor
= free_private_thread_info
;
1678 info
->private->core
= -1;
1679 info
->private->extra
= 0;
1682 return info
->private;
1685 /* Call this function as a result of
1686 1) A halt indication (T packet) containing a thread id
1687 2) A direct query of currthread
1688 3) Successful execution of set thread */
1691 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1693 rs
->general_thread
= currthread
;
1696 /* If 'QPassSignals' is supported, tell the remote stub what signals
1697 it can simply pass through to the inferior without reporting. */
1700 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1702 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1704 char *pass_packet
, *p
;
1706 struct remote_state
*rs
= get_remote_state ();
1708 gdb_assert (numsigs
< 256);
1709 for (i
= 0; i
< numsigs
; i
++)
1711 if (pass_signals
[i
])
1714 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1715 strcpy (pass_packet
, "QPassSignals:");
1716 p
= pass_packet
+ strlen (pass_packet
);
1717 for (i
= 0; i
< numsigs
; i
++)
1719 if (pass_signals
[i
])
1722 *p
++ = tohex (i
>> 4);
1723 *p
++ = tohex (i
& 15);
1732 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1734 char *buf
= rs
->buf
;
1736 putpkt (pass_packet
);
1737 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1738 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1739 if (rs
->last_pass_packet
)
1740 xfree (rs
->last_pass_packet
);
1741 rs
->last_pass_packet
= pass_packet
;
1744 xfree (pass_packet
);
1748 /* If 'QProgramSignals' is supported, tell the remote stub what
1749 signals it should pass through to the inferior when detaching. */
1752 remote_program_signals (int numsigs
, unsigned char *signals
)
1754 if (remote_protocol_packets
[PACKET_QProgramSignals
].support
!= PACKET_DISABLE
)
1758 struct remote_state
*rs
= get_remote_state ();
1760 gdb_assert (numsigs
< 256);
1761 for (i
= 0; i
< numsigs
; i
++)
1766 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1767 strcpy (packet
, "QProgramSignals:");
1768 p
= packet
+ strlen (packet
);
1769 for (i
= 0; i
< numsigs
; i
++)
1771 if (signal_pass_state (i
))
1774 *p
++ = tohex (i
>> 4);
1775 *p
++ = tohex (i
& 15);
1784 if (!rs
->last_program_signals_packet
1785 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1787 char *buf
= rs
->buf
;
1790 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1791 packet_ok (buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1792 xfree (rs
->last_program_signals_packet
);
1793 rs
->last_program_signals_packet
= packet
;
1800 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1801 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1802 thread. If GEN is set, set the general thread, if not, then set
1803 the step/continue thread. */
1805 set_thread (struct ptid ptid
, int gen
)
1807 struct remote_state
*rs
= get_remote_state ();
1808 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1809 char *buf
= rs
->buf
;
1810 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1812 if (ptid_equal (state
, ptid
))
1816 *buf
++ = gen
? 'g' : 'c';
1817 if (ptid_equal (ptid
, magic_null_ptid
))
1818 xsnprintf (buf
, endbuf
- buf
, "0");
1819 else if (ptid_equal (ptid
, any_thread_ptid
))
1820 xsnprintf (buf
, endbuf
- buf
, "0");
1821 else if (ptid_equal (ptid
, minus_one_ptid
))
1822 xsnprintf (buf
, endbuf
- buf
, "-1");
1824 write_ptid (buf
, endbuf
, ptid
);
1826 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1828 rs
->general_thread
= ptid
;
1830 rs
->continue_thread
= ptid
;
1834 set_general_thread (struct ptid ptid
)
1836 set_thread (ptid
, 1);
1840 set_continue_thread (struct ptid ptid
)
1842 set_thread (ptid
, 0);
1845 /* Change the remote current process. Which thread within the process
1846 ends up selected isn't important, as long as it is the same process
1847 as what INFERIOR_PTID points to.
1849 This comes from that fact that there is no explicit notion of
1850 "selected process" in the protocol. The selected process for
1851 general operations is the process the selected general thread
1855 set_general_process (void)
1857 struct remote_state
*rs
= get_remote_state ();
1859 /* If the remote can't handle multiple processes, don't bother. */
1860 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1863 /* We only need to change the remote current thread if it's pointing
1864 at some other process. */
1865 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1866 set_general_thread (inferior_ptid
);
1870 /* Return nonzero if the thread PTID is still alive on the remote
1874 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1876 struct remote_state
*rs
= get_remote_state ();
1879 if (ptid_equal (ptid
, magic_null_ptid
))
1880 /* The main thread is always alive. */
1883 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1884 /* The main thread is always alive. This can happen after a
1885 vAttach, if the remote side doesn't support
1890 endp
= rs
->buf
+ get_remote_packet_size ();
1893 write_ptid (p
, endp
, ptid
);
1896 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1897 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1900 /* About these extended threadlist and threadinfo packets. They are
1901 variable length packets but, the fields within them are often fixed
1902 length. They are redundent enough to send over UDP as is the
1903 remote protocol in general. There is a matching unit test module
1906 /* WARNING: This threadref data structure comes from the remote O.S.,
1907 libstub protocol encoding, and remote.c. It is not particularly
1910 /* Right now, the internal structure is int. We want it to be bigger.
1911 Plan to fix this. */
1913 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1915 /* gdb_ext_thread_info is an internal GDB data structure which is
1916 equivalent to the reply of the remote threadinfo packet. */
1918 struct gdb_ext_thread_info
1920 threadref threadid
; /* External form of thread reference. */
1921 int active
; /* Has state interesting to GDB?
1923 char display
[256]; /* Brief state display, name,
1924 blocked/suspended. */
1925 char shortname
[32]; /* To be used to name threads. */
1926 char more_display
[256]; /* Long info, statistics, queue depth,
1930 /* The volume of remote transfers can be limited by submitting
1931 a mask containing bits specifying the desired information.
1932 Use a union of these values as the 'selection' parameter to
1933 get_thread_info. FIXME: Make these TAG names more thread specific. */
1935 #define TAG_THREADID 1
1936 #define TAG_EXISTS 2
1937 #define TAG_DISPLAY 4
1938 #define TAG_THREADNAME 8
1939 #define TAG_MOREDISPLAY 16
1941 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1943 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1945 static char *unpack_nibble (char *buf
, int *val
);
1947 static char *pack_nibble (char *buf
, int nibble
);
1949 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1951 static char *unpack_byte (char *buf
, int *value
);
1953 static char *pack_int (char *buf
, int value
);
1955 static char *unpack_int (char *buf
, int *value
);
1957 static char *unpack_string (char *src
, char *dest
, int length
);
1959 static char *pack_threadid (char *pkt
, threadref
*id
);
1961 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1963 void int_to_threadref (threadref
*id
, int value
);
1965 static int threadref_to_int (threadref
*ref
);
1967 static void copy_threadref (threadref
*dest
, threadref
*src
);
1969 static int threadmatch (threadref
*dest
, threadref
*src
);
1971 static char *pack_threadinfo_request (char *pkt
, int mode
,
1974 static int remote_unpack_thread_info_response (char *pkt
,
1975 threadref
*expectedref
,
1976 struct gdb_ext_thread_info
1980 static int remote_get_threadinfo (threadref
*threadid
,
1981 int fieldset
, /*TAG mask */
1982 struct gdb_ext_thread_info
*info
);
1984 static char *pack_threadlist_request (char *pkt
, int startflag
,
1986 threadref
*nextthread
);
1988 static int parse_threadlist_response (char *pkt
,
1990 threadref
*original_echo
,
1991 threadref
*resultlist
,
1994 static int remote_get_threadlist (int startflag
,
1995 threadref
*nextthread
,
1999 threadref
*threadlist
);
2001 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2003 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2004 void *context
, int looplimit
);
2006 static int remote_newthread_step (threadref
*ref
, void *context
);
2009 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2010 buffer we're allowed to write to. Returns
2011 BUF+CHARACTERS_WRITTEN. */
2014 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2017 struct remote_state
*rs
= get_remote_state ();
2019 if (remote_multi_process_p (rs
))
2021 pid
= ptid_get_pid (ptid
);
2023 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2025 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2027 tid
= ptid_get_tid (ptid
);
2029 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2031 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2036 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2037 passed the last parsed char. Returns null_ptid on error. */
2040 read_ptid (char *buf
, char **obuf
)
2044 ULONGEST pid
= 0, tid
= 0;
2048 /* Multi-process ptid. */
2049 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2051 error (_("invalid remote ptid: %s"), p
);
2054 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2057 return ptid_build (pid
, 0, tid
);
2060 /* No multi-process. Just a tid. */
2061 pp
= unpack_varlen_hex (p
, &tid
);
2063 /* Since the stub is not sending a process id, then default to
2064 what's in inferior_ptid, unless it's null at this point. If so,
2065 then since there's no way to know the pid of the reported
2066 threads, use the magic number. */
2067 if (ptid_equal (inferior_ptid
, null_ptid
))
2068 pid
= ptid_get_pid (magic_null_ptid
);
2070 pid
= ptid_get_pid (inferior_ptid
);
2074 return ptid_build (pid
, 0, tid
);
2077 /* Encode 64 bits in 16 chars of hex. */
2079 static const char hexchars
[] = "0123456789abcdef";
2082 ishex (int ch
, int *val
)
2084 if ((ch
>= 'a') && (ch
<= 'f'))
2086 *val
= ch
- 'a' + 10;
2089 if ((ch
>= 'A') && (ch
<= 'F'))
2091 *val
= ch
- 'A' + 10;
2094 if ((ch
>= '0') && (ch
<= '9'))
2105 if (ch
>= 'a' && ch
<= 'f')
2106 return ch
- 'a' + 10;
2107 if (ch
>= '0' && ch
<= '9')
2109 if (ch
>= 'A' && ch
<= 'F')
2110 return ch
- 'A' + 10;
2115 stub_unpack_int (char *buff
, int fieldlength
)
2122 nibble
= stubhex (*buff
++);
2126 retval
= retval
<< 4;
2132 unpack_varlen_hex (char *buff
, /* packet to parse */
2136 ULONGEST retval
= 0;
2138 while (ishex (*buff
, &nibble
))
2141 retval
= retval
<< 4;
2142 retval
|= nibble
& 0x0f;
2149 unpack_nibble (char *buf
, int *val
)
2151 *val
= fromhex (*buf
++);
2156 pack_nibble (char *buf
, int nibble
)
2158 *buf
++ = hexchars
[(nibble
& 0x0f)];
2163 pack_hex_byte (char *pkt
, int byte
)
2165 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2166 *pkt
++ = hexchars
[(byte
& 0xf)];
2171 unpack_byte (char *buf
, int *value
)
2173 *value
= stub_unpack_int (buf
, 2);
2178 pack_int (char *buf
, int value
)
2180 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2181 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2182 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2183 buf
= pack_hex_byte (buf
, (value
& 0xff));
2188 unpack_int (char *buf
, int *value
)
2190 *value
= stub_unpack_int (buf
, 8);
2194 #if 0 /* Currently unused, uncomment when needed. */
2195 static char *pack_string (char *pkt
, char *string
);
2198 pack_string (char *pkt
, char *string
)
2203 len
= strlen (string
);
2205 len
= 200; /* Bigger than most GDB packets, junk??? */
2206 pkt
= pack_hex_byte (pkt
, len
);
2210 if ((ch
== '\0') || (ch
== '#'))
2211 ch
= '*'; /* Protect encapsulation. */
2216 #endif /* 0 (unused) */
2219 unpack_string (char *src
, char *dest
, int length
)
2228 pack_threadid (char *pkt
, threadref
*id
)
2231 unsigned char *altid
;
2233 altid
= (unsigned char *) id
;
2234 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2236 pkt
= pack_hex_byte (pkt
, *altid
++);
2242 unpack_threadid (char *inbuf
, threadref
*id
)
2245 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2248 altref
= (char *) id
;
2250 while (inbuf
< limit
)
2252 x
= stubhex (*inbuf
++);
2253 y
= stubhex (*inbuf
++);
2254 *altref
++ = (x
<< 4) | y
;
2259 /* Externally, threadrefs are 64 bits but internally, they are still
2260 ints. This is due to a mismatch of specifications. We would like
2261 to use 64bit thread references internally. This is an adapter
2265 int_to_threadref (threadref
*id
, int value
)
2267 unsigned char *scan
;
2269 scan
= (unsigned char *) id
;
2275 *scan
++ = (value
>> 24) & 0xff;
2276 *scan
++ = (value
>> 16) & 0xff;
2277 *scan
++ = (value
>> 8) & 0xff;
2278 *scan
++ = (value
& 0xff);
2282 threadref_to_int (threadref
*ref
)
2285 unsigned char *scan
;
2291 value
= (value
<< 8) | ((*scan
++) & 0xff);
2296 copy_threadref (threadref
*dest
, threadref
*src
)
2299 unsigned char *csrc
, *cdest
;
2301 csrc
= (unsigned char *) src
;
2302 cdest
= (unsigned char *) dest
;
2309 threadmatch (threadref
*dest
, threadref
*src
)
2311 /* Things are broken right now, so just assume we got a match. */
2313 unsigned char *srcp
, *destp
;
2315 srcp
= (char *) src
;
2316 destp
= (char *) dest
;
2320 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2327 threadid:1, # always request threadid
2334 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2337 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2339 *pkt
++ = 'q'; /* Info Query */
2340 *pkt
++ = 'P'; /* process or thread info */
2341 pkt
= pack_int (pkt
, mode
); /* mode */
2342 pkt
= pack_threadid (pkt
, id
); /* threadid */
2343 *pkt
= '\0'; /* terminate */
2347 /* These values tag the fields in a thread info response packet. */
2348 /* Tagging the fields allows us to request specific fields and to
2349 add more fields as time goes by. */
2351 #define TAG_THREADID 1 /* Echo the thread identifier. */
2352 #define TAG_EXISTS 2 /* Is this process defined enough to
2353 fetch registers and its stack? */
2354 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2355 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2356 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2360 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2361 struct gdb_ext_thread_info
*info
)
2363 struct remote_state
*rs
= get_remote_state ();
2367 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2370 /* info->threadid = 0; FIXME: implement zero_threadref. */
2372 info
->display
[0] = '\0';
2373 info
->shortname
[0] = '\0';
2374 info
->more_display
[0] = '\0';
2376 /* Assume the characters indicating the packet type have been
2378 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2379 pkt
= unpack_threadid (pkt
, &ref
);
2382 warning (_("Incomplete response to threadinfo request."));
2383 if (!threadmatch (&ref
, expectedref
))
2384 { /* This is an answer to a different request. */
2385 warning (_("ERROR RMT Thread info mismatch."));
2388 copy_threadref (&info
->threadid
, &ref
);
2390 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2392 /* Packets are terminated with nulls. */
2393 while ((pkt
< limit
) && mask
&& *pkt
)
2395 pkt
= unpack_int (pkt
, &tag
); /* tag */
2396 pkt
= unpack_byte (pkt
, &length
); /* length */
2397 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2399 warning (_("ERROR RMT: threadinfo tag mismatch."));
2403 if (tag
== TAG_THREADID
)
2407 warning (_("ERROR RMT: length of threadid is not 16."));
2411 pkt
= unpack_threadid (pkt
, &ref
);
2412 mask
= mask
& ~TAG_THREADID
;
2415 if (tag
== TAG_EXISTS
)
2417 info
->active
= stub_unpack_int (pkt
, length
);
2419 mask
= mask
& ~(TAG_EXISTS
);
2422 warning (_("ERROR RMT: 'exists' length too long."));
2428 if (tag
== TAG_THREADNAME
)
2430 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2431 mask
= mask
& ~TAG_THREADNAME
;
2434 if (tag
== TAG_DISPLAY
)
2436 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2437 mask
= mask
& ~TAG_DISPLAY
;
2440 if (tag
== TAG_MOREDISPLAY
)
2442 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2443 mask
= mask
& ~TAG_MOREDISPLAY
;
2446 warning (_("ERROR RMT: unknown thread info tag."));
2447 break; /* Not a tag we know about. */
2453 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2454 struct gdb_ext_thread_info
*info
)
2456 struct remote_state
*rs
= get_remote_state ();
2459 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2461 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2463 if (rs
->buf
[0] == '\0')
2466 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2471 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2474 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2475 threadref
*nextthread
)
2477 *pkt
++ = 'q'; /* info query packet */
2478 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2479 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2480 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2481 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2486 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2489 parse_threadlist_response (char *pkt
, int result_limit
,
2490 threadref
*original_echo
, threadref
*resultlist
,
2493 struct remote_state
*rs
= get_remote_state ();
2495 int count
, resultcount
, done
;
2498 /* Assume the 'q' and 'M chars have been stripped. */
2499 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2500 /* done parse past here */
2501 pkt
= unpack_byte (pkt
, &count
); /* count field */
2502 pkt
= unpack_nibble (pkt
, &done
);
2503 /* The first threadid is the argument threadid. */
2504 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2505 while ((count
-- > 0) && (pkt
< limit
))
2507 pkt
= unpack_threadid (pkt
, resultlist
++);
2508 if (resultcount
++ >= result_limit
)
2517 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2518 int *done
, int *result_count
, threadref
*threadlist
)
2520 struct remote_state
*rs
= get_remote_state ();
2523 /* Trancate result limit to be smaller than the packet size. */
2524 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2525 >= get_remote_packet_size ())
2526 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2528 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2530 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2532 if (*rs
->buf
== '\0')
2536 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2537 &rs
->echo_nextthread
, threadlist
, done
);
2539 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2541 /* FIXME: This is a good reason to drop the packet. */
2542 /* Possably, there is a duplicate response. */
2544 retransmit immediatly - race conditions
2545 retransmit after timeout - yes
2547 wait for packet, then exit
2549 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2550 return 0; /* I choose simply exiting. */
2552 if (*result_count
<= 0)
2556 warning (_("RMT ERROR : failed to get remote thread list."));
2559 return result
; /* break; */
2561 if (*result_count
> result_limit
)
2564 warning (_("RMT ERROR: threadlist response longer than requested."));
2570 /* This is the interface between remote and threads, remotes upper
2573 /* remote_find_new_threads retrieves the thread list and for each
2574 thread in the list, looks up the thread in GDB's internal list,
2575 adding the thread if it does not already exist. This involves
2576 getting partial thread lists from the remote target so, polling the
2577 quit_flag is required. */
2581 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2584 struct remote_state
*rs
= get_remote_state ();
2585 int done
, i
, result_count
;
2593 if (loopcount
++ > looplimit
)
2596 warning (_("Remote fetch threadlist -infinite loop-."));
2599 if (!remote_get_threadlist (startflag
, &rs
->nextthread
,
2600 MAXTHREADLISTRESULTS
,
2601 &done
, &result_count
, rs
->resultthreadlist
))
2606 /* Clear for later iterations. */
2608 /* Setup to resume next batch of thread references, set nextthread. */
2609 if (result_count
>= 1)
2610 copy_threadref (&rs
->nextthread
,
2611 &rs
->resultthreadlist
[result_count
- 1]);
2613 while (result_count
--)
2614 if (!(result
= (*stepfunction
) (&rs
->resultthreadlist
[i
++], context
)))
2621 remote_newthread_step (threadref
*ref
, void *context
)
2623 int pid
= ptid_get_pid (inferior_ptid
);
2624 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2626 if (!in_thread_list (ptid
))
2628 return 1; /* continue iterator */
2631 #define CRAZY_MAX_THREADS 1000
2634 remote_current_thread (ptid_t oldpid
)
2636 struct remote_state
*rs
= get_remote_state ();
2639 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2640 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2641 return read_ptid (&rs
->buf
[2], NULL
);
2646 /* Find new threads for info threads command.
2647 * Original version, using John Metzler's thread protocol.
2651 remote_find_new_threads (void)
2653 remote_threadlist_iterator (remote_newthread_step
, 0,
2657 #if defined(HAVE_LIBEXPAT)
2659 typedef struct thread_item
2665 DEF_VEC_O(thread_item_t
);
2667 struct threads_parsing_context
2669 VEC (thread_item_t
) *items
;
2673 start_thread (struct gdb_xml_parser
*parser
,
2674 const struct gdb_xml_element
*element
,
2675 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2677 struct threads_parsing_context
*data
= user_data
;
2679 struct thread_item item
;
2681 struct gdb_xml_value
*attr
;
2683 id
= xml_find_attribute (attributes
, "id")->value
;
2684 item
.ptid
= read_ptid (id
, NULL
);
2686 attr
= xml_find_attribute (attributes
, "core");
2688 item
.core
= *(ULONGEST
*) attr
->value
;
2694 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2698 end_thread (struct gdb_xml_parser
*parser
,
2699 const struct gdb_xml_element
*element
,
2700 void *user_data
, const char *body_text
)
2702 struct threads_parsing_context
*data
= user_data
;
2704 if (body_text
&& *body_text
)
2705 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2708 const struct gdb_xml_attribute thread_attributes
[] = {
2709 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2710 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2711 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2714 const struct gdb_xml_element thread_children
[] = {
2715 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2718 const struct gdb_xml_element threads_children
[] = {
2719 { "thread", thread_attributes
, thread_children
,
2720 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2721 start_thread
, end_thread
},
2722 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2725 const struct gdb_xml_element threads_elements
[] = {
2726 { "threads", NULL
, threads_children
,
2727 GDB_XML_EF_NONE
, NULL
, NULL
},
2728 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2731 /* Discard the contents of the constructed thread info context. */
2734 clear_threads_parsing_context (void *p
)
2736 struct threads_parsing_context
*context
= p
;
2738 struct thread_item
*item
;
2740 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2741 xfree (item
->extra
);
2743 VEC_free (thread_item_t
, context
->items
);
2749 * Find all threads for info threads command.
2750 * Uses new thread protocol contributed by Cisco.
2751 * Falls back and attempts to use the older method (above)
2752 * if the target doesn't respond to the new method.
2756 remote_threads_info (struct target_ops
*ops
)
2758 struct remote_state
*rs
= get_remote_state ();
2762 if (rs
->remote_desc
== 0) /* paranoia */
2763 error (_("Command can only be used when connected to the remote target."));
2765 #if defined(HAVE_LIBEXPAT)
2766 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2768 char *xml
= target_read_stralloc (¤t_target
,
2769 TARGET_OBJECT_THREADS
, NULL
);
2771 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2775 struct threads_parsing_context context
;
2777 context
.items
= NULL
;
2778 make_cleanup (clear_threads_parsing_context
, &context
);
2780 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2781 threads_elements
, xml
, &context
) == 0)
2784 struct thread_item
*item
;
2787 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2790 if (!ptid_equal (item
->ptid
, null_ptid
))
2792 struct private_thread_info
*info
;
2793 /* In non-stop mode, we assume new found threads
2794 are running until proven otherwise with a
2795 stop reply. In all-stop, we can only get
2796 here if all threads are stopped. */
2797 int running
= non_stop
? 1 : 0;
2799 remote_notice_new_inferior (item
->ptid
, running
);
2801 info
= demand_private_info (item
->ptid
);
2802 info
->core
= item
->core
;
2803 info
->extra
= item
->extra
;
2810 do_cleanups (back_to
);
2815 if (rs
->use_threadinfo_query
)
2817 putpkt ("qfThreadInfo");
2818 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2820 if (bufp
[0] != '\0') /* q packet recognized */
2822 struct cleanup
*old_chain
;
2825 /* remote_notice_new_inferior (in the loop below) may make
2826 new RSP calls, which clobber rs->buf. Work with a
2828 bufp
= saved_reply
= xstrdup (rs
->buf
);
2829 old_chain
= make_cleanup (free_current_contents
, &saved_reply
);
2831 while (*bufp
++ == 'm') /* reply contains one or more TID */
2835 new_thread
= read_ptid (bufp
, &bufp
);
2836 if (!ptid_equal (new_thread
, null_ptid
))
2838 /* In non-stop mode, we assume new found threads
2839 are running until proven otherwise with a
2840 stop reply. In all-stop, we can only get
2841 here if all threads are stopped. */
2842 int running
= non_stop
? 1 : 0;
2844 remote_notice_new_inferior (new_thread
, running
);
2847 while (*bufp
++ == ','); /* comma-separated list */
2848 free_current_contents (&saved_reply
);
2849 putpkt ("qsThreadInfo");
2850 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2851 bufp
= saved_reply
= xstrdup (rs
->buf
);
2853 do_cleanups (old_chain
);
2858 /* Only qfThreadInfo is supported in non-stop mode. */
2862 /* Else fall back to old method based on jmetzler protocol. */
2863 rs
->use_threadinfo_query
= 0;
2864 remote_find_new_threads ();
2869 * Collect a descriptive string about the given thread.
2870 * The target may say anything it wants to about the thread
2871 * (typically info about its blocked / runnable state, name, etc.).
2872 * This string will appear in the info threads display.
2874 * Optional: targets are not required to implement this function.
2878 remote_threads_extra_info (struct thread_info
*tp
)
2880 struct remote_state
*rs
= get_remote_state ();
2884 struct gdb_ext_thread_info threadinfo
;
2885 static char display_buf
[100]; /* arbitrary... */
2886 int n
= 0; /* position in display_buf */
2888 if (rs
->remote_desc
== 0) /* paranoia */
2889 internal_error (__FILE__
, __LINE__
,
2890 _("remote_threads_extra_info"));
2892 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2893 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2894 /* This is the main thread which was added by GDB. The remote
2895 server doesn't know about it. */
2898 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2900 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2902 if (info
&& info
->private)
2903 return info
->private->extra
;
2908 if (rs
->use_threadextra_query
)
2911 char *endb
= rs
->buf
+ get_remote_packet_size ();
2913 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2915 write_ptid (b
, endb
, tp
->ptid
);
2918 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2919 if (rs
->buf
[0] != 0)
2921 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2922 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2923 display_buf
[result
] = '\0';
2928 /* If the above query fails, fall back to the old method. */
2929 rs
->use_threadextra_query
= 0;
2930 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2931 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2932 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2933 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2934 if (threadinfo
.active
)
2936 if (*threadinfo
.shortname
)
2937 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2938 " Name: %s,", threadinfo
.shortname
);
2939 if (*threadinfo
.display
)
2940 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2941 " State: %s,", threadinfo
.display
);
2942 if (*threadinfo
.more_display
)
2943 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2944 " Priority: %s", threadinfo
.more_display
);
2948 /* For purely cosmetic reasons, clear up trailing commas. */
2949 if (',' == display_buf
[n
-1])
2950 display_buf
[n
-1] = ' ';
2959 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2960 struct static_tracepoint_marker
*marker
)
2962 struct remote_state
*rs
= get_remote_state ();
2965 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2967 p
+= hexnumstr (p
, addr
);
2969 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2973 error (_("Remote failure reply: %s"), p
);
2977 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2984 static VEC(static_tracepoint_marker_p
) *
2985 remote_static_tracepoint_markers_by_strid (const char *strid
)
2987 struct remote_state
*rs
= get_remote_state ();
2988 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2989 struct static_tracepoint_marker
*marker
= NULL
;
2990 struct cleanup
*old_chain
;
2993 /* Ask for a first packet of static tracepoint marker
2996 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2999 error (_("Remote failure reply: %s"), p
);
3001 old_chain
= make_cleanup (free_current_marker
, &marker
);
3006 marker
= XCNEW (struct static_tracepoint_marker
);
3010 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3012 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3014 VEC_safe_push (static_tracepoint_marker_p
,
3020 release_static_tracepoint_marker (marker
);
3021 memset (marker
, 0, sizeof (*marker
));
3024 while (*p
++ == ','); /* comma-separated list */
3025 /* Ask for another packet of static tracepoint definition. */
3027 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3031 do_cleanups (old_chain
);
3036 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3039 remote_get_ada_task_ptid (long lwp
, long thread
)
3041 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
3045 /* Restart the remote side; this is an extended protocol operation. */
3048 extended_remote_restart (void)
3050 struct remote_state
*rs
= get_remote_state ();
3052 /* Send the restart command; for reasons I don't understand the
3053 remote side really expects a number after the "R". */
3054 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3057 remote_fileio_reset ();
3060 /* Clean up connection to a remote debugger. */
3065 struct remote_state
*rs
= get_remote_state ();
3067 if (rs
->remote_desc
== NULL
)
3068 return; /* already closed */
3070 /* Make sure we leave stdin registered in the event loop, and we
3071 don't leave the async SIGINT signal handler installed. */
3072 remote_terminal_ours ();
3074 serial_close (rs
->remote_desc
);
3075 rs
->remote_desc
= NULL
;
3077 /* We don't have a connection to the remote stub anymore. Get rid
3078 of all the inferiors and their threads we were controlling.
3079 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3080 will be unable to find the thread corresponding to (pid, 0, 0). */
3081 inferior_ptid
= null_ptid
;
3082 discard_all_inferiors ();
3084 /* We are closing the remote target, so we should discard
3085 everything of this target. */
3086 discard_pending_stop_replies_in_queue (rs
);
3088 if (remote_async_inferior_event_token
)
3089 delete_async_event_handler (&remote_async_inferior_event_token
);
3091 remote_notif_state_xfree (rs
->notif_state
);
3093 trace_reset_local_state ();
3096 /* Query the remote side for the text, data and bss offsets. */
3101 struct remote_state
*rs
= get_remote_state ();
3104 int lose
, num_segments
= 0, do_sections
, do_segments
;
3105 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3106 struct section_offsets
*offs
;
3107 struct symfile_segment_data
*data
;
3109 if (symfile_objfile
== NULL
)
3112 putpkt ("qOffsets");
3113 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3116 if (buf
[0] == '\000')
3117 return; /* Return silently. Stub doesn't support
3121 warning (_("Remote failure reply: %s"), buf
);
3125 /* Pick up each field in turn. This used to be done with scanf, but
3126 scanf will make trouble if CORE_ADDR size doesn't match
3127 conversion directives correctly. The following code will work
3128 with any size of CORE_ADDR. */
3129 text_addr
= data_addr
= bss_addr
= 0;
3133 if (strncmp (ptr
, "Text=", 5) == 0)
3136 /* Don't use strtol, could lose on big values. */
3137 while (*ptr
&& *ptr
!= ';')
3138 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3140 if (strncmp (ptr
, ";Data=", 6) == 0)
3143 while (*ptr
&& *ptr
!= ';')
3144 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3149 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3152 while (*ptr
&& *ptr
!= ';')
3153 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3155 if (bss_addr
!= data_addr
)
3156 warning (_("Target reported unsupported offsets: %s"), buf
);
3161 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3164 /* Don't use strtol, could lose on big values. */
3165 while (*ptr
&& *ptr
!= ';')
3166 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3169 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3172 while (*ptr
&& *ptr
!= ';')
3173 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3181 error (_("Malformed response to offset query, %s"), buf
);
3182 else if (*ptr
!= '\0')
3183 warning (_("Target reported unsupported offsets: %s"), buf
);
3185 offs
= ((struct section_offsets
*)
3186 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3187 memcpy (offs
, symfile_objfile
->section_offsets
,
3188 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3190 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3191 do_segments
= (data
!= NULL
);
3192 do_sections
= num_segments
== 0;
3194 if (num_segments
> 0)
3196 segments
[0] = text_addr
;
3197 segments
[1] = data_addr
;
3199 /* If we have two segments, we can still try to relocate everything
3200 by assuming that the .text and .data offsets apply to the whole
3201 text and data segments. Convert the offsets given in the packet
3202 to base addresses for symfile_map_offsets_to_segments. */
3203 else if (data
&& data
->num_segments
== 2)
3205 segments
[0] = data
->segment_bases
[0] + text_addr
;
3206 segments
[1] = data
->segment_bases
[1] + data_addr
;
3209 /* If the object file has only one segment, assume that it is text
3210 rather than data; main programs with no writable data are rare,
3211 but programs with no code are useless. Of course the code might
3212 have ended up in the data segment... to detect that we would need
3213 the permissions here. */
3214 else if (data
&& data
->num_segments
== 1)
3216 segments
[0] = data
->segment_bases
[0] + text_addr
;
3219 /* There's no way to relocate by segment. */
3225 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3226 offs
, num_segments
, segments
);
3228 if (ret
== 0 && !do_sections
)
3229 error (_("Can not handle qOffsets TextSeg "
3230 "response with this symbol file"));
3237 free_symfile_segment_data (data
);
3241 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3243 /* This is a temporary kludge to force data and bss to use the
3244 same offsets because that's what nlmconv does now. The real
3245 solution requires changes to the stub and remote.c that I
3246 don't have time to do right now. */
3248 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3249 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3252 objfile_relocate (symfile_objfile
, offs
);
3255 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3256 threads we know are stopped already. This is used during the
3257 initial remote connection in non-stop mode --- threads that are
3258 reported as already being stopped are left stopped. */
3261 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3263 /* If we have a stop reply for this thread, it must be stopped. */
3264 if (peek_stop_reply (thread
->ptid
))
3265 set_stop_requested (thread
->ptid
, 1);
3270 /* Send interrupt_sequence to remote target. */
3272 send_interrupt_sequence (void)
3274 struct remote_state
*rs
= get_remote_state ();
3276 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3277 remote_serial_write ("\x03", 1);
3278 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3279 serial_send_break (rs
->remote_desc
);
3280 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3282 serial_send_break (rs
->remote_desc
);
3283 remote_serial_write ("g", 1);
3286 internal_error (__FILE__
, __LINE__
,
3287 _("Invalid value for interrupt_sequence_mode: %s."),
3288 interrupt_sequence_mode
);
3292 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3293 and extract the PTID. Returns NULL_PTID if not found. */
3296 stop_reply_extract_thread (char *stop_reply
)
3298 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3302 /* Txx r:val ; r:val (...) */
3305 /* Look for "register" named "thread". */
3310 p1
= strchr (p
, ':');
3314 if (strncmp (p
, "thread", p1
- p
) == 0)
3315 return read_ptid (++p1
, &p
);
3317 p1
= strchr (p
, ';');
3329 /* Determine the remote side's current thread. If we have a stop
3330 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3331 "thread" register we can extract the current thread from. If not,
3332 ask the remote which is the current thread with qC. The former
3333 method avoids a roundtrip. */
3336 get_current_thread (char *wait_status
)
3340 /* Note we don't use remote_parse_stop_reply as that makes use of
3341 the target architecture, which we haven't yet fully determined at
3343 if (wait_status
!= NULL
)
3344 ptid
= stop_reply_extract_thread (wait_status
);
3345 if (ptid_equal (ptid
, null_ptid
))
3346 ptid
= remote_current_thread (inferior_ptid
);
3351 /* Query the remote target for which is the current thread/process,
3352 add it to our tables, and update INFERIOR_PTID. The caller is
3353 responsible for setting the state such that the remote end is ready
3354 to return the current thread.
3356 This function is called after handling the '?' or 'vRun' packets,
3357 whose response is a stop reply from which we can also try
3358 extracting the thread. If the target doesn't support the explicit
3359 qC query, we infer the current thread from that stop reply, passed
3360 in in WAIT_STATUS, which may be NULL. */
3363 add_current_inferior_and_thread (char *wait_status
)
3365 struct remote_state
*rs
= get_remote_state ();
3367 ptid_t ptid
= null_ptid
;
3369 inferior_ptid
= null_ptid
;
3371 /* Now, if we have thread information, update inferior_ptid. */
3372 ptid
= get_current_thread (wait_status
);
3374 if (!ptid_equal (ptid
, null_ptid
))
3376 if (!remote_multi_process_p (rs
))
3379 inferior_ptid
= ptid
;
3383 /* Without this, some commands which require an active target
3384 (such as kill) won't work. This variable serves (at least)
3385 double duty as both the pid of the target process (if it has
3386 such), and as a flag indicating that a target is active. */
3387 inferior_ptid
= magic_null_ptid
;
3391 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3393 /* Add the main thread. */
3394 add_thread_silent (inferior_ptid
);
3398 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3400 struct remote_state
*rs
= get_remote_state ();
3401 struct packet_config
*noack_config
;
3402 char *wait_status
= NULL
;
3404 immediate_quit
++; /* Allow user to interrupt it. */
3407 if (interrupt_on_connect
)
3408 send_interrupt_sequence ();
3410 /* Ack any packet which the remote side has already sent. */
3411 serial_write (rs
->remote_desc
, "+", 1);
3413 /* Signal other parts that we're going through the initial setup,
3414 and so things may not be stable yet. */
3415 rs
->starting_up
= 1;
3417 /* The first packet we send to the target is the optional "supported
3418 packets" request. If the target can answer this, it will tell us
3419 which later probes to skip. */
3420 remote_query_supported ();
3422 /* If the stub wants to get a QAllow, compose one and send it. */
3423 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3424 remote_set_permissions ();
3426 /* Next, we possibly activate noack mode.
3428 If the QStartNoAckMode packet configuration is set to AUTO,
3429 enable noack mode if the stub reported a wish for it with
3432 If set to TRUE, then enable noack mode even if the stub didn't
3433 report it in qSupported. If the stub doesn't reply OK, the
3434 session ends with an error.
3436 If FALSE, then don't activate noack mode, regardless of what the
3437 stub claimed should be the default with qSupported. */
3439 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3441 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3442 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3443 && noack_config
->support
== PACKET_ENABLE
))
3445 putpkt ("QStartNoAckMode");
3446 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3447 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3453 /* Tell the remote that we are using the extended protocol. */
3455 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3458 /* Let the target know which signals it is allowed to pass down to
3460 update_signals_program_target ();
3462 /* Next, if the target can specify a description, read it. We do
3463 this before anything involving memory or registers. */
3464 target_find_description ();
3466 /* Next, now that we know something about the target, update the
3467 address spaces in the program spaces. */
3468 update_address_spaces ();
3470 /* On OSs where the list of libraries is global to all
3471 processes, we fetch them early. */
3472 if (gdbarch_has_global_solist (target_gdbarch ()))
3473 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3477 if (!rs
->non_stop_aware
)
3478 error (_("Non-stop mode requested, but remote "
3479 "does not support non-stop"));
3481 putpkt ("QNonStop:1");
3482 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3484 if (strcmp (rs
->buf
, "OK") != 0)
3485 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3487 /* Find about threads and processes the stub is already
3488 controlling. We default to adding them in the running state.
3489 The '?' query below will then tell us about which threads are
3491 remote_threads_info (target
);
3493 else if (rs
->non_stop_aware
)
3495 /* Don't assume that the stub can operate in all-stop mode.
3496 Request it explicitly. */
3497 putpkt ("QNonStop:0");
3498 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3500 if (strcmp (rs
->buf
, "OK") != 0)
3501 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3504 /* Upload TSVs regardless of whether the target is running or not. The
3505 remote stub, such as GDBserver, may have some predefined or builtin
3506 TSVs, even if the target is not running. */
3507 if (remote_get_trace_status (current_trace_status ()) != -1)
3509 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3511 remote_upload_trace_state_variables (&uploaded_tsvs
);
3512 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3515 /* Check whether the target is running now. */
3517 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3523 struct inferior
*inf
;
3525 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3528 error (_("The target is not running (try extended-remote?)"));
3530 /* We're connected, but not running. Drop out before we
3531 call start_remote. */
3532 rs
->starting_up
= 0;
3537 /* Save the reply for later. */
3538 wait_status
= alloca (strlen (rs
->buf
) + 1);
3539 strcpy (wait_status
, rs
->buf
);
3542 /* Fetch thread list. */
3543 target_find_new_threads ();
3545 /* Let the stub know that we want it to return the thread. */
3546 set_continue_thread (minus_one_ptid
);
3548 if (thread_count () == 0)
3550 /* Target has no concept of threads at all. GDB treats
3551 non-threaded target as single-threaded; add a main
3553 add_current_inferior_and_thread (wait_status
);
3557 /* We have thread information; select the thread the target
3558 says should be current. If we're reconnecting to a
3559 multi-threaded program, this will ideally be the thread
3560 that last reported an event before GDB disconnected. */
3561 inferior_ptid
= get_current_thread (wait_status
);
3562 if (ptid_equal (inferior_ptid
, null_ptid
))
3564 /* Odd... The target was able to list threads, but not
3565 tell us which thread was current (no "thread"
3566 register in T stop reply?). Just pick the first
3567 thread in the thread list then. */
3568 inferior_ptid
= thread_list
->ptid
;
3572 /* init_wait_for_inferior should be called before get_offsets in order
3573 to manage `inserted' flag in bp loc in a correct state.
3574 breakpoint_init_inferior, called from init_wait_for_inferior, set
3575 `inserted' flag to 0, while before breakpoint_re_set, called from
3576 start_remote, set `inserted' flag to 1. In the initialization of
3577 inferior, breakpoint_init_inferior should be called first, and then
3578 breakpoint_re_set can be called. If this order is broken, state of
3579 `inserted' flag is wrong, and cause some problems on breakpoint
3581 init_wait_for_inferior ();
3583 get_offsets (); /* Get text, data & bss offsets. */
3585 /* If we could not find a description using qXfer, and we know
3586 how to do it some other way, try again. This is not
3587 supported for non-stop; it could be, but it is tricky if
3588 there are no stopped threads when we connect. */
3589 if (remote_read_description_p (target
)
3590 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3592 target_clear_description ();
3593 target_find_description ();
3596 /* Use the previously fetched status. */
3597 gdb_assert (wait_status
!= NULL
);
3598 strcpy (rs
->buf
, wait_status
);
3599 rs
->cached_wait_status
= 1;
3602 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3606 /* Clear WFI global state. Do this before finding about new
3607 threads and inferiors, and setting the current inferior.
3608 Otherwise we would clear the proceed status of the current
3609 inferior when we want its stop_soon state to be preserved
3610 (see notice_new_inferior). */
3611 init_wait_for_inferior ();
3613 /* In non-stop, we will either get an "OK", meaning that there
3614 are no stopped threads at this time; or, a regular stop
3615 reply. In the latter case, there may be more than one thread
3616 stopped --- we pull them all out using the vStopped
3618 if (strcmp (rs
->buf
, "OK") != 0)
3620 struct notif_client
*notif
= ¬if_client_stop
;
3622 /* remote_notif_get_pending_replies acks this one, and gets
3624 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
3625 = remote_notif_parse (notif
, rs
->buf
);
3626 remote_notif_get_pending_events (notif
);
3628 /* Make sure that threads that were stopped remain
3630 iterate_over_threads (set_stop_requested_callback
, NULL
);
3633 if (target_can_async_p ())
3634 target_async (inferior_event_handler
, 0);
3636 if (thread_count () == 0)
3639 error (_("The target is not running (try extended-remote?)"));
3641 /* We're connected, but not running. Drop out before we
3642 call start_remote. */
3643 rs
->starting_up
= 0;
3647 /* Let the stub know that we want it to return the thread. */
3649 /* Force the stub to choose a thread. */
3650 set_general_thread (null_ptid
);
3653 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3654 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3655 error (_("remote didn't report the current thread in non-stop mode"));
3657 get_offsets (); /* Get text, data & bss offsets. */
3659 /* In non-stop mode, any cached wait status will be stored in
3660 the stop reply queue. */
3661 gdb_assert (wait_status
== NULL
);
3663 /* Report all signals during attach/startup. */
3664 remote_pass_signals (0, NULL
);
3667 /* If we connected to a live target, do some additional setup. */
3668 if (target_has_execution
)
3670 if (exec_bfd
) /* No use without an exec file. */
3671 remote_check_symbols ();
3674 /* Possibly the target has been engaged in a trace run started
3675 previously; find out where things are at. */
3676 if (remote_get_trace_status (current_trace_status ()) != -1)
3678 struct uploaded_tp
*uploaded_tps
= NULL
;
3680 if (current_trace_status ()->running
)
3681 printf_filtered (_("Trace is already running on the target.\n"));
3683 remote_upload_tracepoints (&uploaded_tps
);
3685 merge_uploaded_tracepoints (&uploaded_tps
);
3688 /* The thread and inferior lists are now synchronized with the
3689 target, our symbols have been relocated, and we're merged the
3690 target's tracepoints with ours. We're done with basic start
3692 rs
->starting_up
= 0;
3694 /* If breakpoints are global, insert them now. */
3695 if (gdbarch_has_global_breakpoints (target_gdbarch ())
3696 && breakpoints_always_inserted_mode ())
3697 insert_breakpoints ();
3700 /* Open a connection to a remote debugger.
3701 NAME is the filename used for communication. */
3704 remote_open (char *name
, int from_tty
)
3706 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3709 /* Open a connection to a remote debugger using the extended
3710 remote gdb protocol. NAME is the filename used for communication. */
3713 extended_remote_open (char *name
, int from_tty
)
3715 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3718 /* Generic code for opening a connection to a remote target. */
3721 init_all_packet_configs (void)
3725 for (i
= 0; i
< PACKET_MAX
; i
++)
3726 update_packet_config (&remote_protocol_packets
[i
]);
3729 /* Symbol look-up. */
3732 remote_check_symbols (void)
3734 struct remote_state
*rs
= get_remote_state ();
3735 char *msg
, *reply
, *tmp
;
3736 struct minimal_symbol
*sym
;
3739 /* The remote side has no concept of inferiors that aren't running
3740 yet, it only knows about running processes. If we're connected
3741 but our current inferior is not running, we should not invite the
3742 remote target to request symbol lookups related to its
3743 (unrelated) current process. */
3744 if (!target_has_execution
)
3747 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3750 /* Make sure the remote is pointing at the right process. Note
3751 there's no way to select "no process". */
3752 set_general_process ();
3754 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3755 because we need both at the same time. */
3756 msg
= alloca (get_remote_packet_size ());
3758 /* Invite target to request symbol lookups. */
3760 putpkt ("qSymbol::");
3761 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3762 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3765 while (strncmp (reply
, "qSymbol:", 8) == 0)
3768 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3770 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3772 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3775 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3776 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3778 /* If this is a function address, return the start of code
3779 instead of any data function descriptor. */
3780 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3784 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3785 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3789 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3794 static struct serial
*
3795 remote_serial_open (char *name
)
3797 static int udp_warning
= 0;
3799 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3800 of in ser-tcp.c, because it is the remote protocol assuming that the
3801 serial connection is reliable and not the serial connection promising
3803 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3805 warning (_("The remote protocol may be unreliable over UDP.\n"
3806 "Some events may be lost, rendering further debugging "
3811 return serial_open (name
);
3814 /* Inform the target of our permission settings. The permission flags
3815 work without this, but if the target knows the settings, it can do
3816 a couple things. First, it can add its own check, to catch cases
3817 that somehow manage to get by the permissions checks in target
3818 methods. Second, if the target is wired to disallow particular
3819 settings (for instance, a system in the field that is not set up to
3820 be able to stop at a breakpoint), it can object to any unavailable
3824 remote_set_permissions (void)
3826 struct remote_state
*rs
= get_remote_state ();
3828 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3829 "WriteReg:%x;WriteMem:%x;"
3830 "InsertBreak:%x;InsertTrace:%x;"
3831 "InsertFastTrace:%x;Stop:%x",
3832 may_write_registers
, may_write_memory
,
3833 may_insert_breakpoints
, may_insert_tracepoints
,
3834 may_insert_fast_tracepoints
, may_stop
);
3836 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3838 /* If the target didn't like the packet, warn the user. Do not try
3839 to undo the user's settings, that would just be maddening. */
3840 if (strcmp (rs
->buf
, "OK") != 0)
3841 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3844 /* This type describes each known response to the qSupported
3846 struct protocol_feature
3848 /* The name of this protocol feature. */
3851 /* The default for this protocol feature. */
3852 enum packet_support default_support
;
3854 /* The function to call when this feature is reported, or after
3855 qSupported processing if the feature is not supported.
3856 The first argument points to this structure. The second
3857 argument indicates whether the packet requested support be
3858 enabled, disabled, or probed (or the default, if this function
3859 is being called at the end of processing and this feature was
3860 not reported). The third argument may be NULL; if not NULL, it
3861 is a NUL-terminated string taken from the packet following
3862 this feature's name and an equals sign. */
3863 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3866 /* The corresponding packet for this feature. Only used if
3867 FUNC is remote_supported_packet. */
3872 remote_supported_packet (const struct protocol_feature
*feature
,
3873 enum packet_support support
,
3874 const char *argument
)
3878 warning (_("Remote qSupported response supplied an unexpected value for"
3879 " \"%s\"."), feature
->name
);
3883 if (remote_protocol_packets
[feature
->packet
].support
3884 == PACKET_SUPPORT_UNKNOWN
)
3885 remote_protocol_packets
[feature
->packet
].support
= support
;
3889 remote_packet_size (const struct protocol_feature
*feature
,
3890 enum packet_support support
, const char *value
)
3892 struct remote_state
*rs
= get_remote_state ();
3897 if (support
!= PACKET_ENABLE
)
3900 if (value
== NULL
|| *value
== '\0')
3902 warning (_("Remote target reported \"%s\" without a size."),
3908 packet_size
= strtol (value
, &value_end
, 16);
3909 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3911 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3912 feature
->name
, value
);
3916 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3918 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3919 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3920 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3923 /* Record the new maximum packet size. */
3924 rs
->explicit_packet_size
= packet_size
;
3928 remote_multi_process_feature (const struct protocol_feature
*feature
,
3929 enum packet_support support
, const char *value
)
3931 struct remote_state
*rs
= get_remote_state ();
3933 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3937 remote_non_stop_feature (const struct protocol_feature
*feature
,
3938 enum packet_support support
, const char *value
)
3940 struct remote_state
*rs
= get_remote_state ();
3942 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3946 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3947 enum packet_support support
,
3950 struct remote_state
*rs
= get_remote_state ();
3952 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3956 remote_cond_breakpoint_feature (const struct protocol_feature
*feature
,
3957 enum packet_support support
,
3960 struct remote_state
*rs
= get_remote_state ();
3962 rs
->cond_breakpoints
= (support
== PACKET_ENABLE
);
3966 remote_breakpoint_commands_feature (const struct protocol_feature
*feature
,
3967 enum packet_support support
,
3970 struct remote_state
*rs
= get_remote_state ();
3972 rs
->breakpoint_commands
= (support
== PACKET_ENABLE
);
3976 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3977 enum packet_support support
,
3980 struct remote_state
*rs
= get_remote_state ();
3982 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3986 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3987 enum packet_support support
,
3990 struct remote_state
*rs
= get_remote_state ();
3992 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3996 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3997 enum packet_support support
,
4000 struct remote_state
*rs
= get_remote_state ();
4002 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
4006 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
4007 enum packet_support support
,
4010 struct remote_state
*rs
= get_remote_state ();
4012 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
4016 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
4017 enum packet_support support
,
4020 struct remote_state
*rs
= get_remote_state ();
4022 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
4026 remote_string_tracing_feature (const struct protocol_feature
*feature
,
4027 enum packet_support support
,
4030 struct remote_state
*rs
= get_remote_state ();
4032 rs
->string_tracing
= (support
== PACKET_ENABLE
);
4036 remote_augmented_libraries_svr4_read_feature
4037 (const struct protocol_feature
*feature
,
4038 enum packet_support support
, const char *value
)
4040 struct remote_state
*rs
= get_remote_state ();
4042 rs
->augmented_libraries_svr4_read
= (support
== PACKET_ENABLE
);
4045 static const struct protocol_feature remote_protocol_features
[] = {
4046 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4047 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4048 PACKET_qXfer_auxv
},
4049 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4050 PACKET_qXfer_features
},
4051 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4052 PACKET_qXfer_libraries
},
4053 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4054 PACKET_qXfer_libraries_svr4
},
4055 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4056 remote_augmented_libraries_svr4_read_feature
, -1 },
4057 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4058 PACKET_qXfer_memory_map
},
4059 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4060 PACKET_qXfer_spu_read
},
4061 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4062 PACKET_qXfer_spu_write
},
4063 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4064 PACKET_qXfer_osdata
},
4065 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4066 PACKET_qXfer_threads
},
4067 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4068 PACKET_qXfer_traceframe_info
},
4069 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4070 PACKET_QPassSignals
},
4071 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4072 PACKET_QProgramSignals
},
4073 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4074 PACKET_QStartNoAckMode
},
4075 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
4076 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
4077 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4078 PACKET_qXfer_siginfo_read
},
4079 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4080 PACKET_qXfer_siginfo_write
},
4081 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
4082 PACKET_ConditionalTracepoints
},
4083 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_cond_breakpoint_feature
,
4084 PACKET_ConditionalBreakpoints
},
4085 { "BreakpointCommands", PACKET_DISABLE
, remote_breakpoint_commands_feature
,
4086 PACKET_BreakpointCommands
},
4087 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
4088 PACKET_FastTracepoints
},
4089 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
4090 PACKET_StaticTracepoints
},
4091 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
4092 PACKET_InstallInTrace
},
4093 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
4095 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4097 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4099 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4100 PACKET_TracepointSource
},
4101 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4103 { "EnableDisableTracepoints", PACKET_DISABLE
,
4104 remote_enable_disable_tracepoint_feature
, -1 },
4105 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4106 PACKET_qXfer_fdpic
},
4107 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4109 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4110 PACKET_QDisableRandomization
},
4111 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4112 { "QTBuffer:size", PACKET_DISABLE
,
4113 remote_supported_packet
, PACKET_QTBuffer_size
},
4114 { "tracenz", PACKET_DISABLE
,
4115 remote_string_tracing_feature
, -1 },
4116 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4117 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4118 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4119 PACKET_qXfer_btrace
}
4122 static char *remote_support_xml
;
4124 /* Register string appended to "xmlRegisters=" in qSupported query. */
4127 register_remote_support_xml (const char *xml
)
4129 #if defined(HAVE_LIBEXPAT)
4130 if (remote_support_xml
== NULL
)
4131 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4134 char *copy
= xstrdup (remote_support_xml
+ 13);
4135 char *p
= strtok (copy
, ",");
4139 if (strcmp (p
, xml
) == 0)
4146 while ((p
= strtok (NULL
, ",")) != NULL
);
4149 remote_support_xml
= reconcat (remote_support_xml
,
4150 remote_support_xml
, ",", xml
,
4157 remote_query_supported_append (char *msg
, const char *append
)
4160 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4162 return xstrdup (append
);
4166 remote_query_supported (void)
4168 struct remote_state
*rs
= get_remote_state ();
4171 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4173 /* The packet support flags are handled differently for this packet
4174 than for most others. We treat an error, a disabled packet, and
4175 an empty response identically: any features which must be reported
4176 to be used will be automatically disabled. An empty buffer
4177 accomplishes this, since that is also the representation for a list
4178 containing no features. */
4181 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
4184 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4186 q
= remote_query_supported_append (q
, "multiprocess+");
4188 if (remote_support_xml
)
4189 q
= remote_query_supported_append (q
, remote_support_xml
);
4191 q
= remote_query_supported_append (q
, "qRelocInsn+");
4193 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4196 do_cleanups (old_chain
);
4198 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4200 /* If an error occured, warn, but do not return - just reset the
4201 buffer to empty and go on to disable features. */
4202 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4205 warning (_("Remote failure reply: %s"), rs
->buf
);
4210 memset (seen
, 0, sizeof (seen
));
4215 enum packet_support is_supported
;
4216 char *p
, *end
, *name_end
, *value
;
4218 /* First separate out this item from the rest of the packet. If
4219 there's another item after this, we overwrite the separator
4220 (terminated strings are much easier to work with). */
4222 end
= strchr (p
, ';');
4225 end
= p
+ strlen (p
);
4235 warning (_("empty item in \"qSupported\" response"));
4240 name_end
= strchr (p
, '=');
4243 /* This is a name=value entry. */
4244 is_supported
= PACKET_ENABLE
;
4245 value
= name_end
+ 1;
4254 is_supported
= PACKET_ENABLE
;
4258 is_supported
= PACKET_DISABLE
;
4262 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4266 warning (_("unrecognized item \"%s\" "
4267 "in \"qSupported\" response"), p
);
4273 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4274 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4276 const struct protocol_feature
*feature
;
4279 feature
= &remote_protocol_features
[i
];
4280 feature
->func (feature
, is_supported
, value
);
4285 /* If we increased the packet size, make sure to increase the global
4286 buffer size also. We delay this until after parsing the entire
4287 qSupported packet, because this is the same buffer we were
4289 if (rs
->buf_size
< rs
->explicit_packet_size
)
4291 rs
->buf_size
= rs
->explicit_packet_size
;
4292 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4295 /* Handle the defaults for unmentioned features. */
4296 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4299 const struct protocol_feature
*feature
;
4301 feature
= &remote_protocol_features
[i
];
4302 feature
->func (feature
, feature
->default_support
, NULL
);
4306 /* Remove any of the remote.c targets from target stack. Upper targets depend
4307 on it so remove them first. */
4310 remote_unpush_target (void)
4312 pop_all_targets_above (process_stratum
- 1);
4316 remote_open_1 (char *name
, int from_tty
,
4317 struct target_ops
*target
, int extended_p
)
4319 struct remote_state
*rs
= get_remote_state ();
4322 error (_("To open a remote debug connection, you need to specify what\n"
4323 "serial device is attached to the remote system\n"
4324 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4326 /* See FIXME above. */
4327 if (!target_async_permitted
)
4328 wait_forever_enabled_p
= 1;
4330 /* If we're connected to a running target, target_preopen will kill it.
4331 Ask this question first, before target_preopen has a chance to kill
4333 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4336 && !query (_("Already connected to a remote target. Disconnect? ")))
4337 error (_("Still connected."));
4340 /* Here the possibly existing remote target gets unpushed. */
4341 target_preopen (from_tty
);
4343 /* Make sure we send the passed signals list the next time we resume. */
4344 xfree (rs
->last_pass_packet
);
4345 rs
->last_pass_packet
= NULL
;
4347 /* Make sure we send the program signals list the next time we
4349 xfree (rs
->last_program_signals_packet
);
4350 rs
->last_program_signals_packet
= NULL
;
4352 remote_fileio_reset ();
4353 reopen_exec_file ();
4356 rs
->remote_desc
= remote_serial_open (name
);
4357 if (!rs
->remote_desc
)
4358 perror_with_name (name
);
4360 if (baud_rate
!= -1)
4362 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4364 /* The requested speed could not be set. Error out to
4365 top level after closing remote_desc. Take care to
4366 set remote_desc to NULL to avoid closing remote_desc
4368 serial_close (rs
->remote_desc
);
4369 rs
->remote_desc
= NULL
;
4370 perror_with_name (name
);
4374 serial_raw (rs
->remote_desc
);
4376 /* If there is something sitting in the buffer we might take it as a
4377 response to a command, which would be bad. */
4378 serial_flush_input (rs
->remote_desc
);
4382 puts_filtered ("Remote debugging using ");
4383 puts_filtered (name
);
4384 puts_filtered ("\n");
4386 push_target (target
); /* Switch to using remote target now. */
4388 /* Register extra event sources in the event loop. */
4389 remote_async_inferior_event_token
4390 = create_async_event_handler (remote_async_inferior_event_handler
,
4392 rs
->notif_state
= remote_notif_state_allocate ();
4394 /* Reset the target state; these things will be queried either by
4395 remote_query_supported or as they are needed. */
4396 init_all_packet_configs ();
4397 rs
->cached_wait_status
= 0;
4398 rs
->explicit_packet_size
= 0;
4400 rs
->multi_process_aware
= 0;
4401 rs
->extended
= extended_p
;
4402 rs
->non_stop_aware
= 0;
4403 rs
->waiting_for_stop_reply
= 0;
4404 rs
->ctrlc_pending_p
= 0;
4406 rs
->general_thread
= not_sent_ptid
;
4407 rs
->continue_thread
= not_sent_ptid
;
4408 rs
->remote_traceframe_number
= -1;
4410 /* Probe for ability to use "ThreadInfo" query, as required. */
4411 rs
->use_threadinfo_query
= 1;
4412 rs
->use_threadextra_query
= 1;
4414 if (target_async_permitted
)
4416 /* With this target we start out by owning the terminal. */
4417 remote_async_terminal_ours_p
= 1;
4419 /* FIXME: cagney/1999-09-23: During the initial connection it is
4420 assumed that the target is already ready and able to respond to
4421 requests. Unfortunately remote_start_remote() eventually calls
4422 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4423 around this. Eventually a mechanism that allows
4424 wait_for_inferior() to expect/get timeouts will be
4426 wait_forever_enabled_p
= 0;
4429 /* First delete any symbols previously loaded from shared libraries. */
4430 no_shared_libraries (NULL
, 0);
4433 init_thread_list ();
4435 /* Start the remote connection. If error() or QUIT, discard this
4436 target (we'd otherwise be in an inconsistent state) and then
4437 propogate the error on up the exception chain. This ensures that
4438 the caller doesn't stumble along blindly assuming that the
4439 function succeeded. The CLI doesn't have this problem but other
4440 UI's, such as MI do.
4442 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4443 this function should return an error indication letting the
4444 caller restore the previous state. Unfortunately the command
4445 ``target remote'' is directly wired to this function making that
4446 impossible. On a positive note, the CLI side of this problem has
4447 been fixed - the function set_cmd_context() makes it possible for
4448 all the ``target ....'' commands to share a common callback
4449 function. See cli-dump.c. */
4451 volatile struct gdb_exception ex
;
4453 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4455 remote_start_remote (from_tty
, target
, extended_p
);
4459 /* Pop the partially set up target - unless something else did
4460 already before throwing the exception. */
4461 if (rs
->remote_desc
!= NULL
)
4462 remote_unpush_target ();
4463 if (target_async_permitted
)
4464 wait_forever_enabled_p
= 1;
4465 throw_exception (ex
);
4469 if (target_async_permitted
)
4470 wait_forever_enabled_p
= 1;
4473 /* This takes a program previously attached to and detaches it. After
4474 this is done, GDB can be used to debug some other program. We
4475 better not have left any breakpoints in the target program or it'll
4476 die when it hits one. */
4479 remote_detach_1 (const char *args
, int from_tty
, int extended
)
4481 int pid
= ptid_get_pid (inferior_ptid
);
4482 struct remote_state
*rs
= get_remote_state ();
4485 error (_("Argument given to \"detach\" when remotely debugging."));
4487 if (!target_has_execution
)
4488 error (_("No process to detach from."));
4492 char *exec_file
= get_exec_file (0);
4493 if (exec_file
== NULL
)
4495 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4496 target_pid_to_str (pid_to_ptid (pid
)));
4497 gdb_flush (gdb_stdout
);
4500 /* Tell the remote target to detach. */
4501 if (remote_multi_process_p (rs
))
4502 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4504 strcpy (rs
->buf
, "D");
4507 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4509 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4511 else if (rs
->buf
[0] == '\0')
4512 error (_("Remote doesn't know how to detach"));
4514 error (_("Can't detach process."));
4516 if (from_tty
&& !extended
)
4517 puts_filtered (_("Ending remote debugging.\n"));
4519 target_mourn_inferior ();
4523 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4525 remote_detach_1 (args
, from_tty
, 0);
4529 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4531 remote_detach_1 (args
, from_tty
, 1);
4534 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4537 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4540 error (_("Argument given to \"disconnect\" when remotely debugging."));
4542 /* Make sure we unpush even the extended remote targets; mourn
4543 won't do it. So call remote_mourn_1 directly instead of
4544 target_mourn_inferior. */
4545 remote_mourn_1 (target
);
4548 puts_filtered ("Ending remote debugging.\n");
4551 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4552 be chatty about it. */
4555 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4557 struct remote_state
*rs
= get_remote_state ();
4559 char *wait_status
= NULL
;
4561 pid
= parse_pid_to_attach (args
);
4563 /* Remote PID can be freely equal to getpid, do not check it here the same
4564 way as in other targets. */
4566 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4567 error (_("This target does not support attaching to a process"));
4571 char *exec_file
= get_exec_file (0);
4574 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4575 target_pid_to_str (pid_to_ptid (pid
)));
4577 printf_unfiltered (_("Attaching to %s\n"),
4578 target_pid_to_str (pid_to_ptid (pid
)));
4580 gdb_flush (gdb_stdout
);
4583 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4585 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4587 if (packet_ok (rs
->buf
,
4588 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4592 /* Save the reply for later. */
4593 wait_status
= alloca (strlen (rs
->buf
) + 1);
4594 strcpy (wait_status
, rs
->buf
);
4596 else if (strcmp (rs
->buf
, "OK") != 0)
4597 error (_("Attaching to %s failed with: %s"),
4598 target_pid_to_str (pid_to_ptid (pid
)),
4601 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4602 error (_("This target does not support attaching to a process"));
4604 error (_("Attaching to %s failed"),
4605 target_pid_to_str (pid_to_ptid (pid
)));
4607 set_current_inferior (remote_add_inferior (0, pid
, 1));
4609 inferior_ptid
= pid_to_ptid (pid
);
4613 struct thread_info
*thread
;
4615 /* Get list of threads. */
4616 remote_threads_info (target
);
4618 thread
= first_thread_of_process (pid
);
4620 inferior_ptid
= thread
->ptid
;
4622 inferior_ptid
= pid_to_ptid (pid
);
4624 /* Invalidate our notion of the remote current thread. */
4625 record_currthread (rs
, minus_one_ptid
);
4629 /* Now, if we have thread information, update inferior_ptid. */
4630 inferior_ptid
= remote_current_thread (inferior_ptid
);
4632 /* Add the main thread to the thread list. */
4633 add_thread_silent (inferior_ptid
);
4636 /* Next, if the target can specify a description, read it. We do
4637 this before anything involving memory or registers. */
4638 target_find_description ();
4642 /* Use the previously fetched status. */
4643 gdb_assert (wait_status
!= NULL
);
4645 if (target_can_async_p ())
4647 struct notif_event
*reply
4648 = remote_notif_parse (¬if_client_stop
, wait_status
);
4650 push_stop_reply ((struct stop_reply
*) reply
);
4652 target_async (inferior_event_handler
, 0);
4656 gdb_assert (wait_status
!= NULL
);
4657 strcpy (rs
->buf
, wait_status
);
4658 rs
->cached_wait_status
= 1;
4662 gdb_assert (wait_status
== NULL
);
4666 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4668 extended_remote_attach_1 (ops
, args
, from_tty
);
4671 /* Convert hex digit A to a number. */
4676 if (a
>= '0' && a
<= '9')
4678 else if (a
>= 'a' && a
<= 'f')
4679 return a
- 'a' + 10;
4680 else if (a
>= 'A' && a
<= 'F')
4681 return a
- 'A' + 10;
4683 error (_("Reply contains invalid hex digit %d"), a
);
4687 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4691 for (i
= 0; i
< count
; i
++)
4693 if (hex
[0] == 0 || hex
[1] == 0)
4695 /* Hex string is short, or of uneven length.
4696 Return the count that has been converted so far. */
4699 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4705 /* Convert number NIB to a hex digit. */
4713 return 'a' + nib
- 10;
4717 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4721 /* May use a length, or a nul-terminated string as input. */
4723 count
= strlen ((char *) bin
);
4725 for (i
= 0; i
< count
; i
++)
4727 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4728 *hex
++ = tohex (*bin
++ & 0xf);
4734 /* Check for the availability of vCont. This function should also check
4738 remote_vcont_probe (struct remote_state
*rs
)
4742 strcpy (rs
->buf
, "vCont?");
4744 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4747 /* Make sure that the features we assume are supported. */
4748 if (strncmp (buf
, "vCont", 5) == 0)
4751 int support_s
, support_S
, support_c
, support_C
;
4757 rs
->supports_vCont
.t
= 0;
4758 rs
->supports_vCont
.r
= 0;
4759 while (p
&& *p
== ';')
4762 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4764 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4766 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4768 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4770 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4771 rs
->supports_vCont
.t
= 1;
4772 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4773 rs
->supports_vCont
.r
= 1;
4775 p
= strchr (p
, ';');
4778 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4779 BUF will make packet_ok disable the packet. */
4780 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4784 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4787 /* Helper function for building "vCont" resumptions. Write a
4788 resumption to P. ENDP points to one-passed-the-end of the buffer
4789 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4790 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4791 resumed thread should be single-stepped and/or signalled. If PTID
4792 equals minus_one_ptid, then all threads are resumed; if PTID
4793 represents a process, then all threads of the process are resumed;
4794 the thread to be stepped and/or signalled is given in the global
4798 append_resumption (char *p
, char *endp
,
4799 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4801 struct remote_state
*rs
= get_remote_state ();
4803 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4804 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4806 /* GDB is willing to range step. */
4807 && use_range_stepping
4808 /* Target supports range stepping. */
4809 && rs
->supports_vCont
.r
4810 /* We don't currently support range stepping multiple
4811 threads with a wildcard (though the protocol allows it,
4812 so stubs shouldn't make an active effort to forbid
4814 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4816 struct thread_info
*tp
;
4818 if (ptid_equal (ptid
, minus_one_ptid
))
4820 /* If we don't know about the target thread's tid, then
4821 we're resuming magic_null_ptid (see caller). */
4822 tp
= find_thread_ptid (magic_null_ptid
);
4825 tp
= find_thread_ptid (ptid
);
4826 gdb_assert (tp
!= NULL
);
4828 if (tp
->control
.may_range_step
)
4830 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4832 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
4833 phex_nz (tp
->control
.step_range_start
,
4835 phex_nz (tp
->control
.step_range_end
,
4839 p
+= xsnprintf (p
, endp
- p
, ";s");
4842 p
+= xsnprintf (p
, endp
- p
, ";s");
4843 else if (siggnal
!= GDB_SIGNAL_0
)
4844 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4846 p
+= xsnprintf (p
, endp
- p
, ";c");
4848 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4852 /* All (-1) threads of process. */
4853 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4855 p
+= xsnprintf (p
, endp
- p
, ":");
4856 p
= write_ptid (p
, endp
, nptid
);
4858 else if (!ptid_equal (ptid
, minus_one_ptid
))
4860 p
+= xsnprintf (p
, endp
- p
, ":");
4861 p
= write_ptid (p
, endp
, ptid
);
4867 /* Append a vCont continue-with-signal action for threads that have a
4868 non-zero stop signal. */
4871 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4873 struct thread_info
*thread
;
4875 ALL_THREADS (thread
)
4876 if (ptid_match (thread
->ptid
, ptid
)
4877 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4878 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4879 && signal_pass_state (thread
->suspend
.stop_signal
))
4881 p
= append_resumption (p
, endp
, thread
->ptid
,
4882 0, thread
->suspend
.stop_signal
);
4883 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4889 /* Resume the remote inferior by using a "vCont" packet. The thread
4890 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4891 resumed thread should be single-stepped and/or signalled. If PTID
4892 equals minus_one_ptid, then all threads are resumed; the thread to
4893 be stepped and/or signalled is given in the global INFERIOR_PTID.
4894 This function returns non-zero iff it resumes the inferior.
4896 This function issues a strict subset of all possible vCont commands at the
4900 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4902 struct remote_state
*rs
= get_remote_state ();
4906 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4907 remote_vcont_probe (rs
);
4909 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4913 endp
= rs
->buf
+ get_remote_packet_size ();
4915 /* If we could generate a wider range of packets, we'd have to worry
4916 about overflowing BUF. Should there be a generic
4917 "multi-part-packet" packet? */
4919 p
+= xsnprintf (p
, endp
- p
, "vCont");
4921 if (ptid_equal (ptid
, magic_null_ptid
))
4923 /* MAGIC_NULL_PTID means that we don't have any active threads,
4924 so we don't have any TID numbers the inferior will
4925 understand. Make sure to only send forms that do not specify
4927 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4929 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4931 /* Resume all threads (of all processes, or of a single
4932 process), with preference for INFERIOR_PTID. This assumes
4933 inferior_ptid belongs to the set of all threads we are about
4935 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4937 /* Step inferior_ptid, with or without signal. */
4938 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4941 /* Also pass down any pending signaled resumption for other
4942 threads not the current. */
4943 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4945 /* And continue others without a signal. */
4946 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4950 /* Scheduler locking; resume only PTID. */
4951 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4954 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4959 /* In non-stop, the stub replies to vCont with "OK". The stop
4960 reply will be reported asynchronously by means of a `%Stop'
4962 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4963 if (strcmp (rs
->buf
, "OK") != 0)
4964 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4970 /* Tell the remote machine to resume. */
4973 remote_resume (struct target_ops
*ops
,
4974 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4976 struct remote_state
*rs
= get_remote_state ();
4979 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4980 (explained in remote-notif.c:handle_notification) so
4981 remote_notif_process is not called. We need find a place where
4982 it is safe to start a 'vNotif' sequence. It is good to do it
4983 before resuming inferior, because inferior was stopped and no RSP
4984 traffic at that moment. */
4986 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
4988 rs
->last_sent_signal
= siggnal
;
4989 rs
->last_sent_step
= step
;
4991 /* The vCont packet doesn't need to specify threads via Hc. */
4992 /* No reverse support (yet) for vCont. */
4993 if (execution_direction
!= EXEC_REVERSE
)
4994 if (remote_vcont_resume (ptid
, step
, siggnal
))
4997 /* All other supported resume packets do use Hc, so set the continue
4999 if (ptid_equal (ptid
, minus_one_ptid
))
5000 set_continue_thread (any_thread_ptid
);
5002 set_continue_thread (ptid
);
5005 if (execution_direction
== EXEC_REVERSE
)
5007 /* We don't pass signals to the target in reverse exec mode. */
5008 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5009 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5013 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
5014 error (_("Remote reverse-step not supported."));
5016 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
5017 error (_("Remote reverse-continue not supported."));
5019 strcpy (buf
, step
? "bs" : "bc");
5021 else if (siggnal
!= GDB_SIGNAL_0
)
5023 buf
[0] = step
? 'S' : 'C';
5024 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5025 buf
[2] = tohex (((int) siggnal
) & 0xf);
5029 strcpy (buf
, step
? "s" : "c");
5034 /* We are about to start executing the inferior, let's register it
5035 with the event loop. NOTE: this is the one place where all the
5036 execution commands end up. We could alternatively do this in each
5037 of the execution commands in infcmd.c. */
5038 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5039 into infcmd.c in order to allow inferior function calls to work
5040 NOT asynchronously. */
5041 if (target_can_async_p ())
5042 target_async (inferior_event_handler
, 0);
5044 /* We've just told the target to resume. The remote server will
5045 wait for the inferior to stop, and then send a stop reply. In
5046 the mean time, we can't start another command/query ourselves
5047 because the stub wouldn't be ready to process it. This applies
5048 only to the base all-stop protocol, however. In non-stop (which
5049 only supports vCont), the stub replies with an "OK", and is
5050 immediate able to process further serial input. */
5052 rs
->waiting_for_stop_reply
= 1;
5056 /* Set up the signal handler for SIGINT, while the target is
5057 executing, ovewriting the 'regular' SIGINT signal handler. */
5059 async_initialize_sigint_signal_handler (void)
5061 signal (SIGINT
, async_handle_remote_sigint
);
5064 /* Signal handler for SIGINT, while the target is executing. */
5066 async_handle_remote_sigint (int sig
)
5068 signal (sig
, async_handle_remote_sigint_twice
);
5069 mark_async_signal_handler (async_sigint_remote_token
);
5072 /* Signal handler for SIGINT, installed after SIGINT has already been
5073 sent once. It will take effect the second time that the user sends
5076 async_handle_remote_sigint_twice (int sig
)
5078 signal (sig
, async_handle_remote_sigint
);
5079 mark_async_signal_handler (async_sigint_remote_twice_token
);
5082 /* Perform the real interruption of the target execution, in response
5085 async_remote_interrupt (gdb_client_data arg
)
5088 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5090 target_stop (inferior_ptid
);
5093 /* Perform interrupt, if the first attempt did not succeed. Just give
5094 up on the target alltogether. */
5096 async_remote_interrupt_twice (gdb_client_data arg
)
5099 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5104 /* Reinstall the usual SIGINT handlers, after the target has
5107 async_cleanup_sigint_signal_handler (void *dummy
)
5109 signal (SIGINT
, handle_sigint
);
5112 /* Send ^C to target to halt it. Target will respond, and send us a
5114 static void (*ofunc
) (int);
5116 /* The command line interface's stop routine. This function is installed
5117 as a signal handler for SIGINT. The first time a user requests a
5118 stop, we call remote_stop to send a break or ^C. If there is no
5119 response from the target (it didn't stop when the user requested it),
5120 we ask the user if he'd like to detach from the target. */
5122 sync_remote_interrupt (int signo
)
5124 /* If this doesn't work, try more severe steps. */
5125 signal (signo
, sync_remote_interrupt_twice
);
5127 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5130 /* The user typed ^C twice. */
5133 sync_remote_interrupt_twice (int signo
)
5135 signal (signo
, ofunc
);
5136 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5137 signal (signo
, sync_remote_interrupt
);
5140 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5141 thread, all threads of a remote process, or all threads of all
5145 remote_stop_ns (ptid_t ptid
)
5147 struct remote_state
*rs
= get_remote_state ();
5149 char *endp
= rs
->buf
+ get_remote_packet_size ();
5151 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
5152 remote_vcont_probe (rs
);
5154 if (!rs
->supports_vCont
.t
)
5155 error (_("Remote server does not support stopping threads"));
5157 if (ptid_equal (ptid
, minus_one_ptid
)
5158 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5159 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5164 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5166 if (ptid_is_pid (ptid
))
5167 /* All (-1) threads of process. */
5168 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
5171 /* Small optimization: if we already have a stop reply for
5172 this thread, no use in telling the stub we want this
5174 if (peek_stop_reply (ptid
))
5180 write_ptid (p
, endp
, nptid
);
5183 /* In non-stop, we get an immediate OK reply. The stop reply will
5184 come in asynchronously by notification. */
5186 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5187 if (strcmp (rs
->buf
, "OK") != 0)
5188 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5191 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5192 remote target. It is undefined which thread of which process
5193 reports the stop. */
5196 remote_stop_as (ptid_t ptid
)
5198 struct remote_state
*rs
= get_remote_state ();
5200 rs
->ctrlc_pending_p
= 1;
5202 /* If the inferior is stopped already, but the core didn't know
5203 about it yet, just ignore the request. The cached wait status
5204 will be collected in remote_wait. */
5205 if (rs
->cached_wait_status
)
5208 /* Send interrupt_sequence to remote target. */
5209 send_interrupt_sequence ();
5212 /* This is the generic stop called via the target vector. When a target
5213 interrupt is requested, either by the command line or the GUI, we
5214 will eventually end up here. */
5217 remote_stop (ptid_t ptid
)
5220 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5223 remote_stop_ns (ptid
);
5225 remote_stop_as (ptid
);
5228 /* Ask the user what to do when an interrupt is received. */
5231 interrupt_query (void)
5233 target_terminal_ours ();
5235 if (target_can_async_p ())
5237 signal (SIGINT
, handle_sigint
);
5242 if (query (_("Interrupted while waiting for the program.\n\
5243 Give up (and stop debugging it)? ")))
5245 remote_unpush_target ();
5250 target_terminal_inferior ();
5253 /* Enable/disable target terminal ownership. Most targets can use
5254 terminal groups to control terminal ownership. Remote targets are
5255 different in that explicit transfer of ownership to/from GDB/target
5259 remote_terminal_inferior (void)
5261 if (!target_async_permitted
)
5262 /* Nothing to do. */
5265 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5266 idempotent. The event-loop GDB talking to an asynchronous target
5267 with a synchronous command calls this function from both
5268 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5269 transfer the terminal to the target when it shouldn't this guard
5271 if (!remote_async_terminal_ours_p
)
5273 delete_file_handler (input_fd
);
5274 remote_async_terminal_ours_p
= 0;
5275 async_initialize_sigint_signal_handler ();
5276 /* NOTE: At this point we could also register our selves as the
5277 recipient of all input. Any characters typed could then be
5278 passed on down to the target. */
5282 remote_terminal_ours (void)
5284 if (!target_async_permitted
)
5285 /* Nothing to do. */
5288 /* See FIXME in remote_terminal_inferior. */
5289 if (remote_async_terminal_ours_p
)
5291 async_cleanup_sigint_signal_handler (NULL
);
5292 add_file_handler (input_fd
, stdin_event_handler
, 0);
5293 remote_async_terminal_ours_p
= 1;
5297 remote_console_output (char *msg
)
5301 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5304 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5308 fputs_unfiltered (tb
, gdb_stdtarg
);
5310 gdb_flush (gdb_stdtarg
);
5313 typedef struct cached_reg
5316 gdb_byte data
[MAX_REGISTER_SIZE
];
5319 DEF_VEC_O(cached_reg_t
);
5321 typedef struct stop_reply
5323 struct notif_event base
;
5325 /* The identifier of the thread about this event */
5328 /* The remote state this event is associated with. When the remote
5329 connection, represented by a remote_state object, is closed,
5330 all the associated stop_reply events should be released. */
5331 struct remote_state
*rs
;
5333 struct target_waitstatus ws
;
5335 /* Expedited registers. This makes remote debugging a bit more
5336 efficient for those targets that provide critical registers as
5337 part of their normal status mechanism (as another roundtrip to
5338 fetch them is avoided). */
5339 VEC(cached_reg_t
) *regcache
;
5341 int stopped_by_watchpoint_p
;
5342 CORE_ADDR watch_data_address
;
5347 DECLARE_QUEUE_P (stop_reply_p
);
5348 DEFINE_QUEUE_P (stop_reply_p
);
5349 /* The list of already fetched and acknowledged stop events. This
5350 queue is used for notification Stop, and other notifications
5351 don't need queue for their events, because the notification events
5352 of Stop can't be consumed immediately, so that events should be
5353 queued first, and be consumed by remote_wait_{ns,as} one per
5354 time. Other notifications can consume their events immediately,
5355 so queue is not needed for them. */
5356 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5359 stop_reply_xfree (struct stop_reply
*r
)
5361 notif_event_xfree ((struct notif_event
*) r
);
5365 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5366 struct notif_event
*event
)
5368 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5372 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5373 struct notif_event
*event
)
5375 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5378 putpkt ((char *) self
->ack_command
);
5380 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5381 /* We got an unknown stop reply. */
5382 error (_("Unknown stop reply"));
5384 push_stop_reply (stop_reply
);
5388 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5390 /* We can't get pending events in remote_notif_process for
5391 notification stop, and we have to do this in remote_wait_ns
5392 instead. If we fetch all queued events from stub, remote stub
5393 may exit and we have no chance to process them back in
5395 mark_async_event_handler (remote_async_inferior_event_token
);
5400 stop_reply_dtr (struct notif_event
*event
)
5402 struct stop_reply
*r
= (struct stop_reply
*) event
;
5404 VEC_free (cached_reg_t
, r
->regcache
);
5407 static struct notif_event
*
5408 remote_notif_stop_alloc_reply (void)
5410 struct notif_event
*r
5411 = (struct notif_event
*) XNEW (struct stop_reply
);
5413 r
->dtr
= stop_reply_dtr
;
5418 /* A client of notification Stop. */
5420 struct notif_client notif_client_stop
=
5424 remote_notif_stop_parse
,
5425 remote_notif_stop_ack
,
5426 remote_notif_stop_can_get_pending_events
,
5427 remote_notif_stop_alloc_reply
,
5431 /* A parameter to pass data in and out. */
5433 struct queue_iter_param
5436 struct stop_reply
*output
;
5439 /* Remove stop replies in the queue if its pid is equal to the given
5443 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
5444 QUEUE_ITER (stop_reply_p
) *iter
,
5448 struct queue_iter_param
*param
= data
;
5449 struct inferior
*inf
= param
->input
;
5451 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
5453 stop_reply_xfree (event
);
5454 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5460 /* Discard all pending stop replies of inferior INF. */
5463 discard_pending_stop_replies (struct inferior
*inf
)
5466 struct queue_iter_param param
;
5467 struct stop_reply
*reply
;
5468 struct remote_state
*rs
= get_remote_state ();
5469 struct remote_notif_state
*rns
= rs
->notif_state
;
5471 /* This function can be notified when an inferior exists. When the
5472 target is not remote, the notification state is NULL. */
5473 if (rs
->remote_desc
== NULL
)
5476 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
5478 /* Discard the in-flight notification. */
5479 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
5481 stop_reply_xfree (reply
);
5482 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
5486 param
.output
= NULL
;
5487 /* Discard the stop replies we have already pulled with
5489 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5490 remove_stop_reply_for_inferior
, ¶m
);
5493 /* If its remote state is equal to the given remote state,
5494 remove EVENT from the stop reply queue. */
5497 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
5498 QUEUE_ITER (stop_reply_p
) *iter
,
5502 struct queue_iter_param
*param
= data
;
5503 struct remote_state
*rs
= param
->input
;
5505 if (event
->rs
== rs
)
5507 stop_reply_xfree (event
);
5508 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5514 /* Discard the stop replies for RS in stop_reply_queue. */
5517 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
5519 struct queue_iter_param param
;
5522 param
.output
= NULL
;
5523 /* Discard the stop replies we have already pulled with
5525 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5526 remove_stop_reply_of_remote_state
, ¶m
);
5529 /* A parameter to pass data in and out. */
5532 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5533 QUEUE_ITER (stop_reply_p
) *iter
,
5537 struct queue_iter_param
*param
= data
;
5538 ptid_t
*ptid
= param
->input
;
5540 if (ptid_match (event
->ptid
, *ptid
))
5542 param
->output
= event
;
5543 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5550 /* Remove the first reply in 'stop_reply_queue' which matches
5553 static struct stop_reply
*
5554 remote_notif_remove_queued_reply (ptid_t ptid
)
5556 struct queue_iter_param param
;
5558 param
.input
= &ptid
;
5559 param
.output
= NULL
;
5561 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5562 remote_notif_remove_once_on_match
, ¶m
);
5564 fprintf_unfiltered (gdb_stdlog
,
5565 "notif: discard queued event: 'Stop' in %s\n",
5566 target_pid_to_str (ptid
));
5568 return param
.output
;
5571 /* Look for a queued stop reply belonging to PTID. If one is found,
5572 remove it from the queue, and return it. Returns NULL if none is
5573 found. If there are still queued events left to process, tell the
5574 event loop to get back to target_wait soon. */
5576 static struct stop_reply
*
5577 queued_stop_reply (ptid_t ptid
)
5579 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5581 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5582 /* There's still at least an event left. */
5583 mark_async_event_handler (remote_async_inferior_event_token
);
5588 /* Push a fully parsed stop reply in the stop reply queue. Since we
5589 know that we now have at least one queued event left to pass to the
5590 core side, tell the event loop to get back to target_wait soon. */
5593 push_stop_reply (struct stop_reply
*new_event
)
5595 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5598 fprintf_unfiltered (gdb_stdlog
,
5599 "notif: push 'Stop' %s to queue %d\n",
5600 target_pid_to_str (new_event
->ptid
),
5601 QUEUE_length (stop_reply_p
,
5604 mark_async_event_handler (remote_async_inferior_event_token
);
5608 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5609 QUEUE_ITER (stop_reply_p
) *iter
,
5610 struct stop_reply
*event
,
5613 ptid_t
*ptid
= data
;
5615 return !(ptid_equal (*ptid
, event
->ptid
)
5616 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5619 /* Returns true if we have a stop reply for PTID. */
5622 peek_stop_reply (ptid_t ptid
)
5624 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5625 stop_reply_match_ptid_and_ws
, &ptid
);
5628 /* Parse the stop reply in BUF. Either the function succeeds, and the
5629 result is stored in EVENT, or throws an error. */
5632 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5634 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5638 event
->ptid
= null_ptid
;
5639 event
->rs
= get_remote_state ();
5640 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5641 event
->ws
.value
.integer
= 0;
5642 event
->stopped_by_watchpoint_p
= 0;
5643 event
->regcache
= NULL
;
5648 case 'T': /* Status with PC, SP, FP, ... */
5649 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5650 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5652 n... = register number
5653 r... = register contents
5656 p
= &buf
[3]; /* after Txx */
5664 /* If the packet contains a register number, save it in
5665 pnum and set p1 to point to the character following it.
5666 Otherwise p1 points to p. */
5668 /* If this packet is an awatch packet, don't parse the 'a'
5669 as a register number. */
5671 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5672 && strncmp (p
, "core", strlen ("core") != 0))
5674 /* Read the ``P'' register number. */
5675 pnum
= strtol (p
, &p_temp
, 16);
5681 if (p1
== p
) /* No register number present here. */
5683 p1
= strchr (p
, ':');
5685 error (_("Malformed packet(a) (missing colon): %s\n\
5688 if (strncmp (p
, "thread", p1
- p
) == 0)
5689 event
->ptid
= read_ptid (++p1
, &p
);
5690 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5691 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5692 || (strncmp (p
, "awatch", p1
- p
) == 0))
5694 event
->stopped_by_watchpoint_p
= 1;
5695 p
= unpack_varlen_hex (++p1
, &addr
);
5696 event
->watch_data_address
= (CORE_ADDR
) addr
;
5698 else if (strncmp (p
, "library", p1
- p
) == 0)
5702 while (*p_temp
&& *p_temp
!= ';')
5705 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5708 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5710 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5711 /* p1 will indicate "begin" or "end", but it makes
5712 no difference for now, so ignore it. */
5713 p_temp
= strchr (p1
+ 1, ';');
5717 else if (strncmp (p
, "core", p1
- p
) == 0)
5721 p
= unpack_varlen_hex (++p1
, &c
);
5726 /* Silently skip unknown optional info. */
5727 p_temp
= strchr (p1
+ 1, ';');
5734 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5735 cached_reg_t cached_reg
;
5740 error (_("Malformed packet(b) (missing colon): %s\n\
5746 error (_("Remote sent bad register number %s: %s\n\
5748 hex_string (pnum
), p
, buf
);
5750 cached_reg
.num
= reg
->regnum
;
5752 fieldsize
= hex2bin (p
, cached_reg
.data
,
5753 register_size (target_gdbarch (),
5756 if (fieldsize
< register_size (target_gdbarch (),
5758 warning (_("Remote reply is too short: %s"), buf
);
5760 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5764 error (_("Remote register badly formatted: %s\nhere: %s"),
5769 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5773 case 'S': /* Old style status, just signal only. */
5777 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5778 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
5779 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
5780 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
5782 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
5785 case 'W': /* Target exited. */
5792 /* GDB used to accept only 2 hex chars here. Stubs should
5793 only send more if they detect GDB supports multi-process
5795 p
= unpack_varlen_hex (&buf
[1], &value
);
5799 /* The remote process exited. */
5800 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5801 event
->ws
.value
.integer
= value
;
5805 /* The remote process exited with a signal. */
5806 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5807 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
5808 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5810 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
5813 /* If no process is specified, assume inferior_ptid. */
5814 pid
= ptid_get_pid (inferior_ptid
);
5823 else if (strncmp (p
,
5824 "process:", sizeof ("process:") - 1) == 0)
5828 p
+= sizeof ("process:") - 1;
5829 unpack_varlen_hex (p
, &upid
);
5833 error (_("unknown stop reply packet: %s"), buf
);
5836 error (_("unknown stop reply packet: %s"), buf
);
5837 event
->ptid
= pid_to_ptid (pid
);
5842 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5843 error (_("No process or thread specified in stop reply: %s"), buf
);
5846 /* When the stub wants to tell GDB about a new notification reply, it
5847 sends a notification (%Stop, for example). Those can come it at
5848 any time, hence, we have to make sure that any pending
5849 putpkt/getpkt sequence we're making is finished, before querying
5850 the stub for more events with the corresponding ack command
5851 (vStopped, for example). E.g., if we started a vStopped sequence
5852 immediately upon receiving the notification, something like this
5860 1.6) <-- (registers reply to step #1.3)
5862 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5865 To solve this, whenever we parse a %Stop notification successfully,
5866 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5867 doing whatever we were doing:
5873 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5874 2.5) <-- (registers reply to step #2.3)
5876 Eventualy after step #2.5, we return to the event loop, which
5877 notices there's an event on the
5878 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5879 associated callback --- the function below. At this point, we're
5880 always safe to start a vStopped sequence. :
5883 2.7) <-- T05 thread:2
5889 remote_notif_get_pending_events (struct notif_client
*nc
)
5891 struct remote_state
*rs
= get_remote_state ();
5893 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
5896 fprintf_unfiltered (gdb_stdlog
,
5897 "notif: process: '%s' ack pending event\n",
5901 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
5902 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
5906 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5907 if (strcmp (rs
->buf
, "OK") == 0)
5910 remote_notif_ack (nc
, rs
->buf
);
5916 fprintf_unfiltered (gdb_stdlog
,
5917 "notif: process: '%s' no pending reply\n",
5922 /* Called when it is decided that STOP_REPLY holds the info of the
5923 event that is to be returned to the core. This function always
5924 destroys STOP_REPLY. */
5927 process_stop_reply (struct stop_reply
*stop_reply
,
5928 struct target_waitstatus
*status
)
5932 *status
= stop_reply
->ws
;
5933 ptid
= stop_reply
->ptid
;
5935 /* If no thread/process was reported by the stub, assume the current
5937 if (ptid_equal (ptid
, null_ptid
))
5938 ptid
= inferior_ptid
;
5940 if (status
->kind
!= TARGET_WAITKIND_EXITED
5941 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5943 struct remote_state
*rs
= get_remote_state ();
5945 /* Expedited registers. */
5946 if (stop_reply
->regcache
)
5948 struct regcache
*regcache
5949 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5954 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5956 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5957 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5960 rs
->remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5961 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
5963 remote_notice_new_inferior (ptid
, 0);
5964 demand_private_info (ptid
)->core
= stop_reply
->core
;
5967 stop_reply_xfree (stop_reply
);
5971 /* The non-stop mode version of target_wait. */
5974 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5976 struct remote_state
*rs
= get_remote_state ();
5977 struct stop_reply
*stop_reply
;
5981 /* If in non-stop mode, get out of getpkt even if a
5982 notification is received. */
5984 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5985 0 /* forever */, &is_notif
);
5988 if (ret
!= -1 && !is_notif
)
5991 case 'E': /* Error of some sort. */
5992 /* We're out of sync with the target now. Did it continue
5993 or not? We can't tell which thread it was in non-stop,
5994 so just ignore this. */
5995 warning (_("Remote failure reply: %s"), rs
->buf
);
5997 case 'O': /* Console output. */
5998 remote_console_output (rs
->buf
+ 1);
6001 warning (_("Invalid remote reply: %s"), rs
->buf
);
6005 /* Acknowledge a pending stop reply that may have arrived in the
6007 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6008 remote_notif_get_pending_events (¬if_client_stop
);
6010 /* If indeed we noticed a stop reply, we're done. */
6011 stop_reply
= queued_stop_reply (ptid
);
6012 if (stop_reply
!= NULL
)
6013 return process_stop_reply (stop_reply
, status
);
6015 /* Still no event. If we're just polling for an event, then
6016 return to the event loop. */
6017 if (options
& TARGET_WNOHANG
)
6019 status
->kind
= TARGET_WAITKIND_IGNORE
;
6020 return minus_one_ptid
;
6023 /* Otherwise do a blocking wait. */
6024 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6025 1 /* forever */, &is_notif
);
6029 /* Wait until the remote machine stops, then return, storing status in
6030 STATUS just as `wait' would. */
6033 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6035 struct remote_state
*rs
= get_remote_state ();
6036 ptid_t event_ptid
= null_ptid
;
6038 struct stop_reply
*stop_reply
;
6042 status
->kind
= TARGET_WAITKIND_IGNORE
;
6043 status
->value
.integer
= 0;
6045 stop_reply
= queued_stop_reply (ptid
);
6046 if (stop_reply
!= NULL
)
6047 return process_stop_reply (stop_reply
, status
);
6049 if (rs
->cached_wait_status
)
6050 /* Use the cached wait status, but only once. */
6051 rs
->cached_wait_status
= 0;
6057 if (!target_is_async_p ())
6059 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
6060 /* If the user hit C-c before this packet, or between packets,
6061 pretend that it was hit right here. */
6062 if (check_quit_flag ())
6065 sync_remote_interrupt (SIGINT
);
6069 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6070 _never_ wait for ever -> test on target_is_async_p().
6071 However, before we do that we need to ensure that the caller
6072 knows how to take the target into/out of async mode. */
6073 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6074 wait_forever_enabled_p
, &is_notif
);
6076 if (!target_is_async_p ())
6077 signal (SIGINT
, ofunc
);
6079 /* GDB gets a notification. Return to core as this event is
6081 if (ret
!= -1 && is_notif
)
6082 return minus_one_ptid
;
6087 rs
->remote_stopped_by_watchpoint_p
= 0;
6089 /* We got something. */
6090 rs
->waiting_for_stop_reply
= 0;
6092 /* Assume that the target has acknowledged Ctrl-C unless we receive
6093 an 'F' or 'O' packet. */
6094 if (buf
[0] != 'F' && buf
[0] != 'O')
6095 rs
->ctrlc_pending_p
= 0;
6099 case 'E': /* Error of some sort. */
6100 /* We're out of sync with the target now. Did it continue or
6101 not? Not is more likely, so report a stop. */
6102 warning (_("Remote failure reply: %s"), buf
);
6103 status
->kind
= TARGET_WAITKIND_STOPPED
;
6104 status
->value
.sig
= GDB_SIGNAL_0
;
6106 case 'F': /* File-I/O request. */
6107 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6108 rs
->ctrlc_pending_p
= 0;
6110 case 'T': case 'S': case 'X': case 'W':
6112 struct stop_reply
*stop_reply
6113 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6116 event_ptid
= process_stop_reply (stop_reply
, status
);
6119 case 'O': /* Console output. */
6120 remote_console_output (buf
+ 1);
6122 /* The target didn't really stop; keep waiting. */
6123 rs
->waiting_for_stop_reply
= 1;
6127 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6129 /* Zero length reply means that we tried 'S' or 'C' and the
6130 remote system doesn't support it. */
6131 target_terminal_ours_for_output ();
6133 ("Can't send signals to this remote system. %s not sent.\n",
6134 gdb_signal_to_name (rs
->last_sent_signal
));
6135 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6136 target_terminal_inferior ();
6138 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6139 putpkt ((char *) buf
);
6141 /* We just told the target to resume, so a stop reply is in
6143 rs
->waiting_for_stop_reply
= 1;
6146 /* else fallthrough */
6148 warning (_("Invalid remote reply: %s"), buf
);
6150 rs
->waiting_for_stop_reply
= 1;
6154 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6156 /* Nothing interesting happened. If we're doing a non-blocking
6157 poll, we're done. Otherwise, go back to waiting. */
6158 if (options
& TARGET_WNOHANG
)
6159 return minus_one_ptid
;
6163 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6164 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6166 if (!ptid_equal (event_ptid
, null_ptid
))
6167 record_currthread (rs
, event_ptid
);
6169 event_ptid
= inferior_ptid
;
6172 /* A process exit. Invalidate our notion of current thread. */
6173 record_currthread (rs
, minus_one_ptid
);
6178 /* Wait until the remote machine stops, then return, storing status in
6179 STATUS just as `wait' would. */
6182 remote_wait (struct target_ops
*ops
,
6183 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6188 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6190 event_ptid
= remote_wait_as (ptid
, status
, options
);
6192 if (target_can_async_p ())
6194 /* If there are are events left in the queue tell the event loop
6196 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6197 mark_async_event_handler (remote_async_inferior_event_token
);
6203 /* Fetch a single register using a 'p' packet. */
6206 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6208 struct remote_state
*rs
= get_remote_state ();
6210 char regp
[MAX_REGISTER_SIZE
];
6213 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
6216 if (reg
->pnum
== -1)
6221 p
+= hexnumstr (p
, reg
->pnum
);
6224 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6228 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6232 case PACKET_UNKNOWN
:
6235 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6236 gdbarch_register_name (get_regcache_arch (regcache
),
6241 /* If this register is unfetchable, tell the regcache. */
6244 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6248 /* Otherwise, parse and supply the value. */
6254 error (_("fetch_register_using_p: early buf termination"));
6256 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6259 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6263 /* Fetch the registers included in the target's 'g' packet. */
6266 send_g_packet (void)
6268 struct remote_state
*rs
= get_remote_state ();
6271 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6272 remote_send (&rs
->buf
, &rs
->buf_size
);
6274 /* We can get out of synch in various cases. If the first character
6275 in the buffer is not a hex character, assume that has happened
6276 and try to fetch another packet to read. */
6277 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6278 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6279 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6280 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6283 fprintf_unfiltered (gdb_stdlog
,
6284 "Bad register packet; fetching a new packet\n");
6285 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6288 buf_len
= strlen (rs
->buf
);
6290 /* Sanity check the received packet. */
6291 if (buf_len
% 2 != 0)
6292 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6298 process_g_packet (struct regcache
*regcache
)
6300 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6301 struct remote_state
*rs
= get_remote_state ();
6302 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6307 buf_len
= strlen (rs
->buf
);
6309 /* Further sanity checks, with knowledge of the architecture. */
6310 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6311 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6313 /* Save the size of the packet sent to us by the target. It is used
6314 as a heuristic when determining the max size of packets that the
6315 target can safely receive. */
6316 if (rsa
->actual_register_packet_size
== 0)
6317 rsa
->actual_register_packet_size
= buf_len
;
6319 /* If this is smaller than we guessed the 'g' packet would be,
6320 update our records. A 'g' reply that doesn't include a register's
6321 value implies either that the register is not available, or that
6322 the 'p' packet must be used. */
6323 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6325 rsa
->sizeof_g_packet
= buf_len
/ 2;
6327 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6329 if (rsa
->regs
[i
].pnum
== -1)
6332 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6333 rsa
->regs
[i
].in_g_packet
= 0;
6335 rsa
->regs
[i
].in_g_packet
= 1;
6339 regs
= alloca (rsa
->sizeof_g_packet
);
6341 /* Unimplemented registers read as all bits zero. */
6342 memset (regs
, 0, rsa
->sizeof_g_packet
);
6344 /* Reply describes registers byte by byte, each byte encoded as two
6345 hex characters. Suck them all up, then supply them to the
6346 register cacheing/storage mechanism. */
6349 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6351 if (p
[0] == 0 || p
[1] == 0)
6352 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6353 internal_error (__FILE__
, __LINE__
,
6354 _("unexpected end of 'g' packet reply"));
6356 if (p
[0] == 'x' && p
[1] == 'x')
6357 regs
[i
] = 0; /* 'x' */
6359 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6363 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6365 struct packet_reg
*r
= &rsa
->regs
[i
];
6369 if (r
->offset
* 2 >= strlen (rs
->buf
))
6370 /* This shouldn't happen - we adjusted in_g_packet above. */
6371 internal_error (__FILE__
, __LINE__
,
6372 _("unexpected end of 'g' packet reply"));
6373 else if (rs
->buf
[r
->offset
* 2] == 'x')
6375 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6376 /* The register isn't available, mark it as such (at
6377 the same time setting the value to zero). */
6378 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6381 regcache_raw_supply (regcache
, r
->regnum
,
6388 fetch_registers_using_g (struct regcache
*regcache
)
6391 process_g_packet (regcache
);
6394 /* Make the remote selected traceframe match GDB's selected
6398 set_remote_traceframe (void)
6401 struct remote_state
*rs
= get_remote_state ();
6403 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6406 /* Avoid recursion, remote_trace_find calls us again. */
6407 rs
->remote_traceframe_number
= get_traceframe_number ();
6409 newnum
= target_trace_find (tfind_number
,
6410 get_traceframe_number (), 0, 0, NULL
);
6412 /* Should not happen. If it does, all bets are off. */
6413 if (newnum
!= get_traceframe_number ())
6414 warning (_("could not set remote traceframe"));
6418 remote_fetch_registers (struct target_ops
*ops
,
6419 struct regcache
*regcache
, int regnum
)
6421 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6424 set_remote_traceframe ();
6425 set_general_thread (inferior_ptid
);
6429 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6431 gdb_assert (reg
!= NULL
);
6433 /* If this register might be in the 'g' packet, try that first -
6434 we are likely to read more than one register. If this is the
6435 first 'g' packet, we might be overly optimistic about its
6436 contents, so fall back to 'p'. */
6437 if (reg
->in_g_packet
)
6439 fetch_registers_using_g (regcache
);
6440 if (reg
->in_g_packet
)
6444 if (fetch_register_using_p (regcache
, reg
))
6447 /* This register is not available. */
6448 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6453 fetch_registers_using_g (regcache
);
6455 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6456 if (!rsa
->regs
[i
].in_g_packet
)
6457 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6459 /* This register is not available. */
6460 regcache_raw_supply (regcache
, i
, NULL
);
6464 /* Prepare to store registers. Since we may send them all (using a
6465 'G' request), we have to read out the ones we don't want to change
6469 remote_prepare_to_store (struct regcache
*regcache
)
6471 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6473 gdb_byte buf
[MAX_REGISTER_SIZE
];
6475 /* Make sure the entire registers array is valid. */
6476 switch (remote_protocol_packets
[PACKET_P
].support
)
6478 case PACKET_DISABLE
:
6479 case PACKET_SUPPORT_UNKNOWN
:
6480 /* Make sure all the necessary registers are cached. */
6481 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6482 if (rsa
->regs
[i
].in_g_packet
)
6483 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6490 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6491 packet was not recognized. */
6494 store_register_using_P (const struct regcache
*regcache
,
6495 struct packet_reg
*reg
)
6497 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6498 struct remote_state
*rs
= get_remote_state ();
6499 /* Try storing a single register. */
6500 char *buf
= rs
->buf
;
6501 gdb_byte regp
[MAX_REGISTER_SIZE
];
6504 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
6507 if (reg
->pnum
== -1)
6510 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6511 p
= buf
+ strlen (buf
);
6512 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6513 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6515 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6517 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6522 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6523 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6524 case PACKET_UNKNOWN
:
6527 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6531 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6532 contents of the register cache buffer. FIXME: ignores errors. */
6535 store_registers_using_G (const struct regcache
*regcache
)
6537 struct remote_state
*rs
= get_remote_state ();
6538 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6542 /* Extract all the registers in the regcache copying them into a
6547 regs
= alloca (rsa
->sizeof_g_packet
);
6548 memset (regs
, 0, rsa
->sizeof_g_packet
);
6549 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6551 struct packet_reg
*r
= &rsa
->regs
[i
];
6554 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6558 /* Command describes registers byte by byte,
6559 each byte encoded as two hex characters. */
6562 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6564 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6566 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6567 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6568 error (_("Could not write registers; remote failure reply '%s'"),
6572 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6573 of the register cache buffer. FIXME: ignores errors. */
6576 remote_store_registers (struct target_ops
*ops
,
6577 struct regcache
*regcache
, int regnum
)
6579 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6582 set_remote_traceframe ();
6583 set_general_thread (inferior_ptid
);
6587 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6589 gdb_assert (reg
!= NULL
);
6591 /* Always prefer to store registers using the 'P' packet if
6592 possible; we often change only a small number of registers.
6593 Sometimes we change a larger number; we'd need help from a
6594 higher layer to know to use 'G'. */
6595 if (store_register_using_P (regcache
, reg
))
6598 /* For now, don't complain if we have no way to write the
6599 register. GDB loses track of unavailable registers too
6600 easily. Some day, this may be an error. We don't have
6601 any way to read the register, either... */
6602 if (!reg
->in_g_packet
)
6605 store_registers_using_G (regcache
);
6609 store_registers_using_G (regcache
);
6611 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6612 if (!rsa
->regs
[i
].in_g_packet
)
6613 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6614 /* See above for why we do not issue an error here. */
6619 /* Return the number of hex digits in num. */
6622 hexnumlen (ULONGEST num
)
6626 for (i
= 0; num
!= 0; i
++)
6632 /* Set BUF to the minimum number of hex digits representing NUM. */
6635 hexnumstr (char *buf
, ULONGEST num
)
6637 int len
= hexnumlen (num
);
6639 return hexnumnstr (buf
, num
, len
);
6643 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6646 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6652 for (i
= width
- 1; i
>= 0; i
--)
6654 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6661 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6664 remote_address_masked (CORE_ADDR addr
)
6666 unsigned int address_size
= remote_address_size
;
6668 /* If "remoteaddresssize" was not set, default to target address size. */
6670 address_size
= gdbarch_addr_bit (target_gdbarch ());
6672 if (address_size
> 0
6673 && address_size
< (sizeof (ULONGEST
) * 8))
6675 /* Only create a mask when that mask can safely be constructed
6676 in a ULONGEST variable. */
6679 mask
= (mask
<< address_size
) - 1;
6685 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6686 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6687 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6688 (which may be more than *OUT_LEN due to escape characters). The
6689 total number of bytes in the output buffer will be at most
6693 remote_escape_output (const gdb_byte
*buffer
, int len
,
6694 gdb_byte
*out_buf
, int *out_len
,
6697 int input_index
, output_index
;
6700 for (input_index
= 0; input_index
< len
; input_index
++)
6702 gdb_byte b
= buffer
[input_index
];
6704 if (b
== '$' || b
== '#' || b
== '}')
6706 /* These must be escaped. */
6707 if (output_index
+ 2 > out_maxlen
)
6709 out_buf
[output_index
++] = '}';
6710 out_buf
[output_index
++] = b
^ 0x20;
6714 if (output_index
+ 1 > out_maxlen
)
6716 out_buf
[output_index
++] = b
;
6720 *out_len
= input_index
;
6721 return output_index
;
6724 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6725 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6726 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6728 This function reverses remote_escape_output. It allows more
6729 escaped characters than that function does, in particular because
6730 '*' must be escaped to avoid the run-length encoding processing
6731 in reading packets. */
6734 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6735 gdb_byte
*out_buf
, int out_maxlen
)
6737 int input_index
, output_index
;
6742 for (input_index
= 0; input_index
< len
; input_index
++)
6744 gdb_byte b
= buffer
[input_index
];
6746 if (output_index
+ 1 > out_maxlen
)
6748 warning (_("Received too much data from remote target;"
6749 " ignoring overflow."));
6750 return output_index
;
6755 out_buf
[output_index
++] = b
^ 0x20;
6761 out_buf
[output_index
++] = b
;
6765 error (_("Unmatched escape character in target response."));
6767 return output_index
;
6770 /* Determine whether the remote target supports binary downloading.
6771 This is accomplished by sending a no-op memory write of zero length
6772 to the target at the specified address. It does not suffice to send
6773 the whole packet, since many stubs strip the eighth bit and
6774 subsequently compute a wrong checksum, which causes real havoc with
6777 NOTE: This can still lose if the serial line is not eight-bit
6778 clean. In cases like this, the user should clear "remote
6782 check_binary_download (CORE_ADDR addr
)
6784 struct remote_state
*rs
= get_remote_state ();
6786 switch (remote_protocol_packets
[PACKET_X
].support
)
6788 case PACKET_DISABLE
:
6792 case PACKET_SUPPORT_UNKNOWN
:
6798 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6800 p
+= hexnumstr (p
, (ULONGEST
) 0);
6804 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6805 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6807 if (rs
->buf
[0] == '\0')
6810 fprintf_unfiltered (gdb_stdlog
,
6811 "binary downloading NOT "
6812 "supported by target\n");
6813 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6818 fprintf_unfiltered (gdb_stdlog
,
6819 "binary downloading supported by target\n");
6820 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6827 /* Write memory data directly to the remote machine.
6828 This does not inform the data cache; the data cache uses this.
6829 HEADER is the starting part of the packet.
6830 MEMADDR is the address in the remote memory space.
6831 MYADDR is the address of the buffer in our space.
6832 LEN is the number of bytes.
6833 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6834 should send data as binary ('X'), or hex-encoded ('M').
6836 The function creates packet of the form
6837 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6839 where encoding of <DATA> is termined by PACKET_FORMAT.
6841 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6844 Returns the number of bytes transferred, or a negative value (an
6845 'enum target_xfer_error' value) for error. Only transfer a single
6849 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6850 const gdb_byte
*myaddr
, ssize_t len
,
6851 char packet_format
, int use_length
)
6853 struct remote_state
*rs
= get_remote_state ();
6863 if (packet_format
!= 'X' && packet_format
!= 'M')
6864 internal_error (__FILE__
, __LINE__
,
6865 _("remote_write_bytes_aux: bad packet format"));
6870 payload_size
= get_memory_write_packet_size ();
6872 /* The packet buffer will be large enough for the payload;
6873 get_memory_packet_size ensures this. */
6876 /* Compute the size of the actual payload by subtracting out the
6877 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6879 payload_size
-= strlen ("$,:#NN");
6881 /* The comma won't be used. */
6883 header_length
= strlen (header
);
6884 payload_size
-= header_length
;
6885 payload_size
-= hexnumlen (memaddr
);
6887 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6889 strcat (rs
->buf
, header
);
6890 p
= rs
->buf
+ strlen (header
);
6892 /* Compute a best guess of the number of bytes actually transfered. */
6893 if (packet_format
== 'X')
6895 /* Best guess at number of bytes that will fit. */
6896 todo
= min (len
, payload_size
);
6898 payload_size
-= hexnumlen (todo
);
6899 todo
= min (todo
, payload_size
);
6903 /* Num bytes that will fit. */
6904 todo
= min (len
, payload_size
/ 2);
6906 payload_size
-= hexnumlen (todo
);
6907 todo
= min (todo
, payload_size
/ 2);
6911 internal_error (__FILE__
, __LINE__
,
6912 _("minimum packet size too small to write data"));
6914 /* If we already need another packet, then try to align the end
6915 of this packet to a useful boundary. */
6916 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6917 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6919 /* Append "<memaddr>". */
6920 memaddr
= remote_address_masked (memaddr
);
6921 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6928 /* Append <len>. Retain the location/size of <len>. It may need to
6929 be adjusted once the packet body has been created. */
6931 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6939 /* Append the packet body. */
6940 if (packet_format
== 'X')
6942 /* Binary mode. Send target system values byte by byte, in
6943 increasing byte addresses. Only escape certain critical
6945 payload_length
= remote_escape_output (myaddr
, todo
, (gdb_byte
*) p
,
6946 &nr_bytes
, payload_size
);
6948 /* If not all TODO bytes fit, then we'll need another packet. Make
6949 a second try to keep the end of the packet aligned. Don't do
6950 this if the packet is tiny. */
6951 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6955 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6957 if (new_nr_bytes
!= nr_bytes
)
6958 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6959 (gdb_byte
*) p
, &nr_bytes
,
6963 p
+= payload_length
;
6964 if (use_length
&& nr_bytes
< todo
)
6966 /* Escape chars have filled up the buffer prematurely,
6967 and we have actually sent fewer bytes than planned.
6968 Fix-up the length field of the packet. Use the same
6969 number of characters as before. */
6970 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6971 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6976 /* Normal mode: Send target system values byte by byte, in
6977 increasing byte addresses. Each byte is encoded as a two hex
6979 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6983 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6984 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6986 if (rs
->buf
[0] == 'E')
6987 return TARGET_XFER_E_IO
;
6989 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6990 fewer bytes than we'd planned. */
6994 /* Write memory data directly to the remote machine.
6995 This does not inform the data cache; the data cache uses this.
6996 MEMADDR is the address in the remote memory space.
6997 MYADDR is the address of the buffer in our space.
6998 LEN is the number of bytes.
7000 Returns number of bytes transferred, or a negative value (an 'enum
7001 target_xfer_error' value) for error. Only transfer a single
7005 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
7007 char *packet_format
= 0;
7009 /* Check whether the target supports binary download. */
7010 check_binary_download (memaddr
);
7012 switch (remote_protocol_packets
[PACKET_X
].support
)
7015 packet_format
= "X";
7017 case PACKET_DISABLE
:
7018 packet_format
= "M";
7020 case PACKET_SUPPORT_UNKNOWN
:
7021 internal_error (__FILE__
, __LINE__
,
7022 _("remote_write_bytes: bad internal state"));
7024 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7027 return remote_write_bytes_aux (packet_format
,
7028 memaddr
, myaddr
, len
, packet_format
[0], 1);
7031 /* Read memory data directly from the remote machine.
7032 This does not use the data cache; the data cache uses this.
7033 MEMADDR is the address in the remote memory space.
7034 MYADDR is the address of the buffer in our space.
7035 LEN is the number of bytes.
7037 Returns number of bytes transferred, or a negative value (an 'enum
7038 target_xfer_error' value) for error. */
7041 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
7043 struct remote_state
*rs
= get_remote_state ();
7044 int max_buf_size
; /* Max size of packet output buffer. */
7052 max_buf_size
= get_memory_read_packet_size ();
7053 /* The packet buffer will be large enough for the payload;
7054 get_memory_packet_size ensures this. */
7056 /* Number if bytes that will fit. */
7057 todo
= min (len
, max_buf_size
/ 2);
7059 /* Construct "m"<memaddr>","<len>". */
7060 memaddr
= remote_address_masked (memaddr
);
7063 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7065 p
+= hexnumstr (p
, (ULONGEST
) todo
);
7068 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7069 if (rs
->buf
[0] == 'E'
7070 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7071 && rs
->buf
[3] == '\0')
7072 return TARGET_XFER_E_IO
;
7073 /* Reply describes memory byte by byte, each byte encoded as two hex
7076 i
= hex2bin (p
, myaddr
, todo
);
7077 /* Return what we have. Let higher layers handle partial reads. */
7083 /* Sends a packet with content determined by the printf format string
7084 FORMAT and the remaining arguments, then gets the reply. Returns
7085 whether the packet was a success, a failure, or unknown. */
7087 static enum packet_result
7088 remote_send_printf (const char *format
, ...)
7090 struct remote_state
*rs
= get_remote_state ();
7091 int max_size
= get_remote_packet_size ();
7094 va_start (ap
, format
);
7097 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7098 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7100 if (putpkt (rs
->buf
) < 0)
7101 error (_("Communication problem with target."));
7104 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7106 return packet_check_result (rs
->buf
);
7110 restore_remote_timeout (void *p
)
7112 int value
= *(int *)p
;
7114 remote_timeout
= value
;
7117 /* Flash writing can take quite some time. We'll set
7118 effectively infinite timeout for flash operations.
7119 In future, we'll need to decide on a better approach. */
7120 static const int remote_flash_timeout
= 1000;
7123 remote_flash_erase (struct target_ops
*ops
,
7124 ULONGEST address
, LONGEST length
)
7126 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7127 int saved_remote_timeout
= remote_timeout
;
7128 enum packet_result ret
;
7129 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7130 &saved_remote_timeout
);
7132 remote_timeout
= remote_flash_timeout
;
7134 ret
= remote_send_printf ("vFlashErase:%s,%s",
7135 phex (address
, addr_size
),
7139 case PACKET_UNKNOWN
:
7140 error (_("Remote target does not support flash erase"));
7142 error (_("Error erasing flash with vFlashErase packet"));
7147 do_cleanups (back_to
);
7151 remote_flash_write (struct target_ops
*ops
,
7152 ULONGEST address
, LONGEST length
,
7153 const gdb_byte
*data
)
7155 int saved_remote_timeout
= remote_timeout
;
7157 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7158 &saved_remote_timeout
);
7160 remote_timeout
= remote_flash_timeout
;
7161 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
7162 do_cleanups (back_to
);
7168 remote_flash_done (struct target_ops
*ops
)
7170 int saved_remote_timeout
= remote_timeout
;
7172 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7173 &saved_remote_timeout
);
7175 remote_timeout
= remote_flash_timeout
;
7176 ret
= remote_send_printf ("vFlashDone");
7177 do_cleanups (back_to
);
7181 case PACKET_UNKNOWN
:
7182 error (_("Remote target does not support vFlashDone"));
7184 error (_("Error finishing flash operation"));
7191 remote_files_info (struct target_ops
*ignore
)
7193 puts_filtered ("Debugging a target over a serial line.\n");
7196 /* Stuff for dealing with the packets which are part of this protocol.
7197 See comment at top of file for details. */
7199 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7200 error to higher layers. Called when a serial error is detected.
7201 The exception message is STRING, followed by a colon and a blank,
7202 the system error message for errno at function entry and final dot
7203 for output compatibility with throw_perror_with_name. */
7206 unpush_and_perror (const char *string
)
7208 int saved_errno
= errno
;
7210 remote_unpush_target ();
7211 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7212 safe_strerror (saved_errno
));
7215 /* Read a single character from the remote end. */
7218 readchar (int timeout
)
7221 struct remote_state
*rs
= get_remote_state ();
7223 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7228 switch ((enum serial_rc
) ch
)
7231 remote_unpush_target ();
7232 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7235 unpush_and_perror (_("Remote communication error. "
7236 "Target disconnected."));
7238 case SERIAL_TIMEOUT
:
7244 /* Wrapper for serial_write that closes the target and throws if
7248 remote_serial_write (const char *str
, int len
)
7250 struct remote_state
*rs
= get_remote_state ();
7252 if (serial_write (rs
->remote_desc
, str
, len
))
7254 unpush_and_perror (_("Remote communication error. "
7255 "Target disconnected."));
7259 /* Send the command in *BUF to the remote machine, and read the reply
7260 into *BUF. Report an error if we get an error reply. Resize
7261 *BUF using xrealloc if necessary to hold the result, and update
7265 remote_send (char **buf
,
7269 getpkt (buf
, sizeof_buf
, 0);
7271 if ((*buf
)[0] == 'E')
7272 error (_("Remote failure reply: %s"), *buf
);
7275 /* Return a pointer to an xmalloc'ed string representing an escaped
7276 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7277 etc. The caller is responsible for releasing the returned
7281 escape_buffer (const char *buf
, int n
)
7283 struct cleanup
*old_chain
;
7284 struct ui_file
*stb
;
7287 stb
= mem_fileopen ();
7288 old_chain
= make_cleanup_ui_file_delete (stb
);
7290 fputstrn_unfiltered (buf
, n
, 0, stb
);
7291 str
= ui_file_xstrdup (stb
, NULL
);
7292 do_cleanups (old_chain
);
7296 /* Display a null-terminated packet on stdout, for debugging, using C
7300 print_packet (char *buf
)
7302 puts_filtered ("\"");
7303 fputstr_filtered (buf
, '"', gdb_stdout
);
7304 puts_filtered ("\"");
7310 return putpkt_binary (buf
, strlen (buf
));
7313 /* Send a packet to the remote machine, with error checking. The data
7314 of the packet is in BUF. The string in BUF can be at most
7315 get_remote_packet_size () - 5 to account for the $, # and checksum,
7316 and for a possible /0 if we are debugging (remote_debug) and want
7317 to print the sent packet as a string. */
7320 putpkt_binary (char *buf
, int cnt
)
7322 struct remote_state
*rs
= get_remote_state ();
7324 unsigned char csum
= 0;
7325 char *buf2
= alloca (cnt
+ 6);
7332 /* Catch cases like trying to read memory or listing threads while
7333 we're waiting for a stop reply. The remote server wouldn't be
7334 ready to handle this request, so we'd hang and timeout. We don't
7335 have to worry about this in synchronous mode, because in that
7336 case it's not possible to issue a command while the target is
7337 running. This is not a problem in non-stop mode, because in that
7338 case, the stub is always ready to process serial input. */
7339 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
7340 error (_("Cannot execute this command while the target is running."));
7342 /* We're sending out a new packet. Make sure we don't look at a
7343 stale cached response. */
7344 rs
->cached_wait_status
= 0;
7346 /* Copy the packet into buffer BUF2, encapsulating it
7347 and giving it a checksum. */
7352 for (i
= 0; i
< cnt
; i
++)
7358 *p
++ = tohex ((csum
>> 4) & 0xf);
7359 *p
++ = tohex (csum
& 0xf);
7361 /* Send it over and over until we get a positive ack. */
7365 int started_error_output
= 0;
7369 struct cleanup
*old_chain
;
7373 str
= escape_buffer (buf2
, p
- buf2
);
7374 old_chain
= make_cleanup (xfree
, str
);
7375 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7376 gdb_flush (gdb_stdlog
);
7377 do_cleanups (old_chain
);
7379 remote_serial_write (buf2
, p
- buf2
);
7381 /* If this is a no acks version of the remote protocol, send the
7382 packet and move on. */
7386 /* Read until either a timeout occurs (-2) or '+' is read.
7387 Handle any notification that arrives in the mean time. */
7390 ch
= readchar (remote_timeout
);
7398 case SERIAL_TIMEOUT
:
7401 if (started_error_output
)
7403 putchar_unfiltered ('\n');
7404 started_error_output
= 0;
7413 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7417 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7419 case SERIAL_TIMEOUT
:
7423 break; /* Retransmit buffer. */
7427 fprintf_unfiltered (gdb_stdlog
,
7428 "Packet instead of Ack, ignoring it\n");
7429 /* It's probably an old response sent because an ACK
7430 was lost. Gobble up the packet and ack it so it
7431 doesn't get retransmitted when we resend this
7434 remote_serial_write ("+", 1);
7435 continue; /* Now, go look for +. */
7442 /* If we got a notification, handle it, and go back to looking
7444 /* We've found the start of a notification. Now
7445 collect the data. */
7446 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7451 struct cleanup
*old_chain
;
7454 str
= escape_buffer (rs
->buf
, val
);
7455 old_chain
= make_cleanup (xfree
, str
);
7456 fprintf_unfiltered (gdb_stdlog
,
7457 " Notification received: %s\n",
7459 do_cleanups (old_chain
);
7461 handle_notification (rs
->notif_state
, rs
->buf
);
7462 /* We're in sync now, rewait for the ack. */
7469 if (!started_error_output
)
7471 started_error_output
= 1;
7472 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7474 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7475 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7484 if (!started_error_output
)
7486 started_error_output
= 1;
7487 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7489 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7493 break; /* Here to retransmit. */
7497 /* This is wrong. If doing a long backtrace, the user should be
7498 able to get out next time we call QUIT, without anything as
7499 violent as interrupt_query. If we want to provide a way out of
7500 here without getting to the next QUIT, it should be based on
7501 hitting ^C twice as in remote_wait. */
7512 /* Come here after finding the start of a frame when we expected an
7513 ack. Do our best to discard the rest of this packet. */
7522 c
= readchar (remote_timeout
);
7525 case SERIAL_TIMEOUT
:
7526 /* Nothing we can do. */
7529 /* Discard the two bytes of checksum and stop. */
7530 c
= readchar (remote_timeout
);
7532 c
= readchar (remote_timeout
);
7535 case '*': /* Run length encoding. */
7536 /* Discard the repeat count. */
7537 c
= readchar (remote_timeout
);
7542 /* A regular character. */
7548 /* Come here after finding the start of the frame. Collect the rest
7549 into *BUF, verifying the checksum, length, and handling run-length
7550 compression. NUL terminate the buffer. If there is not enough room,
7551 expand *BUF using xrealloc.
7553 Returns -1 on error, number of characters in buffer (ignoring the
7554 trailing NULL) on success. (could be extended to return one of the
7555 SERIAL status indications). */
7558 read_frame (char **buf_p
,
7565 struct remote_state
*rs
= get_remote_state ();
7572 c
= readchar (remote_timeout
);
7575 case SERIAL_TIMEOUT
:
7577 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7581 fputs_filtered ("Saw new packet start in middle of old one\n",
7583 return -1; /* Start a new packet, count retries. */
7586 unsigned char pktcsum
;
7592 check_0
= readchar (remote_timeout
);
7594 check_1
= readchar (remote_timeout
);
7596 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7599 fputs_filtered ("Timeout in checksum, retrying\n",
7603 else if (check_0
< 0 || check_1
< 0)
7606 fputs_filtered ("Communication error in checksum\n",
7611 /* Don't recompute the checksum; with no ack packets we
7612 don't have any way to indicate a packet retransmission
7617 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7618 if (csum
== pktcsum
)
7623 struct cleanup
*old_chain
;
7626 str
= escape_buffer (buf
, bc
);
7627 old_chain
= make_cleanup (xfree
, str
);
7628 fprintf_unfiltered (gdb_stdlog
,
7629 "Bad checksum, sentsum=0x%x, "
7630 "csum=0x%x, buf=%s\n",
7631 pktcsum
, csum
, str
);
7632 do_cleanups (old_chain
);
7634 /* Number of characters in buffer ignoring trailing
7638 case '*': /* Run length encoding. */
7643 c
= readchar (remote_timeout
);
7645 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7647 /* The character before ``*'' is repeated. */
7649 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7651 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7653 /* Make some more room in the buffer. */
7654 *sizeof_buf
+= repeat
;
7655 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7659 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7665 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7669 if (bc
>= *sizeof_buf
- 1)
7671 /* Make some more room in the buffer. */
7673 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7684 /* Read a packet from the remote machine, with error checking, and
7685 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7686 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7687 rather than timing out; this is used (in synchronous mode) to wait
7688 for a target that is is executing user code to stop. */
7689 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7690 don't have to change all the calls to getpkt to deal with the
7691 return value, because at the moment I don't know what the right
7692 thing to do it for those. */
7700 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7704 /* Read a packet from the remote machine, with error checking, and
7705 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7706 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7707 rather than timing out; this is used (in synchronous mode) to wait
7708 for a target that is is executing user code to stop. If FOREVER ==
7709 0, this function is allowed to time out gracefully and return an
7710 indication of this to the caller. Otherwise return the number of
7711 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7712 enough reason to return to the caller. *IS_NOTIF is an output
7713 boolean that indicates whether *BUF holds a notification or not
7714 (a regular packet). */
7717 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7718 int expecting_notif
, int *is_notif
)
7720 struct remote_state
*rs
= get_remote_state ();
7726 /* We're reading a new response. Make sure we don't look at a
7727 previously cached response. */
7728 rs
->cached_wait_status
= 0;
7730 strcpy (*buf
, "timeout");
7733 timeout
= watchdog
> 0 ? watchdog
: -1;
7734 else if (expecting_notif
)
7735 timeout
= 0; /* There should already be a char in the buffer. If
7738 timeout
= remote_timeout
;
7742 /* Process any number of notifications, and then return when
7746 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
7748 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7750 /* This can loop forever if the remote side sends us
7751 characters continuously, but if it pauses, we'll get
7752 SERIAL_TIMEOUT from readchar because of timeout. Then
7753 we'll count that as a retry.
7755 Note that even when forever is set, we will only wait
7756 forever prior to the start of a packet. After that, we
7757 expect characters to arrive at a brisk pace. They should
7758 show up within remote_timeout intervals. */
7760 c
= readchar (timeout
);
7761 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7763 if (c
== SERIAL_TIMEOUT
)
7765 if (expecting_notif
)
7766 return -1; /* Don't complain, it's normal to not get
7767 anything in this case. */
7769 if (forever
) /* Watchdog went off? Kill the target. */
7772 remote_unpush_target ();
7773 throw_error (TARGET_CLOSE_ERROR
,
7774 _("Watchdog timeout has expired. "
7775 "Target detached."));
7778 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7782 /* We've found the start of a packet or notification.
7783 Now collect the data. */
7784 val
= read_frame (buf
, sizeof_buf
);
7789 remote_serial_write ("-", 1);
7792 if (tries
> MAX_TRIES
)
7794 /* We have tried hard enough, and just can't receive the
7795 packet/notification. Give up. */
7796 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7798 /* Skip the ack char if we're in no-ack mode. */
7799 if (!rs
->noack_mode
)
7800 remote_serial_write ("+", 1);
7804 /* If we got an ordinary packet, return that to our caller. */
7809 struct cleanup
*old_chain
;
7812 str
= escape_buffer (*buf
, val
);
7813 old_chain
= make_cleanup (xfree
, str
);
7814 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7815 do_cleanups (old_chain
);
7818 /* Skip the ack char if we're in no-ack mode. */
7819 if (!rs
->noack_mode
)
7820 remote_serial_write ("+", 1);
7821 if (is_notif
!= NULL
)
7826 /* If we got a notification, handle it, and go back to looking
7830 gdb_assert (c
== '%');
7834 struct cleanup
*old_chain
;
7837 str
= escape_buffer (*buf
, val
);
7838 old_chain
= make_cleanup (xfree
, str
);
7839 fprintf_unfiltered (gdb_stdlog
,
7840 " Notification received: %s\n",
7842 do_cleanups (old_chain
);
7844 if (is_notif
!= NULL
)
7847 handle_notification (rs
->notif_state
, *buf
);
7849 /* Notifications require no acknowledgement. */
7851 if (expecting_notif
)
7858 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7860 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7864 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7867 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7873 remote_kill (struct target_ops
*ops
)
7875 struct gdb_exception ex
;
7877 /* Catch errors so the user can quit from gdb even when we
7878 aren't on speaking terms with the remote system. */
7879 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
7885 if (ex
.error
== TARGET_CLOSE_ERROR
)
7887 /* If we got an (EOF) error that caused the target
7888 to go away, then we're done, that's what we wanted.
7889 "k" is susceptible to cause a premature EOF, given
7890 that the remote server isn't actually required to
7891 reply to "k", and it can happen that it doesn't
7892 even get to reply ACK to the "k". */
7896 /* Otherwise, something went wrong. We didn't actually kill
7897 the target. Just propagate the exception, and let the
7898 user or higher layers decide what to do. */
7899 throw_exception (ex
);
7902 /* We've killed the remote end, we get to mourn it. Since this is
7903 target remote, single-process, mourning the inferior also
7904 unpushes remote_ops. */
7905 target_mourn_inferior ();
7909 remote_vkill (int pid
, struct remote_state
*rs
)
7911 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7914 /* Tell the remote target to detach. */
7915 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7917 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7919 if (packet_ok (rs
->buf
,
7920 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7922 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7929 extended_remote_kill (struct target_ops
*ops
)
7932 int pid
= ptid_get_pid (inferior_ptid
);
7933 struct remote_state
*rs
= get_remote_state ();
7935 res
= remote_vkill (pid
, rs
);
7936 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7938 /* Don't try 'k' on a multi-process aware stub -- it has no way
7939 to specify the pid. */
7943 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7944 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7947 /* Don't wait for it to die. I'm not really sure it matters whether
7948 we do or not. For the existing stubs, kill is a noop. */
7954 error (_("Can't kill process"));
7956 target_mourn_inferior ();
7960 remote_mourn (struct target_ops
*ops
)
7962 remote_mourn_1 (ops
);
7965 /* Worker function for remote_mourn. */
7967 remote_mourn_1 (struct target_ops
*target
)
7969 unpush_target (target
);
7971 /* remote_close takes care of doing most of the clean up. */
7972 generic_mourn_inferior ();
7976 extended_remote_mourn_1 (struct target_ops
*target
)
7978 struct remote_state
*rs
= get_remote_state ();
7980 /* In case we got here due to an error, but we're going to stay
7982 rs
->waiting_for_stop_reply
= 0;
7984 /* If the current general thread belonged to the process we just
7985 detached from or has exited, the remote side current general
7986 thread becomes undefined. Considering a case like this:
7988 - We just got here due to a detach.
7989 - The process that we're detaching from happens to immediately
7990 report a global breakpoint being hit in non-stop mode, in the
7991 same thread we had selected before.
7992 - GDB attaches to this process again.
7993 - This event happens to be the next event we handle.
7995 GDB would consider that the current general thread didn't need to
7996 be set on the stub side (with Hg), since for all it knew,
7997 GENERAL_THREAD hadn't changed.
7999 Notice that although in all-stop mode, the remote server always
8000 sets the current thread to the thread reporting the stop event,
8001 that doesn't happen in non-stop mode; in non-stop, the stub *must
8002 not* change the current thread when reporting a breakpoint hit,
8003 due to the decoupling of event reporting and event handling.
8005 To keep things simple, we always invalidate our notion of the
8007 record_currthread (rs
, minus_one_ptid
);
8009 /* Unlike "target remote", we do not want to unpush the target; then
8010 the next time the user says "run", we won't be connected. */
8012 /* Call common code to mark the inferior as not running. */
8013 generic_mourn_inferior ();
8015 if (!have_inferiors ())
8017 if (!remote_multi_process_p (rs
))
8019 /* Check whether the target is running now - some remote stubs
8020 automatically restart after kill. */
8022 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8024 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
8026 /* Assume that the target has been restarted. Set
8027 inferior_ptid so that bits of core GDB realizes
8028 there's something here, e.g., so that the user can
8029 say "kill" again. */
8030 inferior_ptid
= magic_null_ptid
;
8037 extended_remote_mourn (struct target_ops
*ops
)
8039 extended_remote_mourn_1 (ops
);
8043 extended_remote_supports_disable_randomization (void)
8045 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
8050 extended_remote_disable_randomization (int val
)
8052 struct remote_state
*rs
= get_remote_state ();
8055 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
8058 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
8060 error (_("Target does not support QDisableRandomization."));
8061 if (strcmp (reply
, "OK") != 0)
8062 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
8066 extended_remote_run (char *args
)
8068 struct remote_state
*rs
= get_remote_state ();
8071 /* If the user has disabled vRun support, or we have detected that
8072 support is not available, do not try it. */
8073 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
8076 strcpy (rs
->buf
, "vRun;");
8077 len
= strlen (rs
->buf
);
8079 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
8080 error (_("Remote file name too long for run packet"));
8081 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
8083 gdb_assert (args
!= NULL
);
8086 struct cleanup
*back_to
;
8090 argv
= gdb_buildargv (args
);
8091 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
8092 for (i
= 0; argv
[i
] != NULL
; i
++)
8094 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8095 error (_("Argument list too long for run packet"));
8096 rs
->buf
[len
++] = ';';
8097 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
8099 do_cleanups (back_to
);
8102 rs
->buf
[len
++] = '\0';
8105 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8107 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
8109 /* We have a wait response. All is well. */
8112 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
8113 /* It wasn't disabled before, but it is now. */
8117 if (remote_exec_file
[0] == '\0')
8118 error (_("Running the default executable on the remote target failed; "
8119 "try \"set remote exec-file\"?"));
8121 error (_("Running \"%s\" on the remote target failed"),
8126 /* In the extended protocol we want to be able to do things like
8127 "run" and have them basically work as expected. So we need
8128 a special create_inferior function. We support changing the
8129 executable file and the command line arguments, but not the
8133 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
8134 char **env
, int from_tty
)
8138 struct remote_state
*rs
= get_remote_state ();
8140 /* If running asynchronously, register the target file descriptor
8141 with the event loop. */
8142 if (target_can_async_p ())
8143 target_async (inferior_event_handler
, 0);
8145 /* Disable address space randomization if requested (and supported). */
8146 if (extended_remote_supports_disable_randomization ())
8147 extended_remote_disable_randomization (disable_randomization
);
8149 /* Now restart the remote server. */
8150 run_worked
= extended_remote_run (args
) != -1;
8153 /* vRun was not supported. Fail if we need it to do what the
8155 if (remote_exec_file
[0])
8156 error (_("Remote target does not support \"set remote exec-file\""));
8158 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8160 /* Fall back to "R". */
8161 extended_remote_restart ();
8164 if (!have_inferiors ())
8166 /* Clean up from the last time we ran, before we mark the target
8167 running again. This will mark breakpoints uninserted, and
8168 get_offsets may insert breakpoints. */
8169 init_thread_list ();
8170 init_wait_for_inferior ();
8173 /* vRun's success return is a stop reply. */
8174 stop_reply
= run_worked
? rs
->buf
: NULL
;
8175 add_current_inferior_and_thread (stop_reply
);
8177 /* Get updated offsets, if the stub uses qOffsets. */
8182 extended_remote_create_inferior (struct target_ops
*ops
,
8183 char *exec_file
, char *args
,
8184 char **env
, int from_tty
)
8186 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
8190 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8191 the list of conditions (in agent expression bytecode format), if any, the
8192 target needs to evaluate. The output is placed into the packet buffer
8193 started from BUF and ended at BUF_END. */
8196 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8197 struct bp_target_info
*bp_tgt
, char *buf
,
8200 struct agent_expr
*aexpr
= NULL
;
8203 char *buf_start
= buf
;
8205 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8208 buf
+= strlen (buf
);
8209 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8212 /* Send conditions to the target and free the vector. */
8214 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8217 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8218 buf
+= strlen (buf
);
8219 for (i
= 0; i
< aexpr
->len
; ++i
)
8220 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8227 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8228 struct bp_target_info
*bp_tgt
, char *buf
)
8230 struct agent_expr
*aexpr
= NULL
;
8233 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8236 buf
+= strlen (buf
);
8238 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8239 buf
+= strlen (buf
);
8241 /* Concatenate all the agent expressions that are commands into the
8244 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8247 sprintf (buf
, "X%x,", aexpr
->len
);
8248 buf
+= strlen (buf
);
8249 for (i
= 0; i
< aexpr
->len
; ++i
)
8250 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8255 /* Insert a breakpoint. On targets that have software breakpoint
8256 support, we ask the remote target to do the work; on targets
8257 which don't, we insert a traditional memory breakpoint. */
8260 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
8261 struct bp_target_info
*bp_tgt
)
8263 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8264 If it succeeds, then set the support to PACKET_ENABLE. If it
8265 fails, and the user has explicitly requested the Z support then
8266 report an error, otherwise, mark it disabled and go on. */
8268 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8270 CORE_ADDR addr
= bp_tgt
->placed_address
;
8271 struct remote_state
*rs
;
8274 struct condition_list
*cond
= NULL
;
8276 /* Make sure the remote is pointing at the right process, if
8278 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8279 set_general_process ();
8281 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8283 rs
= get_remote_state ();
8285 endbuf
= rs
->buf
+ get_remote_packet_size ();
8290 addr
= (ULONGEST
) remote_address_masked (addr
);
8291 p
+= hexnumstr (p
, addr
);
8292 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8294 if (remote_supports_cond_breakpoints ())
8295 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8297 if (remote_can_run_breakpoint_commands ())
8298 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8301 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8303 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8308 bp_tgt
->placed_address
= addr
;
8309 bp_tgt
->placed_size
= bpsize
;
8311 case PACKET_UNKNOWN
:
8316 /* If this breakpoint has target-side commands but this stub doesn't
8317 support Z0 packets, throw error. */
8318 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8319 throw_error (NOT_SUPPORTED_ERROR
, _("\
8320 Target doesn't support breakpoints that have target side commands."));
8322 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
8326 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
8327 struct bp_target_info
*bp_tgt
)
8329 CORE_ADDR addr
= bp_tgt
->placed_address
;
8330 struct remote_state
*rs
= get_remote_state ();
8332 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8335 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8337 /* Make sure the remote is pointing at the right process, if
8339 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8340 set_general_process ();
8346 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8347 p
+= hexnumstr (p
, addr
);
8348 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8351 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8353 return (rs
->buf
[0] == 'E');
8356 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
8360 watchpoint_to_Z_packet (int type
)
8365 return Z_PACKET_WRITE_WP
;
8368 return Z_PACKET_READ_WP
;
8371 return Z_PACKET_ACCESS_WP
;
8374 internal_error (__FILE__
, __LINE__
,
8375 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8380 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
8381 struct expression
*cond
)
8383 struct remote_state
*rs
= get_remote_state ();
8384 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8386 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8388 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8391 /* Make sure the remote is pointing at the right process, if
8393 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8394 set_general_process ();
8396 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8397 p
= strchr (rs
->buf
, '\0');
8398 addr
= remote_address_masked (addr
);
8399 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8400 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8403 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8405 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8409 case PACKET_UNKNOWN
:
8414 internal_error (__FILE__
, __LINE__
,
8415 _("remote_insert_watchpoint: reached end of function"));
8419 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8420 CORE_ADDR start
, int length
)
8422 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8424 return diff
< length
;
8429 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
8430 struct expression
*cond
)
8432 struct remote_state
*rs
= get_remote_state ();
8433 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8435 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8437 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8440 /* Make sure the remote is pointing at the right process, if
8442 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8443 set_general_process ();
8445 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8446 p
= strchr (rs
->buf
, '\0');
8447 addr
= remote_address_masked (addr
);
8448 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8449 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8451 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8453 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8456 case PACKET_UNKNOWN
:
8461 internal_error (__FILE__
, __LINE__
,
8462 _("remote_remove_watchpoint: reached end of function"));
8466 int remote_hw_watchpoint_limit
= -1;
8467 int remote_hw_watchpoint_length_limit
= -1;
8468 int remote_hw_breakpoint_limit
= -1;
8471 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
8473 if (remote_hw_watchpoint_length_limit
== 0)
8475 else if (remote_hw_watchpoint_length_limit
< 0)
8477 else if (len
<= remote_hw_watchpoint_length_limit
)
8484 remote_check_watch_resources (int type
, int cnt
, int ot
)
8486 if (type
== bp_hardware_breakpoint
)
8488 if (remote_hw_breakpoint_limit
== 0)
8490 else if (remote_hw_breakpoint_limit
< 0)
8492 else if (cnt
<= remote_hw_breakpoint_limit
)
8497 if (remote_hw_watchpoint_limit
== 0)
8499 else if (remote_hw_watchpoint_limit
< 0)
8503 else if (cnt
<= remote_hw_watchpoint_limit
)
8510 remote_stopped_by_watchpoint (void)
8512 struct remote_state
*rs
= get_remote_state ();
8514 return rs
->remote_stopped_by_watchpoint_p
;
8518 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8520 struct remote_state
*rs
= get_remote_state ();
8523 if (remote_stopped_by_watchpoint ())
8525 *addr_p
= rs
->remote_watch_data_address
;
8534 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
8535 struct bp_target_info
*bp_tgt
)
8538 struct remote_state
*rs
;
8542 /* The length field should be set to the size of a breakpoint
8543 instruction, even though we aren't inserting one ourselves. */
8545 gdbarch_remote_breakpoint_from_pc
8546 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
8548 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8551 /* Make sure the remote is pointing at the right process, if
8553 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8554 set_general_process ();
8556 rs
= get_remote_state ();
8558 endbuf
= rs
->buf
+ get_remote_packet_size ();
8564 addr
= remote_address_masked (bp_tgt
->placed_address
);
8565 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8566 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8568 if (remote_supports_cond_breakpoints ())
8569 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8571 if (remote_can_run_breakpoint_commands ())
8572 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8575 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8577 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8580 if (rs
->buf
[1] == '.')
8582 message
= strchr (rs
->buf
+ 2, '.');
8584 error (_("Remote failure reply: %s"), message
+ 1);
8587 case PACKET_UNKNOWN
:
8592 internal_error (__FILE__
, __LINE__
,
8593 _("remote_insert_hw_breakpoint: reached end of function"));
8598 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
8599 struct bp_target_info
*bp_tgt
)
8602 struct remote_state
*rs
= get_remote_state ();
8604 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8606 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8609 /* Make sure the remote is pointing at the right process, if
8611 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8612 set_general_process ();
8618 addr
= remote_address_masked (bp_tgt
->placed_address
);
8619 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8620 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8623 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8625 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8628 case PACKET_UNKNOWN
:
8633 internal_error (__FILE__
, __LINE__
,
8634 _("remote_remove_hw_breakpoint: reached end of function"));
8637 /* Verify memory using the "qCRC:" request. */
8640 remote_verify_memory (struct target_ops
*ops
,
8641 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8643 struct remote_state
*rs
= get_remote_state ();
8644 unsigned long host_crc
, target_crc
;
8647 /* Make sure the remote is pointing at the right process. */
8648 set_general_process ();
8650 /* FIXME: assumes lma can fit into long. */
8651 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8652 (long) lma
, (long) size
);
8655 /* Be clever; compute the host_crc before waiting for target
8657 host_crc
= xcrc32 (data
, size
, 0xffffffff);
8659 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8660 if (rs
->buf
[0] == 'E')
8663 if (rs
->buf
[0] != 'C')
8664 error (_("remote target does not support this operation"));
8666 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8667 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8669 return (host_crc
== target_crc
);
8672 /* compare-sections command
8674 With no arguments, compares each loadable section in the exec bfd
8675 with the same memory range on the target, and reports mismatches.
8676 Useful for verifying the image on the target against the exec file. */
8679 compare_sections_command (char *args
, int from_tty
)
8682 struct cleanup
*old_chain
;
8684 const char *sectname
;
8692 error (_("command cannot be used without an exec file"));
8694 /* Make sure the remote is pointing at the right process. */
8695 set_general_process ();
8697 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8699 if (!(s
->flags
& SEC_LOAD
))
8700 continue; /* Skip non-loadable section. */
8702 size
= bfd_get_section_size (s
);
8704 continue; /* Skip zero-length section. */
8706 sectname
= bfd_get_section_name (exec_bfd
, s
);
8707 if (args
&& strcmp (args
, sectname
) != 0)
8708 continue; /* Not the section selected by user. */
8710 matched
= 1; /* Do this section. */
8713 sectdata
= xmalloc (size
);
8714 old_chain
= make_cleanup (xfree
, sectdata
);
8715 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8717 res
= target_verify_memory (sectdata
, lma
, size
);
8720 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8721 paddress (target_gdbarch (), lma
),
8722 paddress (target_gdbarch (), lma
+ size
));
8724 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8725 paddress (target_gdbarch (), lma
),
8726 paddress (target_gdbarch (), lma
+ size
));
8728 printf_filtered ("matched.\n");
8731 printf_filtered ("MIS-MATCHED!\n");
8735 do_cleanups (old_chain
);
8738 warning (_("One or more sections of the remote executable does not match\n\
8739 the loaded file\n"));
8740 if (args
&& !matched
)
8741 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8744 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8745 into remote target. The number of bytes written to the remote
8746 target is returned, or -1 for error. */
8749 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8750 const char *annex
, const gdb_byte
*writebuf
,
8751 ULONGEST offset
, LONGEST len
,
8752 struct packet_config
*packet
)
8756 struct remote_state
*rs
= get_remote_state ();
8757 int max_size
= get_memory_write_packet_size ();
8759 if (packet
->support
== PACKET_DISABLE
)
8762 /* Insert header. */
8763 i
= snprintf (rs
->buf
, max_size
,
8764 "qXfer:%s:write:%s:%s:",
8765 object_name
, annex
? annex
: "",
8766 phex_nz (offset
, sizeof offset
));
8767 max_size
-= (i
+ 1);
8769 /* Escape as much data as fits into rs->buf. */
8770 buf_len
= remote_escape_output
8771 (writebuf
, len
, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
8773 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8774 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8775 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8778 unpack_varlen_hex (rs
->buf
, &n
);
8782 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8783 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8784 number of bytes read is returned, or 0 for EOF, or -1 for error.
8785 The number of bytes read may be less than LEN without indicating an
8786 EOF. PACKET is checked and updated to indicate whether the remote
8787 target supports this object. */
8790 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8792 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8793 struct packet_config
*packet
)
8795 struct remote_state
*rs
= get_remote_state ();
8796 LONGEST i
, n
, packet_len
;
8798 if (packet
->support
== PACKET_DISABLE
)
8801 /* Check whether we've cached an end-of-object packet that matches
8803 if (rs
->finished_object
)
8805 if (strcmp (object_name
, rs
->finished_object
) == 0
8806 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
8807 && offset
== rs
->finished_offset
)
8810 /* Otherwise, we're now reading something different. Discard
8812 xfree (rs
->finished_object
);
8813 xfree (rs
->finished_annex
);
8814 rs
->finished_object
= NULL
;
8815 rs
->finished_annex
= NULL
;
8818 /* Request only enough to fit in a single packet. The actual data
8819 may not, since we don't know how much of it will need to be escaped;
8820 the target is free to respond with slightly less data. We subtract
8821 five to account for the response type and the protocol frame. */
8822 n
= min (get_remote_packet_size () - 5, len
);
8823 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8824 object_name
, annex
? annex
: "",
8825 phex_nz (offset
, sizeof offset
),
8826 phex_nz (n
, sizeof n
));
8827 i
= putpkt (rs
->buf
);
8832 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8833 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8836 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8837 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8839 /* 'm' means there is (or at least might be) more data after this
8840 batch. That does not make sense unless there's at least one byte
8841 of data in this reply. */
8842 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8843 error (_("Remote qXfer reply contained no data."));
8845 /* Got some data. */
8846 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
8847 packet_len
- 1, readbuf
, n
);
8849 /* 'l' is an EOF marker, possibly including a final block of data,
8850 or possibly empty. If we have the final block of a non-empty
8851 object, record this fact to bypass a subsequent partial read. */
8852 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8854 rs
->finished_object
= xstrdup (object_name
);
8855 rs
->finished_annex
= xstrdup (annex
? annex
: "");
8856 rs
->finished_offset
= offset
+ i
;
8863 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8864 const char *annex
, gdb_byte
*readbuf
,
8865 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
)
8867 struct remote_state
*rs
;
8872 set_remote_traceframe ();
8873 set_general_thread (inferior_ptid
);
8875 rs
= get_remote_state ();
8877 /* Handle memory using the standard memory routines. */
8878 if (object
== TARGET_OBJECT_MEMORY
)
8882 /* If the remote target is connected but not running, we should
8883 pass this request down to a lower stratum (e.g. the executable
8885 if (!target_has_execution
)
8888 if (writebuf
!= NULL
)
8889 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8891 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8896 /* Handle SPU memory using qxfer packets. */
8897 if (object
== TARGET_OBJECT_SPU
)
8900 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8901 &remote_protocol_packets
8902 [PACKET_qXfer_spu_read
]);
8904 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8905 &remote_protocol_packets
8906 [PACKET_qXfer_spu_write
]);
8909 /* Handle extra signal info using qxfer packets. */
8910 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8913 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8914 &remote_protocol_packets
8915 [PACKET_qXfer_siginfo_read
]);
8917 return remote_write_qxfer (ops
, "siginfo", annex
,
8918 writebuf
, offset
, len
,
8919 &remote_protocol_packets
8920 [PACKET_qXfer_siginfo_write
]);
8923 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8926 return remote_read_qxfer (ops
, "statictrace", annex
,
8927 readbuf
, offset
, len
,
8928 &remote_protocol_packets
8929 [PACKET_qXfer_statictrace_read
]);
8934 /* Only handle flash writes. */
8935 if (writebuf
!= NULL
)
8941 case TARGET_OBJECT_FLASH
:
8942 return remote_flash_write (ops
, offset
, len
, writebuf
);
8949 /* Map pre-existing objects onto letters. DO NOT do this for new
8950 objects!!! Instead specify new query packets. */
8953 case TARGET_OBJECT_AVR
:
8957 case TARGET_OBJECT_AUXV
:
8958 gdb_assert (annex
== NULL
);
8959 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8960 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8962 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8963 return remote_read_qxfer
8964 (ops
, "features", annex
, readbuf
, offset
, len
,
8965 &remote_protocol_packets
[PACKET_qXfer_features
]);
8967 case TARGET_OBJECT_LIBRARIES
:
8968 return remote_read_qxfer
8969 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8970 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8972 case TARGET_OBJECT_LIBRARIES_SVR4
:
8973 return remote_read_qxfer
8974 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8975 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8977 case TARGET_OBJECT_MEMORY_MAP
:
8978 gdb_assert (annex
== NULL
);
8979 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8980 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8982 case TARGET_OBJECT_OSDATA
:
8983 /* Should only get here if we're connected. */
8984 gdb_assert (rs
->remote_desc
);
8985 return remote_read_qxfer
8986 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8987 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8989 case TARGET_OBJECT_THREADS
:
8990 gdb_assert (annex
== NULL
);
8991 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8992 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8994 case TARGET_OBJECT_TRACEFRAME_INFO
:
8995 gdb_assert (annex
== NULL
);
8996 return remote_read_qxfer
8997 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8998 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
9000 case TARGET_OBJECT_FDPIC
:
9001 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
9002 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
9004 case TARGET_OBJECT_OPENVMS_UIB
:
9005 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
9006 &remote_protocol_packets
[PACKET_qXfer_uib
]);
9008 case TARGET_OBJECT_BTRACE
:
9009 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
9010 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
9016 /* Note: a zero OFFSET and LEN can be used to query the minimum
9018 if (offset
== 0 && len
== 0)
9019 return (get_remote_packet_size ());
9020 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
9021 large enough let the caller deal with it. */
9022 if (len
< get_remote_packet_size ())
9024 len
= get_remote_packet_size ();
9026 /* Except for querying the minimum buffer size, target must be open. */
9027 if (!rs
->remote_desc
)
9028 error (_("remote query is only available after target open"));
9030 gdb_assert (annex
!= NULL
);
9031 gdb_assert (readbuf
!= NULL
);
9037 /* We used one buffer char for the remote protocol q command and
9038 another for the query type. As the remote protocol encapsulation
9039 uses 4 chars plus one extra in case we are debugging
9040 (remote_debug), we have PBUFZIZ - 7 left to pack the query
9043 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
9045 /* Bad caller may have sent forbidden characters. */
9046 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
9051 gdb_assert (annex
[i
] == '\0');
9053 i
= putpkt (rs
->buf
);
9057 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9058 strcpy ((char *) readbuf
, rs
->buf
);
9060 return strlen ((char *) readbuf
);
9064 remote_search_memory (struct target_ops
* ops
,
9065 CORE_ADDR start_addr
, ULONGEST search_space_len
,
9066 const gdb_byte
*pattern
, ULONGEST pattern_len
,
9067 CORE_ADDR
*found_addrp
)
9069 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
9070 struct remote_state
*rs
= get_remote_state ();
9071 int max_size
= get_memory_write_packet_size ();
9072 struct packet_config
*packet
=
9073 &remote_protocol_packets
[PACKET_qSearch_memory
];
9074 /* Number of packet bytes used to encode the pattern;
9075 this could be more than PATTERN_LEN due to escape characters. */
9076 int escaped_pattern_len
;
9077 /* Amount of pattern that was encodable in the packet. */
9078 int used_pattern_len
;
9081 ULONGEST found_addr
;
9083 /* Don't go to the target if we don't have to.
9084 This is done before checking packet->support to avoid the possibility that
9085 a success for this edge case means the facility works in general. */
9086 if (pattern_len
> search_space_len
)
9088 if (pattern_len
== 0)
9090 *found_addrp
= start_addr
;
9094 /* If we already know the packet isn't supported, fall back to the simple
9095 way of searching memory. */
9097 if (packet
->support
== PACKET_DISABLE
)
9099 /* Target doesn't provided special support, fall back and use the
9100 standard support (copy memory and do the search here). */
9101 return simple_search_memory (ops
, start_addr
, search_space_len
,
9102 pattern
, pattern_len
, found_addrp
);
9105 /* Make sure the remote is pointing at the right process. */
9106 set_general_process ();
9108 /* Insert header. */
9109 i
= snprintf (rs
->buf
, max_size
,
9110 "qSearch:memory:%s;%s;",
9111 phex_nz (start_addr
, addr_size
),
9112 phex_nz (search_space_len
, sizeof (search_space_len
)));
9113 max_size
-= (i
+ 1);
9115 /* Escape as much data as fits into rs->buf. */
9116 escaped_pattern_len
=
9117 remote_escape_output (pattern
, pattern_len
, (gdb_byte
*) rs
->buf
+ i
,
9118 &used_pattern_len
, max_size
);
9120 /* Bail if the pattern is too large. */
9121 if (used_pattern_len
!= pattern_len
)
9122 error (_("Pattern is too large to transmit to remote target."));
9124 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9125 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9126 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9128 /* The request may not have worked because the command is not
9129 supported. If so, fall back to the simple way. */
9130 if (packet
->support
== PACKET_DISABLE
)
9132 return simple_search_memory (ops
, start_addr
, search_space_len
,
9133 pattern
, pattern_len
, found_addrp
);
9138 if (rs
->buf
[0] == '0')
9140 else if (rs
->buf
[0] == '1')
9143 if (rs
->buf
[1] != ',')
9144 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9145 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9146 *found_addrp
= found_addr
;
9149 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9155 remote_rcmd (char *command
,
9156 struct ui_file
*outbuf
)
9158 struct remote_state
*rs
= get_remote_state ();
9161 if (!rs
->remote_desc
)
9162 error (_("remote rcmd is only available after target open"));
9164 /* Send a NULL command across as an empty command. */
9165 if (command
== NULL
)
9168 /* The query prefix. */
9169 strcpy (rs
->buf
, "qRcmd,");
9170 p
= strchr (rs
->buf
, '\0');
9172 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9173 > get_remote_packet_size ())
9174 error (_("\"monitor\" command ``%s'' is too long."), command
);
9176 /* Encode the actual command. */
9177 bin2hex ((gdb_byte
*) command
, p
, 0);
9179 if (putpkt (rs
->buf
) < 0)
9180 error (_("Communication problem with target."));
9182 /* get/display the response */
9187 /* XXX - see also remote_get_noisy_reply(). */
9188 QUIT
; /* Allow user to bail out with ^C. */
9190 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9192 /* Timeout. Continue to (try to) read responses.
9193 This is better than stopping with an error, assuming the stub
9194 is still executing the (long) monitor command.
9195 If needed, the user can interrupt gdb using C-c, obtaining
9196 an effect similar to stop on timeout. */
9201 error (_("Target does not support this command."));
9202 if (buf
[0] == 'O' && buf
[1] != 'K')
9204 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9207 if (strcmp (buf
, "OK") == 0)
9209 if (strlen (buf
) == 3 && buf
[0] == 'E'
9210 && isdigit (buf
[1]) && isdigit (buf
[2]))
9212 error (_("Protocol error with Rcmd"));
9214 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9216 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9218 fputc_unfiltered (c
, outbuf
);
9224 static VEC(mem_region_s
) *
9225 remote_memory_map (struct target_ops
*ops
)
9227 VEC(mem_region_s
) *result
= NULL
;
9228 char *text
= target_read_stralloc (¤t_target
,
9229 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9233 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9235 result
= parse_memory_map (text
);
9236 do_cleanups (back_to
);
9243 packet_command (char *args
, int from_tty
)
9245 struct remote_state
*rs
= get_remote_state ();
9247 if (!rs
->remote_desc
)
9248 error (_("command can only be used with remote target"));
9251 error (_("remote-packet command requires packet text as argument"));
9253 puts_filtered ("sending: ");
9254 print_packet (args
);
9255 puts_filtered ("\n");
9258 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9259 puts_filtered ("received: ");
9260 print_packet (rs
->buf
);
9261 puts_filtered ("\n");
9265 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9267 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9269 static void threadset_test_cmd (char *cmd
, int tty
);
9271 static void threadalive_test (char *cmd
, int tty
);
9273 static void threadlist_test_cmd (char *cmd
, int tty
);
9275 int get_and_display_threadinfo (threadref
*ref
);
9277 static void threadinfo_test_cmd (char *cmd
, int tty
);
9279 static int thread_display_step (threadref
*ref
, void *context
);
9281 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9283 static void init_remote_threadtests (void);
9285 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9288 threadset_test_cmd (char *cmd
, int tty
)
9290 int sample_thread
= SAMPLE_THREAD
;
9292 printf_filtered (_("Remote threadset test\n"));
9293 set_general_thread (sample_thread
);
9298 threadalive_test (char *cmd
, int tty
)
9300 int sample_thread
= SAMPLE_THREAD
;
9301 int pid
= ptid_get_pid (inferior_ptid
);
9302 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
9304 if (remote_thread_alive (ptid
))
9305 printf_filtered ("PASS: Thread alive test\n");
9307 printf_filtered ("FAIL: Thread alive test\n");
9310 void output_threadid (char *title
, threadref
*ref
);
9313 output_threadid (char *title
, threadref
*ref
)
9317 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9319 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9323 threadlist_test_cmd (char *cmd
, int tty
)
9326 threadref nextthread
;
9327 int done
, result_count
;
9328 threadref threadlist
[3];
9330 printf_filtered ("Remote Threadlist test\n");
9331 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9332 &result_count
, &threadlist
[0]))
9333 printf_filtered ("FAIL: threadlist test\n");
9336 threadref
*scan
= threadlist
;
9337 threadref
*limit
= scan
+ result_count
;
9339 while (scan
< limit
)
9340 output_threadid (" thread ", scan
++);
9345 display_thread_info (struct gdb_ext_thread_info
*info
)
9347 output_threadid ("Threadid: ", &info
->threadid
);
9348 printf_filtered ("Name: %s\n ", info
->shortname
);
9349 printf_filtered ("State: %s\n", info
->display
);
9350 printf_filtered ("other: %s\n\n", info
->more_display
);
9354 get_and_display_threadinfo (threadref
*ref
)
9358 struct gdb_ext_thread_info threadinfo
;
9360 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9361 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9362 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9363 display_thread_info (&threadinfo
);
9368 threadinfo_test_cmd (char *cmd
, int tty
)
9370 int athread
= SAMPLE_THREAD
;
9374 int_to_threadref (&thread
, athread
);
9375 printf_filtered ("Remote Threadinfo test\n");
9376 if (!get_and_display_threadinfo (&thread
))
9377 printf_filtered ("FAIL cannot get thread info\n");
9381 thread_display_step (threadref
*ref
, void *context
)
9383 /* output_threadid(" threadstep ",ref); *//* simple test */
9384 return get_and_display_threadinfo (ref
);
9388 threadlist_update_test_cmd (char *cmd
, int tty
)
9390 printf_filtered ("Remote Threadlist update test\n");
9391 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9395 init_remote_threadtests (void)
9397 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9398 _("Fetch and print the remote list of "
9399 "thread identifiers, one pkt only"));
9400 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9401 _("Fetch and display info about one thread"));
9402 add_com ("tset", class_obscure
, threadset_test_cmd
,
9403 _("Test setting to a different thread"));
9404 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9405 _("Iterate through updating all remote thread info"));
9406 add_com ("talive", class_obscure
, threadalive_test
,
9407 _(" Remote thread alive test "));
9412 /* Convert a thread ID to a string. Returns the string in a static
9416 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9418 static char buf
[64];
9419 struct remote_state
*rs
= get_remote_state ();
9421 if (ptid_equal (ptid
, null_ptid
))
9422 return normal_pid_to_str (ptid
);
9423 else if (ptid_is_pid (ptid
))
9425 /* Printing an inferior target id. */
9427 /* When multi-process extensions are off, there's no way in the
9428 remote protocol to know the remote process id, if there's any
9429 at all. There's one exception --- when we're connected with
9430 target extended-remote, and we manually attached to a process
9431 with "attach PID". We don't record anywhere a flag that
9432 allows us to distinguish that case from the case of
9433 connecting with extended-remote and the stub already being
9434 attached to a process, and reporting yes to qAttached, hence
9435 no smart special casing here. */
9436 if (!remote_multi_process_p (rs
))
9438 xsnprintf (buf
, sizeof buf
, "Remote target");
9442 return normal_pid_to_str (ptid
);
9446 if (ptid_equal (magic_null_ptid
, ptid
))
9447 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9448 else if (rs
->extended
&& remote_multi_process_p (rs
))
9449 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9450 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
9452 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9453 ptid_get_tid (ptid
));
9458 /* Get the address of the thread local variable in OBJFILE which is
9459 stored at OFFSET within the thread local storage for thread PTID. */
9462 remote_get_thread_local_address (struct target_ops
*ops
,
9463 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9465 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
9467 struct remote_state
*rs
= get_remote_state ();
9469 char *endp
= rs
->buf
+ get_remote_packet_size ();
9470 enum packet_result result
;
9472 strcpy (p
, "qGetTLSAddr:");
9474 p
= write_ptid (p
, endp
, ptid
);
9476 p
+= hexnumstr (p
, offset
);
9478 p
+= hexnumstr (p
, lm
);
9482 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9483 result
= packet_ok (rs
->buf
,
9484 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9485 if (result
== PACKET_OK
)
9489 unpack_varlen_hex (rs
->buf
, &result
);
9492 else if (result
== PACKET_UNKNOWN
)
9493 throw_error (TLS_GENERIC_ERROR
,
9494 _("Remote target doesn't support qGetTLSAddr packet"));
9496 throw_error (TLS_GENERIC_ERROR
,
9497 _("Remote target failed to process qGetTLSAddr request"));
9500 throw_error (TLS_GENERIC_ERROR
,
9501 _("TLS not supported or disabled on this target"));
9506 /* Provide thread local base, i.e. Thread Information Block address.
9507 Returns 1 if ptid is found and thread_local_base is non zero. */
9510 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
9512 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
9514 struct remote_state
*rs
= get_remote_state ();
9516 char *endp
= rs
->buf
+ get_remote_packet_size ();
9517 enum packet_result result
;
9519 strcpy (p
, "qGetTIBAddr:");
9521 p
= write_ptid (p
, endp
, ptid
);
9525 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9526 result
= packet_ok (rs
->buf
,
9527 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9528 if (result
== PACKET_OK
)
9532 unpack_varlen_hex (rs
->buf
, &result
);
9534 *addr
= (CORE_ADDR
) result
;
9537 else if (result
== PACKET_UNKNOWN
)
9538 error (_("Remote target doesn't support qGetTIBAddr packet"));
9540 error (_("Remote target failed to process qGetTIBAddr request"));
9543 error (_("qGetTIBAddr not supported or disabled on this target"));
9548 /* Support for inferring a target description based on the current
9549 architecture and the size of a 'g' packet. While the 'g' packet
9550 can have any size (since optional registers can be left off the
9551 end), some sizes are easily recognizable given knowledge of the
9552 approximate architecture. */
9554 struct remote_g_packet_guess
9557 const struct target_desc
*tdesc
;
9559 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9560 DEF_VEC_O(remote_g_packet_guess_s
);
9562 struct remote_g_packet_data
9564 VEC(remote_g_packet_guess_s
) *guesses
;
9567 static struct gdbarch_data
*remote_g_packet_data_handle
;
9570 remote_g_packet_data_init (struct obstack
*obstack
)
9572 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9576 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9577 const struct target_desc
*tdesc
)
9579 struct remote_g_packet_data
*data
9580 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9581 struct remote_g_packet_guess new_guess
, *guess
;
9584 gdb_assert (tdesc
!= NULL
);
9587 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9589 if (guess
->bytes
== bytes
)
9590 internal_error (__FILE__
, __LINE__
,
9591 _("Duplicate g packet description added for size %d"),
9594 new_guess
.bytes
= bytes
;
9595 new_guess
.tdesc
= tdesc
;
9596 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9599 /* Return 1 if remote_read_description would do anything on this target
9600 and architecture, 0 otherwise. */
9603 remote_read_description_p (struct target_ops
*target
)
9605 struct remote_g_packet_data
*data
9606 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9608 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9614 static const struct target_desc
*
9615 remote_read_description (struct target_ops
*target
)
9617 struct remote_g_packet_data
*data
9618 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9620 /* Do not try this during initial connection, when we do not know
9621 whether there is a running but stopped thread. */
9622 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9625 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9627 struct remote_g_packet_guess
*guess
;
9629 int bytes
= send_g_packet ();
9632 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9634 if (guess
->bytes
== bytes
)
9635 return guess
->tdesc
;
9637 /* We discard the g packet. A minor optimization would be to
9638 hold on to it, and fill the register cache once we have selected
9639 an architecture, but it's too tricky to do safely. */
9645 /* Remote file transfer support. This is host-initiated I/O, not
9646 target-initiated; for target-initiated, see remote-fileio.c. */
9648 /* If *LEFT is at least the length of STRING, copy STRING to
9649 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9650 decrease *LEFT. Otherwise raise an error. */
9653 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9655 int len
= strlen (string
);
9658 error (_("Packet too long for target."));
9660 memcpy (*buffer
, string
, len
);
9664 /* NUL-terminate the buffer as a convenience, if there is
9670 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9671 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9672 decrease *LEFT. Otherwise raise an error. */
9675 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9678 if (2 * len
> *left
)
9679 error (_("Packet too long for target."));
9681 bin2hex (bytes
, *buffer
, len
);
9685 /* NUL-terminate the buffer as a convenience, if there is
9691 /* If *LEFT is large enough, convert VALUE to hex and add it to
9692 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9693 decrease *LEFT. Otherwise raise an error. */
9696 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9698 int len
= hexnumlen (value
);
9701 error (_("Packet too long for target."));
9703 hexnumstr (*buffer
, value
);
9707 /* NUL-terminate the buffer as a convenience, if there is
9713 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9714 value, *REMOTE_ERRNO to the remote error number or zero if none
9715 was included, and *ATTACHMENT to point to the start of the annex
9716 if any. The length of the packet isn't needed here; there may
9717 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9719 Return 0 if the packet could be parsed, -1 if it could not. If
9720 -1 is returned, the other variables may not be initialized. */
9723 remote_hostio_parse_result (char *buffer
, int *retcode
,
9724 int *remote_errno
, char **attachment
)
9731 if (buffer
[0] != 'F')
9735 *retcode
= strtol (&buffer
[1], &p
, 16);
9736 if (errno
!= 0 || p
== &buffer
[1])
9739 /* Check for ",errno". */
9743 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9744 if (errno
!= 0 || p
+ 1 == p2
)
9749 /* Check for ";attachment". If there is no attachment, the
9750 packet should end here. */
9753 *attachment
= p
+ 1;
9756 else if (*p
== '\0')
9762 /* Send a prepared I/O packet to the target and read its response.
9763 The prepared packet is in the global RS->BUF before this function
9764 is called, and the answer is there when we return.
9766 COMMAND_BYTES is the length of the request to send, which may include
9767 binary data. WHICH_PACKET is the packet configuration to check
9768 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9769 is set to the error number and -1 is returned. Otherwise the value
9770 returned by the function is returned.
9772 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9773 attachment is expected; an error will be reported if there's a
9774 mismatch. If one is found, *ATTACHMENT will be set to point into
9775 the packet buffer and *ATTACHMENT_LEN will be set to the
9776 attachment's length. */
9779 remote_hostio_send_command (int command_bytes
, int which_packet
,
9780 int *remote_errno
, char **attachment
,
9781 int *attachment_len
)
9783 struct remote_state
*rs
= get_remote_state ();
9784 int ret
, bytes_read
;
9785 char *attachment_tmp
;
9787 if (!rs
->remote_desc
9788 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9790 *remote_errno
= FILEIO_ENOSYS
;
9794 putpkt_binary (rs
->buf
, command_bytes
);
9795 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9797 /* If it timed out, something is wrong. Don't try to parse the
9801 *remote_errno
= FILEIO_EINVAL
;
9805 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9808 *remote_errno
= FILEIO_EINVAL
;
9810 case PACKET_UNKNOWN
:
9811 *remote_errno
= FILEIO_ENOSYS
;
9817 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9820 *remote_errno
= FILEIO_EINVAL
;
9824 /* Make sure we saw an attachment if and only if we expected one. */
9825 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9826 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9828 *remote_errno
= FILEIO_EINVAL
;
9832 /* If an attachment was found, it must point into the packet buffer;
9833 work out how many bytes there were. */
9834 if (attachment_tmp
!= NULL
)
9836 *attachment
= attachment_tmp
;
9837 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9843 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9844 remote file descriptor, or -1 if an error occurs (and set
9848 remote_hostio_open (const char *filename
, int flags
, int mode
,
9851 struct remote_state
*rs
= get_remote_state ();
9853 int left
= get_remote_packet_size () - 1;
9855 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9857 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9859 remote_buffer_add_string (&p
, &left
, ",");
9861 remote_buffer_add_int (&p
, &left
, flags
);
9862 remote_buffer_add_string (&p
, &left
, ",");
9864 remote_buffer_add_int (&p
, &left
, mode
);
9866 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9867 remote_errno
, NULL
, NULL
);
9870 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9871 Return the number of bytes written, or -1 if an error occurs (and
9872 set *REMOTE_ERRNO). */
9875 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9876 ULONGEST offset
, int *remote_errno
)
9878 struct remote_state
*rs
= get_remote_state ();
9880 int left
= get_remote_packet_size ();
9883 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9885 remote_buffer_add_int (&p
, &left
, fd
);
9886 remote_buffer_add_string (&p
, &left
, ",");
9888 remote_buffer_add_int (&p
, &left
, offset
);
9889 remote_buffer_add_string (&p
, &left
, ",");
9891 p
+= remote_escape_output (write_buf
, len
, (gdb_byte
*) p
, &out_len
,
9892 get_remote_packet_size () - (p
- rs
->buf
));
9894 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9895 remote_errno
, NULL
, NULL
);
9898 /* Read up to LEN bytes FD on the remote target into READ_BUF
9899 Return the number of bytes read, or -1 if an error occurs (and
9900 set *REMOTE_ERRNO). */
9903 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9904 ULONGEST offset
, int *remote_errno
)
9906 struct remote_state
*rs
= get_remote_state ();
9909 int left
= get_remote_packet_size ();
9910 int ret
, attachment_len
;
9913 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9915 remote_buffer_add_int (&p
, &left
, fd
);
9916 remote_buffer_add_string (&p
, &left
, ",");
9918 remote_buffer_add_int (&p
, &left
, len
);
9919 remote_buffer_add_string (&p
, &left
, ",");
9921 remote_buffer_add_int (&p
, &left
, offset
);
9923 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9924 remote_errno
, &attachment
,
9930 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9932 if (read_len
!= ret
)
9933 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9938 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9939 (and set *REMOTE_ERRNO). */
9942 remote_hostio_close (int fd
, int *remote_errno
)
9944 struct remote_state
*rs
= get_remote_state ();
9946 int left
= get_remote_packet_size () - 1;
9948 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9950 remote_buffer_add_int (&p
, &left
, fd
);
9952 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9953 remote_errno
, NULL
, NULL
);
9956 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9957 occurs (and set *REMOTE_ERRNO). */
9960 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9962 struct remote_state
*rs
= get_remote_state ();
9964 int left
= get_remote_packet_size () - 1;
9966 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9968 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9971 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9972 remote_errno
, NULL
, NULL
);
9975 /* Read value of symbolic link FILENAME on the remote target. Return
9976 a null-terminated string allocated via xmalloc, or NULL if an error
9977 occurs (and set *REMOTE_ERRNO). */
9980 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9982 struct remote_state
*rs
= get_remote_state ();
9985 int left
= get_remote_packet_size ();
9986 int len
, attachment_len
;
9990 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9992 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9995 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9996 remote_errno
, &attachment
,
10002 ret
= xmalloc (len
+ 1);
10004 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10005 (gdb_byte
*) ret
, len
);
10006 if (read_len
!= len
)
10007 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
10014 remote_fileio_errno_to_host (int errnum
)
10020 case FILEIO_ENOENT
:
10028 case FILEIO_EACCES
:
10030 case FILEIO_EFAULT
:
10034 case FILEIO_EEXIST
:
10036 case FILEIO_ENODEV
:
10038 case FILEIO_ENOTDIR
:
10040 case FILEIO_EISDIR
:
10042 case FILEIO_EINVAL
:
10044 case FILEIO_ENFILE
:
10046 case FILEIO_EMFILE
:
10050 case FILEIO_ENOSPC
:
10052 case FILEIO_ESPIPE
:
10056 case FILEIO_ENOSYS
:
10058 case FILEIO_ENAMETOOLONG
:
10059 return ENAMETOOLONG
;
10065 remote_hostio_error (int errnum
)
10067 int host_error
= remote_fileio_errno_to_host (errnum
);
10069 if (host_error
== -1)
10070 error (_("Unknown remote I/O error %d"), errnum
);
10072 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
10076 remote_hostio_close_cleanup (void *opaque
)
10078 int fd
= *(int *) opaque
;
10081 remote_hostio_close (fd
, &remote_errno
);
10086 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
10088 const char *filename
= bfd_get_filename (abfd
);
10089 int fd
, remote_errno
;
10092 gdb_assert (remote_filename_p (filename
));
10094 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
10097 errno
= remote_fileio_errno_to_host (remote_errno
);
10098 bfd_set_error (bfd_error_system_call
);
10102 stream
= xmalloc (sizeof (int));
10108 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
10110 int fd
= *(int *)stream
;
10115 /* Ignore errors on close; these may happen if the remote
10116 connection was already torn down. */
10117 remote_hostio_close (fd
, &remote_errno
);
10119 /* Zero means success. */
10124 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
10125 file_ptr nbytes
, file_ptr offset
)
10127 int fd
= *(int *)stream
;
10129 file_ptr pos
, bytes
;
10132 while (nbytes
> pos
)
10134 bytes
= remote_hostio_pread (fd
, (gdb_byte
*) buf
+ pos
, nbytes
- pos
,
10135 offset
+ pos
, &remote_errno
);
10137 /* Success, but no bytes, means end-of-file. */
10141 errno
= remote_fileio_errno_to_host (remote_errno
);
10142 bfd_set_error (bfd_error_system_call
);
10153 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
10155 /* FIXME: We should probably implement remote_hostio_stat. */
10156 sb
->st_size
= INT_MAX
;
10161 remote_filename_p (const char *filename
)
10163 return strncmp (filename
,
10164 REMOTE_SYSROOT_PREFIX
,
10165 sizeof (REMOTE_SYSROOT_PREFIX
) - 1) == 0;
10169 remote_bfd_open (const char *remote_file
, const char *target
)
10171 bfd
*abfd
= gdb_bfd_openr_iovec (remote_file
, target
,
10172 remote_bfd_iovec_open
, NULL
,
10173 remote_bfd_iovec_pread
,
10174 remote_bfd_iovec_close
,
10175 remote_bfd_iovec_stat
);
10181 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10183 struct cleanup
*back_to
, *close_cleanup
;
10184 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10187 int bytes_in_buffer
;
10190 struct remote_state
*rs
= get_remote_state ();
10192 if (!rs
->remote_desc
)
10193 error (_("command can only be used with remote target"));
10195 file
= gdb_fopen_cloexec (local_file
, "rb");
10197 perror_with_name (local_file
);
10198 back_to
= make_cleanup_fclose (file
);
10200 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10202 0700, &remote_errno
);
10204 remote_hostio_error (remote_errno
);
10206 /* Send up to this many bytes at once. They won't all fit in the
10207 remote packet limit, so we'll transfer slightly fewer. */
10208 io_size
= get_remote_packet_size ();
10209 buffer
= xmalloc (io_size
);
10210 make_cleanup (xfree
, buffer
);
10212 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10214 bytes_in_buffer
= 0;
10217 while (bytes_in_buffer
|| !saw_eof
)
10221 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10222 io_size
- bytes_in_buffer
,
10227 error (_("Error reading %s."), local_file
);
10230 /* EOF. Unless there is something still in the
10231 buffer from the last iteration, we are done. */
10233 if (bytes_in_buffer
== 0)
10241 bytes
+= bytes_in_buffer
;
10242 bytes_in_buffer
= 0;
10244 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
10245 offset
, &remote_errno
);
10248 remote_hostio_error (remote_errno
);
10249 else if (retcode
== 0)
10250 error (_("Remote write of %d bytes returned 0!"), bytes
);
10251 else if (retcode
< bytes
)
10253 /* Short write. Save the rest of the read data for the next
10255 bytes_in_buffer
= bytes
- retcode
;
10256 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10262 discard_cleanups (close_cleanup
);
10263 if (remote_hostio_close (fd
, &remote_errno
))
10264 remote_hostio_error (remote_errno
);
10267 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10268 do_cleanups (back_to
);
10272 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10274 struct cleanup
*back_to
, *close_cleanup
;
10275 int fd
, remote_errno
, bytes
, io_size
;
10279 struct remote_state
*rs
= get_remote_state ();
10281 if (!rs
->remote_desc
)
10282 error (_("command can only be used with remote target"));
10284 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10286 remote_hostio_error (remote_errno
);
10288 file
= gdb_fopen_cloexec (local_file
, "wb");
10290 perror_with_name (local_file
);
10291 back_to
= make_cleanup_fclose (file
);
10293 /* Send up to this many bytes at once. They won't all fit in the
10294 remote packet limit, so we'll transfer slightly fewer. */
10295 io_size
= get_remote_packet_size ();
10296 buffer
= xmalloc (io_size
);
10297 make_cleanup (xfree
, buffer
);
10299 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10304 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
10306 /* Success, but no bytes, means end-of-file. */
10309 remote_hostio_error (remote_errno
);
10313 bytes
= fwrite (buffer
, 1, bytes
, file
);
10315 perror_with_name (local_file
);
10318 discard_cleanups (close_cleanup
);
10319 if (remote_hostio_close (fd
, &remote_errno
))
10320 remote_hostio_error (remote_errno
);
10323 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10324 do_cleanups (back_to
);
10328 remote_file_delete (const char *remote_file
, int from_tty
)
10330 int retcode
, remote_errno
;
10331 struct remote_state
*rs
= get_remote_state ();
10333 if (!rs
->remote_desc
)
10334 error (_("command can only be used with remote target"));
10336 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
10338 remote_hostio_error (remote_errno
);
10341 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10345 remote_put_command (char *args
, int from_tty
)
10347 struct cleanup
*back_to
;
10351 error_no_arg (_("file to put"));
10353 argv
= gdb_buildargv (args
);
10354 back_to
= make_cleanup_freeargv (argv
);
10355 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10356 error (_("Invalid parameters to remote put"));
10358 remote_file_put (argv
[0], argv
[1], from_tty
);
10360 do_cleanups (back_to
);
10364 remote_get_command (char *args
, int from_tty
)
10366 struct cleanup
*back_to
;
10370 error_no_arg (_("file to get"));
10372 argv
= gdb_buildargv (args
);
10373 back_to
= make_cleanup_freeargv (argv
);
10374 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10375 error (_("Invalid parameters to remote get"));
10377 remote_file_get (argv
[0], argv
[1], from_tty
);
10379 do_cleanups (back_to
);
10383 remote_delete_command (char *args
, int from_tty
)
10385 struct cleanup
*back_to
;
10389 error_no_arg (_("file to delete"));
10391 argv
= gdb_buildargv (args
);
10392 back_to
= make_cleanup_freeargv (argv
);
10393 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10394 error (_("Invalid parameters to remote delete"));
10396 remote_file_delete (argv
[0], from_tty
);
10398 do_cleanups (back_to
);
10402 remote_command (char *args
, int from_tty
)
10404 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
10408 remote_can_execute_reverse (void)
10410 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
10411 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
10418 remote_supports_non_stop (void)
10424 remote_supports_disable_randomization (void)
10426 /* Only supported in extended mode. */
10431 remote_supports_multi_process (void)
10433 struct remote_state
*rs
= get_remote_state ();
10435 /* Only extended-remote handles being attached to multiple
10436 processes, even though plain remote can use the multi-process
10437 thread id extensions, so that GDB knows the target process's
10439 return rs
->extended
&& remote_multi_process_p (rs
);
10443 remote_supports_cond_tracepoints (void)
10445 struct remote_state
*rs
= get_remote_state ();
10447 return rs
->cond_tracepoints
;
10451 remote_supports_cond_breakpoints (void)
10453 struct remote_state
*rs
= get_remote_state ();
10455 return rs
->cond_breakpoints
;
10459 remote_supports_fast_tracepoints (void)
10461 struct remote_state
*rs
= get_remote_state ();
10463 return rs
->fast_tracepoints
;
10467 remote_supports_static_tracepoints (void)
10469 struct remote_state
*rs
= get_remote_state ();
10471 return rs
->static_tracepoints
;
10475 remote_supports_install_in_trace (void)
10477 struct remote_state
*rs
= get_remote_state ();
10479 return rs
->install_in_trace
;
10483 remote_supports_enable_disable_tracepoint (void)
10485 struct remote_state
*rs
= get_remote_state ();
10487 return rs
->enable_disable_tracepoints
;
10491 remote_supports_string_tracing (void)
10493 struct remote_state
*rs
= get_remote_state ();
10495 return rs
->string_tracing
;
10499 remote_can_run_breakpoint_commands (void)
10501 struct remote_state
*rs
= get_remote_state ();
10503 return rs
->breakpoint_commands
;
10507 remote_trace_init (void)
10510 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10511 if (strcmp (target_buf
, "OK") != 0)
10512 error (_("Target does not support this command."));
10515 static void free_actions_list (char **actions_list
);
10516 static void free_actions_list_cleanup_wrapper (void *);
10518 free_actions_list_cleanup_wrapper (void *al
)
10520 free_actions_list (al
);
10524 free_actions_list (char **actions_list
)
10528 if (actions_list
== 0)
10531 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10532 xfree (actions_list
[ndx
]);
10534 xfree (actions_list
);
10537 /* Recursive routine to walk through command list including loops, and
10538 download packets for each command. */
10541 remote_download_command_source (int num
, ULONGEST addr
,
10542 struct command_line
*cmds
)
10544 struct remote_state
*rs
= get_remote_state ();
10545 struct command_line
*cmd
;
10547 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10549 QUIT
; /* Allow user to bail out with ^C. */
10550 strcpy (rs
->buf
, "QTDPsrc:");
10551 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10552 rs
->buf
+ strlen (rs
->buf
),
10553 rs
->buf_size
- strlen (rs
->buf
));
10555 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10556 if (strcmp (target_buf
, "OK"))
10557 warning (_("Target does not support source download."));
10559 if (cmd
->control_type
== while_control
10560 || cmd
->control_type
== while_stepping_control
)
10562 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10564 QUIT
; /* Allow user to bail out with ^C. */
10565 strcpy (rs
->buf
, "QTDPsrc:");
10566 encode_source_string (num
, addr
, "cmd", "end",
10567 rs
->buf
+ strlen (rs
->buf
),
10568 rs
->buf_size
- strlen (rs
->buf
));
10570 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10571 if (strcmp (target_buf
, "OK"))
10572 warning (_("Target does not support source download."));
10578 remote_download_tracepoint (struct bp_location
*loc
)
10580 #define BUF_SIZE 2048
10584 char buf
[BUF_SIZE
];
10585 char **tdp_actions
;
10586 char **stepping_actions
;
10588 struct cleanup
*old_chain
= NULL
;
10589 struct agent_expr
*aexpr
;
10590 struct cleanup
*aexpr_chain
= NULL
;
10592 struct breakpoint
*b
= loc
->owner
;
10593 struct tracepoint
*t
= (struct tracepoint
*) b
;
10595 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
10596 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10598 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10601 tpaddr
= loc
->address
;
10602 sprintf_vma (addrbuf
, tpaddr
);
10603 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10604 addrbuf
, /* address */
10605 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10606 t
->step_count
, t
->pass_count
);
10607 /* Fast tracepoints are mostly handled by the target, but we can
10608 tell the target how big of an instruction block should be moved
10610 if (b
->type
== bp_fast_tracepoint
)
10612 /* Only test for support at download time; we may not know
10613 target capabilities at definition time. */
10614 if (remote_supports_fast_tracepoints ())
10618 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10619 tpaddr
, &isize
, NULL
))
10620 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10623 /* If it passed validation at definition but fails now,
10624 something is very wrong. */
10625 internal_error (__FILE__
, __LINE__
,
10626 _("Fast tracepoint not "
10627 "valid during download"));
10630 /* Fast tracepoints are functionally identical to regular
10631 tracepoints, so don't take lack of support as a reason to
10632 give up on the trace run. */
10633 warning (_("Target does not support fast tracepoints, "
10634 "downloading %d as regular tracepoint"), b
->number
);
10636 else if (b
->type
== bp_static_tracepoint
)
10638 /* Only test for support at download time; we may not know
10639 target capabilities at definition time. */
10640 if (remote_supports_static_tracepoints ())
10642 struct static_tracepoint_marker marker
;
10644 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10645 strcat (buf
, ":S");
10647 error (_("Static tracepoint not valid during download"));
10650 /* Fast tracepoints are functionally identical to regular
10651 tracepoints, so don't take lack of support as a reason
10652 to give up on the trace run. */
10653 error (_("Target does not support static tracepoints"));
10655 /* If the tracepoint has a conditional, make it into an agent
10656 expression and append to the definition. */
10659 /* Only test support at download time, we may not know target
10660 capabilities at definition time. */
10661 if (remote_supports_cond_tracepoints ())
10663 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10664 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10665 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10667 pkt
= buf
+ strlen (buf
);
10668 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10669 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10671 do_cleanups (aexpr_chain
);
10674 warning (_("Target does not support conditional tracepoints, "
10675 "ignoring tp %d cond"), b
->number
);
10678 if (b
->commands
|| *default_collect
)
10681 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10682 if (strcmp (target_buf
, "OK"))
10683 error (_("Target does not support tracepoints."));
10685 /* do_single_steps (t); */
10688 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10690 QUIT
; /* Allow user to bail out with ^C. */
10691 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10692 b
->number
, addrbuf
, /* address */
10694 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10697 remote_get_noisy_reply (&target_buf
,
10699 if (strcmp (target_buf
, "OK"))
10700 error (_("Error on target while setting tracepoints."));
10703 if (stepping_actions
)
10705 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10707 QUIT
; /* Allow user to bail out with ^C. */
10708 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10709 b
->number
, addrbuf
, /* address */
10710 ((ndx
== 0) ? "S" : ""),
10711 stepping_actions
[ndx
],
10712 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10714 remote_get_noisy_reply (&target_buf
,
10716 if (strcmp (target_buf
, "OK"))
10717 error (_("Error on target while setting tracepoints."));
10721 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10724 if (b
->addr_string
)
10726 strcpy (buf
, "QTDPsrc:");
10727 encode_source_string (b
->number
, loc
->address
,
10728 "at", b
->addr_string
, buf
+ strlen (buf
),
10729 2048 - strlen (buf
));
10732 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10733 if (strcmp (target_buf
, "OK"))
10734 warning (_("Target does not support source download."));
10736 if (b
->cond_string
)
10738 strcpy (buf
, "QTDPsrc:");
10739 encode_source_string (b
->number
, loc
->address
,
10740 "cond", b
->cond_string
, buf
+ strlen (buf
),
10741 2048 - strlen (buf
));
10743 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10744 if (strcmp (target_buf
, "OK"))
10745 warning (_("Target does not support source download."));
10747 remote_download_command_source (b
->number
, loc
->address
,
10748 breakpoint_commands (b
));
10751 do_cleanups (old_chain
);
10755 remote_can_download_tracepoint (void)
10757 struct remote_state
*rs
= get_remote_state ();
10758 struct trace_status
*ts
;
10761 /* Don't try to install tracepoints until we've relocated our
10762 symbols, and fetched and merged the target's tracepoint list with
10764 if (rs
->starting_up
)
10767 ts
= current_trace_status ();
10768 status
= remote_get_trace_status (ts
);
10770 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10773 /* If we are in a tracing experiment, but remote stub doesn't support
10774 installing tracepoint in trace, we have to return. */
10775 if (!remote_supports_install_in_trace ())
10783 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10785 struct remote_state
*rs
= get_remote_state ();
10788 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10789 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10791 p
= rs
->buf
+ strlen (rs
->buf
);
10792 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10793 error (_("Trace state variable name too long for tsv definition packet"));
10794 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10797 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10798 if (*target_buf
== '\0')
10799 error (_("Target does not support this command."));
10800 if (strcmp (target_buf
, "OK") != 0)
10801 error (_("Error on target while downloading trace state variable."));
10805 remote_enable_tracepoint (struct bp_location
*location
)
10807 struct remote_state
*rs
= get_remote_state ();
10810 sprintf_vma (addr_buf
, location
->address
);
10811 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10812 location
->owner
->number
, addr_buf
);
10814 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10815 if (*rs
->buf
== '\0')
10816 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10817 if (strcmp (rs
->buf
, "OK") != 0)
10818 error (_("Error on target while enabling tracepoint."));
10822 remote_disable_tracepoint (struct bp_location
*location
)
10824 struct remote_state
*rs
= get_remote_state ();
10827 sprintf_vma (addr_buf
, location
->address
);
10828 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10829 location
->owner
->number
, addr_buf
);
10831 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10832 if (*rs
->buf
== '\0')
10833 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10834 if (strcmp (rs
->buf
, "OK") != 0)
10835 error (_("Error on target while disabling tracepoint."));
10839 remote_trace_set_readonly_regions (void)
10843 bfd_size_type size
;
10849 return; /* No information to give. */
10851 strcpy (target_buf
, "QTro");
10852 offset
= strlen (target_buf
);
10853 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10855 char tmp1
[40], tmp2
[40];
10858 if ((s
->flags
& SEC_LOAD
) == 0 ||
10859 /* (s->flags & SEC_CODE) == 0 || */
10860 (s
->flags
& SEC_READONLY
) == 0)
10864 vma
= bfd_get_section_vma (abfd
, s
);
10865 size
= bfd_get_section_size (s
);
10866 sprintf_vma (tmp1
, vma
);
10867 sprintf_vma (tmp2
, vma
+ size
);
10868 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10869 if (offset
+ sec_length
+ 1 > target_buf_size
)
10871 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10874 Too many sections for read-only sections definition packet."));
10877 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10879 offset
+= sec_length
;
10883 putpkt (target_buf
);
10884 getpkt (&target_buf
, &target_buf_size
, 0);
10889 remote_trace_start (void)
10891 putpkt ("QTStart");
10892 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10893 if (*target_buf
== '\0')
10894 error (_("Target does not support this command."));
10895 if (strcmp (target_buf
, "OK") != 0)
10896 error (_("Bogus reply from target: %s"), target_buf
);
10900 remote_get_trace_status (struct trace_status
*ts
)
10902 /* Initialize it just to avoid a GCC false warning. */
10904 /* FIXME we need to get register block size some other way. */
10905 extern int trace_regblock_size
;
10906 volatile struct gdb_exception ex
;
10907 enum packet_result result
;
10909 if (remote_protocol_packets
[PACKET_qTStatus
].support
== PACKET_DISABLE
)
10912 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10914 putpkt ("qTStatus");
10916 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10918 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10922 if (ex
.error
!= TARGET_CLOSE_ERROR
)
10924 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10927 throw_exception (ex
);
10930 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
10932 /* If the remote target doesn't do tracing, flag it. */
10933 if (result
== PACKET_UNKNOWN
)
10936 /* We're working with a live target. */
10937 ts
->filename
= NULL
;
10940 error (_("Bogus trace status reply from target: %s"), target_buf
);
10942 /* Function 'parse_trace_status' sets default value of each field of
10943 'ts' at first, so we don't have to do it here. */
10944 parse_trace_status (p
, ts
);
10946 return ts
->running
;
10950 remote_get_tracepoint_status (struct breakpoint
*bp
,
10951 struct uploaded_tp
*utp
)
10953 struct remote_state
*rs
= get_remote_state ();
10955 struct bp_location
*loc
;
10956 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10957 size_t size
= get_remote_packet_size ();
10961 tp
->base
.hit_count
= 0;
10962 tp
->traceframe_usage
= 0;
10963 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10965 /* If the tracepoint was never downloaded, don't go asking for
10967 if (tp
->number_on_target
== 0)
10969 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10970 phex_nz (loc
->address
, 0));
10972 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10973 if (reply
&& *reply
)
10976 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10982 utp
->hit_count
= 0;
10983 utp
->traceframe_usage
= 0;
10984 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10985 phex_nz (utp
->addr
, 0));
10987 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10988 if (reply
&& *reply
)
10991 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10997 remote_trace_stop (void)
11000 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11001 if (*target_buf
== '\0')
11002 error (_("Target does not support this command."));
11003 if (strcmp (target_buf
, "OK") != 0)
11004 error (_("Bogus reply from target: %s"), target_buf
);
11008 remote_trace_find (enum trace_find_type type
, int num
,
11009 CORE_ADDR addr1
, CORE_ADDR addr2
,
11012 struct remote_state
*rs
= get_remote_state ();
11013 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11015 int target_frameno
= -1, target_tracept
= -1;
11017 /* Lookups other than by absolute frame number depend on the current
11018 trace selected, so make sure it is correct on the remote end
11020 if (type
!= tfind_number
)
11021 set_remote_traceframe ();
11024 strcpy (p
, "QTFrame:");
11025 p
= strchr (p
, '\0');
11029 xsnprintf (p
, endbuf
- p
, "%x", num
);
11032 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
11035 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
11038 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
11039 phex_nz (addr2
, 0));
11041 case tfind_outside
:
11042 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
11043 phex_nz (addr2
, 0));
11046 error (_("Unknown trace find type %d"), type
);
11050 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
11051 if (*reply
== '\0')
11052 error (_("Target does not support this command."));
11054 while (reply
&& *reply
)
11059 target_frameno
= (int) strtol (p
, &reply
, 16);
11061 error (_("Unable to parse trace frame number"));
11062 /* Don't update our remote traceframe number cache on failure
11063 to select a remote traceframe. */
11064 if (target_frameno
== -1)
11069 target_tracept
= (int) strtol (p
, &reply
, 16);
11071 error (_("Unable to parse tracepoint number"));
11073 case 'O': /* "OK"? */
11074 if (reply
[1] == 'K' && reply
[2] == '\0')
11077 error (_("Bogus reply from target: %s"), reply
);
11080 error (_("Bogus reply from target: %s"), reply
);
11083 *tpp
= target_tracept
;
11085 rs
->remote_traceframe_number
= target_frameno
;
11086 return target_frameno
;
11090 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
11092 struct remote_state
*rs
= get_remote_state ();
11096 set_remote_traceframe ();
11098 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
11100 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11101 if (reply
&& *reply
)
11105 unpack_varlen_hex (reply
+ 1, &uval
);
11106 *val
= (LONGEST
) uval
;
11114 remote_save_trace_data (const char *filename
)
11116 struct remote_state
*rs
= get_remote_state ();
11120 strcpy (p
, "QTSave:");
11122 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
11123 error (_("Remote file name too long for trace save packet"));
11124 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
11127 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11128 if (*reply
== '\0')
11129 error (_("Target does not support this command."));
11130 if (strcmp (reply
, "OK") != 0)
11131 error (_("Bogus reply from target: %s"), reply
);
11135 /* This is basically a memory transfer, but needs to be its own packet
11136 because we don't know how the target actually organizes its trace
11137 memory, plus we want to be able to ask for as much as possible, but
11138 not be unhappy if we don't get as much as we ask for. */
11141 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11143 struct remote_state
*rs
= get_remote_state ();
11149 strcpy (p
, "qTBuffer:");
11151 p
+= hexnumstr (p
, offset
);
11153 p
+= hexnumstr (p
, len
);
11157 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11158 if (reply
&& *reply
)
11160 /* 'l' by itself means we're at the end of the buffer and
11161 there is nothing more to get. */
11165 /* Convert the reply into binary. Limit the number of bytes to
11166 convert according to our passed-in buffer size, rather than
11167 what was returned in the packet; if the target is
11168 unexpectedly generous and gives us a bigger reply than we
11169 asked for, we don't want to crash. */
11170 rslt
= hex2bin (target_buf
, buf
, len
);
11174 /* Something went wrong, flag as an error. */
11179 remote_set_disconnected_tracing (int val
)
11181 struct remote_state
*rs
= get_remote_state ();
11183 if (rs
->disconnected_tracing
)
11187 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11189 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11190 if (*reply
== '\0')
11191 error (_("Target does not support this command."));
11192 if (strcmp (reply
, "OK") != 0)
11193 error (_("Bogus reply from target: %s"), reply
);
11196 warning (_("Target does not support disconnected tracing."));
11200 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11202 struct thread_info
*info
= find_thread_ptid (ptid
);
11204 if (info
&& info
->private)
11205 return info
->private->core
;
11210 remote_set_circular_trace_buffer (int val
)
11212 struct remote_state
*rs
= get_remote_state ();
11215 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11217 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11218 if (*reply
== '\0')
11219 error (_("Target does not support this command."));
11220 if (strcmp (reply
, "OK") != 0)
11221 error (_("Bogus reply from target: %s"), reply
);
11224 static struct traceframe_info
*
11225 remote_traceframe_info (void)
11229 /* If current traceframe is not selected, don't bother the remote
11231 if (get_traceframe_number () < 0)
11234 text
= target_read_stralloc (¤t_target
,
11235 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11238 struct traceframe_info
*info
;
11239 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11241 info
= parse_traceframe_info (text
);
11242 do_cleanups (back_to
);
11249 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11250 instruction on which a fast tracepoint may be placed. Returns -1
11251 if the packet is not supported, and 0 if the minimum instruction
11252 length is unknown. */
11255 remote_get_min_fast_tracepoint_insn_len (void)
11257 struct remote_state
*rs
= get_remote_state ();
11260 /* If we're not debugging a process yet, the IPA can't be
11262 if (!target_has_execution
)
11265 /* Make sure the remote is pointing at the right process. */
11266 set_general_process ();
11268 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11270 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11271 if (*reply
== '\0')
11275 ULONGEST min_insn_len
;
11277 unpack_varlen_hex (reply
, &min_insn_len
);
11279 return (int) min_insn_len
;
11284 remote_set_trace_buffer_size (LONGEST val
)
11286 if (remote_protocol_packets
[PACKET_QTBuffer_size
].support
11289 struct remote_state
*rs
= get_remote_state ();
11290 char *buf
= rs
->buf
;
11291 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11292 enum packet_result result
;
11294 gdb_assert (val
>= 0 || val
== -1);
11295 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11296 /* Send -1 as literal "-1" to avoid host size dependency. */
11300 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11303 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11306 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11307 result
= packet_ok (rs
->buf
,
11308 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11310 if (result
!= PACKET_OK
)
11311 warning (_("Bogus reply from target: %s"), rs
->buf
);
11316 remote_set_trace_notes (const char *user
, const char *notes
,
11317 const char *stop_notes
)
11319 struct remote_state
*rs
= get_remote_state ();
11321 char *buf
= rs
->buf
;
11322 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11325 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11328 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11329 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, 0);
11335 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11336 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, 0);
11342 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11343 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, 0);
11347 /* Ensure the buffer is terminated. */
11351 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11352 if (*reply
== '\0')
11355 if (strcmp (reply
, "OK") != 0)
11356 error (_("Bogus reply from target: %s"), reply
);
11362 remote_use_agent (int use
)
11364 if (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
)
11366 struct remote_state
*rs
= get_remote_state ();
11368 /* If the stub supports QAgent. */
11369 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11371 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11373 if (strcmp (rs
->buf
, "OK") == 0)
11384 remote_can_use_agent (void)
11386 return (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
);
11389 struct btrace_target_info
11391 /* The ptid of the traced thread. */
11395 /* Check whether the target supports branch tracing. */
11398 remote_supports_btrace (void)
11400 if (remote_protocol_packets
[PACKET_Qbtrace_off
].support
!= PACKET_ENABLE
)
11402 if (remote_protocol_packets
[PACKET_Qbtrace_bts
].support
!= PACKET_ENABLE
)
11404 if (remote_protocol_packets
[PACKET_qXfer_btrace
].support
!= PACKET_ENABLE
)
11410 /* Enable branch tracing. */
11412 static struct btrace_target_info
*
11413 remote_enable_btrace (ptid_t ptid
)
11415 struct btrace_target_info
*tinfo
= NULL
;
11416 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
11417 struct remote_state
*rs
= get_remote_state ();
11418 char *buf
= rs
->buf
;
11419 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11421 if (packet
->support
!= PACKET_ENABLE
)
11422 error (_("Target does not support branch tracing."));
11424 set_general_thread (ptid
);
11426 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11428 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11430 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11432 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11433 error (_("Could not enable branch tracing for %s: %s"),
11434 target_pid_to_str (ptid
), rs
->buf
+ 2);
11436 error (_("Could not enable branch tracing for %s."),
11437 target_pid_to_str (ptid
));
11440 tinfo
= xzalloc (sizeof (*tinfo
));
11441 tinfo
->ptid
= ptid
;
11446 /* Disable branch tracing. */
11449 remote_disable_btrace (struct btrace_target_info
*tinfo
)
11451 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
11452 struct remote_state
*rs
= get_remote_state ();
11453 char *buf
= rs
->buf
;
11454 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11456 if (packet
->support
!= PACKET_ENABLE
)
11457 error (_("Target does not support branch tracing."));
11459 set_general_thread (tinfo
->ptid
);
11461 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11463 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11465 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11467 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11468 error (_("Could not disable branch tracing for %s: %s"),
11469 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
11471 error (_("Could not disable branch tracing for %s."),
11472 target_pid_to_str (tinfo
->ptid
));
11478 /* Teardown branch tracing. */
11481 remote_teardown_btrace (struct btrace_target_info
*tinfo
)
11483 /* We must not talk to the target during teardown. */
11487 /* Read the branch trace. */
11489 static VEC (btrace_block_s
) *
11490 remote_read_btrace (struct btrace_target_info
*tinfo
,
11491 enum btrace_read_type type
)
11493 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
11494 struct remote_state
*rs
= get_remote_state ();
11495 VEC (btrace_block_s
) *btrace
= NULL
;
11499 if (packet
->support
!= PACKET_ENABLE
)
11500 error (_("Target does not support branch tracing."));
11502 #if !defined(HAVE_LIBEXPAT)
11503 error (_("Cannot process branch tracing result. XML parsing not supported."));
11508 case BTRACE_READ_ALL
:
11511 case BTRACE_READ_NEW
:
11515 internal_error (__FILE__
, __LINE__
,
11516 _("Bad branch tracing read type: %u."),
11517 (unsigned int) type
);
11520 xml
= target_read_stralloc (¤t_target
,
11521 TARGET_OBJECT_BTRACE
, annex
);
11524 struct cleanup
*cleanup
= make_cleanup (xfree
, xml
);
11526 btrace
= parse_xml_btrace (xml
);
11527 do_cleanups (cleanup
);
11534 remote_augmented_libraries_svr4_read (void)
11536 struct remote_state
*rs
= get_remote_state ();
11538 return rs
->augmented_libraries_svr4_read
;
11542 init_remote_ops (void)
11544 remote_ops
.to_shortname
= "remote";
11545 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11546 remote_ops
.to_doc
=
11547 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11548 Specify the serial device it is connected to\n\
11549 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11550 remote_ops
.to_open
= remote_open
;
11551 remote_ops
.to_close
= remote_close
;
11552 remote_ops
.to_detach
= remote_detach
;
11553 remote_ops
.to_disconnect
= remote_disconnect
;
11554 remote_ops
.to_resume
= remote_resume
;
11555 remote_ops
.to_wait
= remote_wait
;
11556 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11557 remote_ops
.to_store_registers
= remote_store_registers
;
11558 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11559 remote_ops
.to_files_info
= remote_files_info
;
11560 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11561 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11562 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11563 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11564 remote_ops
.to_watchpoint_addr_within_range
=
11565 remote_watchpoint_addr_within_range
;
11566 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11567 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11568 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11569 remote_ops
.to_region_ok_for_hw_watchpoint
11570 = remote_region_ok_for_hw_watchpoint
;
11571 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11572 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11573 remote_ops
.to_kill
= remote_kill
;
11574 remote_ops
.to_load
= generic_load
;
11575 remote_ops
.to_mourn_inferior
= remote_mourn
;
11576 remote_ops
.to_pass_signals
= remote_pass_signals
;
11577 remote_ops
.to_program_signals
= remote_program_signals
;
11578 remote_ops
.to_thread_alive
= remote_thread_alive
;
11579 remote_ops
.to_find_new_threads
= remote_threads_info
;
11580 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11581 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11582 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11583 remote_ops
.to_stop
= remote_stop
;
11584 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11585 remote_ops
.to_rcmd
= remote_rcmd
;
11586 remote_ops
.to_log_command
= serial_log_command
;
11587 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11588 remote_ops
.to_stratum
= process_stratum
;
11589 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11590 remote_ops
.to_has_memory
= default_child_has_memory
;
11591 remote_ops
.to_has_stack
= default_child_has_stack
;
11592 remote_ops
.to_has_registers
= default_child_has_registers
;
11593 remote_ops
.to_has_execution
= default_child_has_execution
;
11594 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11595 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11596 remote_ops
.to_magic
= OPS_MAGIC
;
11597 remote_ops
.to_memory_map
= remote_memory_map
;
11598 remote_ops
.to_flash_erase
= remote_flash_erase
;
11599 remote_ops
.to_flash_done
= remote_flash_done
;
11600 remote_ops
.to_read_description
= remote_read_description
;
11601 remote_ops
.to_search_memory
= remote_search_memory
;
11602 remote_ops
.to_can_async_p
= remote_can_async_p
;
11603 remote_ops
.to_is_async_p
= remote_is_async_p
;
11604 remote_ops
.to_async
= remote_async
;
11605 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11606 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11607 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11608 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11609 remote_ops
.to_supports_disable_randomization
11610 = remote_supports_disable_randomization
;
11611 remote_ops
.to_fileio_open
= remote_hostio_open
;
11612 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11613 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11614 remote_ops
.to_fileio_close
= remote_hostio_close
;
11615 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11616 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11617 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11618 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11619 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11620 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11621 remote_ops
.to_trace_init
= remote_trace_init
;
11622 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11623 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11624 remote_ops
.to_download_trace_state_variable
11625 = remote_download_trace_state_variable
;
11626 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11627 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11628 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11629 remote_ops
.to_trace_start
= remote_trace_start
;
11630 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11631 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11632 remote_ops
.to_trace_stop
= remote_trace_stop
;
11633 remote_ops
.to_trace_find
= remote_trace_find
;
11634 remote_ops
.to_get_trace_state_variable_value
11635 = remote_get_trace_state_variable_value
;
11636 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11637 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11638 remote_ops
.to_upload_trace_state_variables
11639 = remote_upload_trace_state_variables
;
11640 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11641 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11642 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11643 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11644 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
11645 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11646 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11647 remote_ops
.to_verify_memory
= remote_verify_memory
;
11648 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11649 remote_ops
.to_set_permissions
= remote_set_permissions
;
11650 remote_ops
.to_static_tracepoint_marker_at
11651 = remote_static_tracepoint_marker_at
;
11652 remote_ops
.to_static_tracepoint_markers_by_strid
11653 = remote_static_tracepoint_markers_by_strid
;
11654 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11655 remote_ops
.to_use_agent
= remote_use_agent
;
11656 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11657 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
11658 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
11659 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
11660 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
11661 remote_ops
.to_read_btrace
= remote_read_btrace
;
11662 remote_ops
.to_augmented_libraries_svr4_read
=
11663 remote_augmented_libraries_svr4_read
;
11666 /* Set up the extended remote vector by making a copy of the standard
11667 remote vector and adding to it. */
11670 init_extended_remote_ops (void)
11672 extended_remote_ops
= remote_ops
;
11674 extended_remote_ops
.to_shortname
= "extended-remote";
11675 extended_remote_ops
.to_longname
=
11676 "Extended remote serial target in gdb-specific protocol";
11677 extended_remote_ops
.to_doc
=
11678 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11679 Specify the serial device it is connected to (e.g. /dev/ttya).";
11680 extended_remote_ops
.to_open
= extended_remote_open
;
11681 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11682 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11683 extended_remote_ops
.to_detach
= extended_remote_detach
;
11684 extended_remote_ops
.to_attach
= extended_remote_attach
;
11685 extended_remote_ops
.to_kill
= extended_remote_kill
;
11686 extended_remote_ops
.to_supports_disable_randomization
11687 = extended_remote_supports_disable_randomization
;
11691 remote_can_async_p (void)
11693 struct remote_state
*rs
= get_remote_state ();
11695 if (!target_async_permitted
)
11696 /* We only enable async when the user specifically asks for it. */
11699 /* We're async whenever the serial device is. */
11700 return serial_can_async_p (rs
->remote_desc
);
11704 remote_is_async_p (void)
11706 struct remote_state
*rs
= get_remote_state ();
11708 if (!target_async_permitted
)
11709 /* We only enable async when the user specifically asks for it. */
11712 /* We're async whenever the serial device is. */
11713 return serial_is_async_p (rs
->remote_desc
);
11716 /* Pass the SERIAL event on and up to the client. One day this code
11717 will be able to delay notifying the client of an event until the
11718 point where an entire packet has been received. */
11720 static serial_event_ftype remote_async_serial_handler
;
11723 remote_async_serial_handler (struct serial
*scb
, void *context
)
11725 struct remote_state
*rs
= context
;
11727 /* Don't propogate error information up to the client. Instead let
11728 the client find out about the error by querying the target. */
11729 rs
->async_client_callback (INF_REG_EVENT
, rs
->async_client_context
);
11733 remote_async_inferior_event_handler (gdb_client_data data
)
11735 inferior_event_handler (INF_REG_EVENT
, NULL
);
11739 remote_async (void (*callback
) (enum inferior_event_type event_type
,
11740 void *context
), void *context
)
11742 struct remote_state
*rs
= get_remote_state ();
11744 if (callback
!= NULL
)
11746 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
11747 rs
->async_client_callback
= callback
;
11748 rs
->async_client_context
= context
;
11751 serial_async (rs
->remote_desc
, NULL
, NULL
);
11755 set_remote_cmd (char *args
, int from_tty
)
11757 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
11761 show_remote_cmd (char *args
, int from_tty
)
11763 /* We can't just use cmd_show_list here, because we want to skip
11764 the redundant "show remote Z-packet" and the legacy aliases. */
11765 struct cleanup
*showlist_chain
;
11766 struct cmd_list_element
*list
= remote_show_cmdlist
;
11767 struct ui_out
*uiout
= current_uiout
;
11769 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11770 for (; list
!= NULL
; list
= list
->next
)
11771 if (strcmp (list
->name
, "Z-packet") == 0)
11773 else if (list
->type
== not_set_cmd
)
11774 /* Alias commands are exactly like the original, except they
11775 don't have the normal type. */
11779 struct cleanup
*option_chain
11780 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11782 ui_out_field_string (uiout
, "name", list
->name
);
11783 ui_out_text (uiout
, ": ");
11784 if (list
->type
== show_cmd
)
11785 do_show_command ((char *) NULL
, from_tty
, list
);
11787 cmd_func (list
, NULL
, from_tty
);
11788 /* Close the tuple. */
11789 do_cleanups (option_chain
);
11792 /* Close the tuple. */
11793 do_cleanups (showlist_chain
);
11797 /* Function to be called whenever a new objfile (shlib) is detected. */
11799 remote_new_objfile (struct objfile
*objfile
)
11801 struct remote_state
*rs
= get_remote_state ();
11803 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
11804 remote_check_symbols ();
11807 /* Pull all the tracepoints defined on the target and create local
11808 data structures representing them. We don't want to create real
11809 tracepoints yet, we don't want to mess up the user's existing
11813 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
11815 struct remote_state
*rs
= get_remote_state ();
11818 /* Ask for a first packet of tracepoint definition. */
11820 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11822 while (*p
&& *p
!= 'l')
11824 parse_tracepoint_definition (p
, utpp
);
11825 /* Ask for another packet of tracepoint definition. */
11827 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11834 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
11836 struct remote_state
*rs
= get_remote_state ();
11839 /* Ask for a first packet of variable definition. */
11841 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11843 while (*p
&& *p
!= 'l')
11845 parse_tsv_definition (p
, utsvp
);
11846 /* Ask for another packet of variable definition. */
11848 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11854 /* The "set/show range-stepping" show hook. */
11857 show_range_stepping (struct ui_file
*file
, int from_tty
,
11858 struct cmd_list_element
*c
,
11861 fprintf_filtered (file
,
11862 _("Debugger's willingness to use range stepping "
11863 "is %s.\n"), value
);
11866 /* The "set/show range-stepping" set hook. */
11869 set_range_stepping (char *ignore_args
, int from_tty
,
11870 struct cmd_list_element
*c
)
11872 struct remote_state
*rs
= get_remote_state ();
11874 /* Whene enabling, check whether range stepping is actually
11875 supported by the target, and warn if not. */
11876 if (use_range_stepping
)
11878 if (rs
->remote_desc
!= NULL
)
11880 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
11881 remote_vcont_probe (rs
);
11883 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_ENABLE
11884 && rs
->supports_vCont
.r
)
11888 warning (_("Range stepping is not supported by the current target"));
11893 _initialize_remote (void)
11895 struct remote_state
*rs
;
11896 struct cmd_list_element
*cmd
;
11897 const char *cmd_name
;
11899 /* architecture specific data */
11900 remote_gdbarch_data_handle
=
11901 gdbarch_data_register_post_init (init_remote_state
);
11902 remote_g_packet_data_handle
=
11903 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
11905 /* Initialize the per-target state. At the moment there is only one
11906 of these, not one per target. Only one target is active at a
11908 remote_state
= new_remote_state ();
11910 init_remote_ops ();
11911 add_target (&remote_ops
);
11913 init_extended_remote_ops ();
11914 add_target (&extended_remote_ops
);
11916 /* Hook into new objfile notification. */
11917 observer_attach_new_objfile (remote_new_objfile
);
11918 /* We're no longer interested in notification events of an inferior
11920 observer_attach_inferior_exit (discard_pending_stop_replies
);
11922 /* Set up signal handlers. */
11923 async_sigint_remote_token
=
11924 create_async_signal_handler (async_remote_interrupt
, NULL
);
11925 async_sigint_remote_twice_token
=
11926 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11929 init_remote_threadtests ();
11932 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
11933 /* set/show remote ... */
11935 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11936 Remote protocol specific variables\n\
11937 Configure various remote-protocol specific variables such as\n\
11938 the packets being used"),
11939 &remote_set_cmdlist
, "set remote ",
11940 0 /* allow-unknown */, &setlist
);
11941 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11942 Remote protocol specific variables\n\
11943 Configure various remote-protocol specific variables such as\n\
11944 the packets being used"),
11945 &remote_show_cmdlist
, "show remote ",
11946 0 /* allow-unknown */, &showlist
);
11948 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11949 Compare section data on target to the exec file.\n\
11950 Argument is a single section name (default: all loaded sections)."),
11953 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11954 Send an arbitrary packet to a remote target.\n\
11955 maintenance packet TEXT\n\
11956 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11957 this command sends the string TEXT to the inferior, and displays the\n\
11958 response packet. GDB supplies the initial `$' character, and the\n\
11959 terminating `#' character and checksum."),
11962 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11963 Set whether to send break if interrupted."), _("\
11964 Show whether to send break if interrupted."), _("\
11965 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11966 set_remotebreak
, show_remotebreak
,
11967 &setlist
, &showlist
);
11968 cmd_name
= "remotebreak";
11969 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11970 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11971 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11972 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11973 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11975 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11976 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11978 Set interrupt sequence to remote target."), _("\
11979 Show interrupt sequence to remote target."), _("\
11980 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11981 NULL
, show_interrupt_sequence
,
11982 &remote_set_cmdlist
,
11983 &remote_show_cmdlist
);
11985 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11986 &interrupt_on_connect
, _("\
11987 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11988 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11989 If set, interrupt sequence is sent to remote target."),
11991 &remote_set_cmdlist
, &remote_show_cmdlist
);
11993 /* Install commands for configuring memory read/write packets. */
11995 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11996 Set the maximum number of bytes per memory write packet (deprecated)."),
11998 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11999 Show the maximum number of bytes per memory write packet (deprecated)."),
12001 add_cmd ("memory-write-packet-size", no_class
,
12002 set_memory_write_packet_size
, _("\
12003 Set the maximum number of bytes per memory-write packet.\n\
12004 Specify the number of bytes in a packet or 0 (zero) for the\n\
12005 default packet size. The actual limit is further reduced\n\
12006 dependent on the target. Specify ``fixed'' to disable the\n\
12007 further restriction and ``limit'' to enable that restriction."),
12008 &remote_set_cmdlist
);
12009 add_cmd ("memory-read-packet-size", no_class
,
12010 set_memory_read_packet_size
, _("\
12011 Set the maximum number of bytes per memory-read packet.\n\
12012 Specify the number of bytes in a packet or 0 (zero) for the\n\
12013 default packet size. The actual limit is further reduced\n\
12014 dependent on the target. Specify ``fixed'' to disable the\n\
12015 further restriction and ``limit'' to enable that restriction."),
12016 &remote_set_cmdlist
);
12017 add_cmd ("memory-write-packet-size", no_class
,
12018 show_memory_write_packet_size
,
12019 _("Show the maximum number of bytes per memory-write packet."),
12020 &remote_show_cmdlist
);
12021 add_cmd ("memory-read-packet-size", no_class
,
12022 show_memory_read_packet_size
,
12023 _("Show the maximum number of bytes per memory-read packet."),
12024 &remote_show_cmdlist
);
12026 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
12027 &remote_hw_watchpoint_limit
, _("\
12028 Set the maximum number of target hardware watchpoints."), _("\
12029 Show the maximum number of target hardware watchpoints."), _("\
12030 Specify a negative limit for unlimited."),
12031 NULL
, NULL
, /* FIXME: i18n: The maximum
12032 number of target hardware
12033 watchpoints is %s. */
12034 &remote_set_cmdlist
, &remote_show_cmdlist
);
12035 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
12036 &remote_hw_watchpoint_length_limit
, _("\
12037 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
12038 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
12039 Specify a negative limit for unlimited."),
12040 NULL
, NULL
, /* FIXME: i18n: The maximum
12041 length (in bytes) of a target
12042 hardware watchpoint is %s. */
12043 &remote_set_cmdlist
, &remote_show_cmdlist
);
12044 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
12045 &remote_hw_breakpoint_limit
, _("\
12046 Set the maximum number of target hardware breakpoints."), _("\
12047 Show the maximum number of target hardware breakpoints."), _("\
12048 Specify a negative limit for unlimited."),
12049 NULL
, NULL
, /* FIXME: i18n: The maximum
12050 number of target hardware
12051 breakpoints is %s. */
12052 &remote_set_cmdlist
, &remote_show_cmdlist
);
12054 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
12055 &remote_address_size
, _("\
12056 Set the maximum size of the address (in bits) in a memory packet."), _("\
12057 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
12059 NULL
, /* FIXME: i18n: */
12060 &setlist
, &showlist
);
12062 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
12063 "X", "binary-download", 1);
12065 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
12066 "vCont", "verbose-resume", 0);
12068 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
12069 "QPassSignals", "pass-signals", 0);
12071 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
12072 "QProgramSignals", "program-signals", 0);
12074 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
12075 "qSymbol", "symbol-lookup", 0);
12077 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
12078 "P", "set-register", 1);
12080 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
12081 "p", "fetch-register", 1);
12083 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
12084 "Z0", "software-breakpoint", 0);
12086 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
12087 "Z1", "hardware-breakpoint", 0);
12089 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
12090 "Z2", "write-watchpoint", 0);
12092 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
12093 "Z3", "read-watchpoint", 0);
12095 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
12096 "Z4", "access-watchpoint", 0);
12098 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
12099 "qXfer:auxv:read", "read-aux-vector", 0);
12101 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
12102 "qXfer:features:read", "target-features", 0);
12104 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
12105 "qXfer:libraries:read", "library-info", 0);
12107 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
12108 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
12110 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
12111 "qXfer:memory-map:read", "memory-map", 0);
12113 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
12114 "qXfer:spu:read", "read-spu-object", 0);
12116 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
12117 "qXfer:spu:write", "write-spu-object", 0);
12119 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
12120 "qXfer:osdata:read", "osdata", 0);
12122 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
12123 "qXfer:threads:read", "threads", 0);
12125 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
12126 "qXfer:siginfo:read", "read-siginfo-object", 0);
12128 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
12129 "qXfer:siginfo:write", "write-siginfo-object", 0);
12131 add_packet_config_cmd
12132 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
12133 "qXfer:traceframe-info:read", "traceframe-info", 0);
12135 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
12136 "qXfer:uib:read", "unwind-info-block", 0);
12138 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
12139 "qGetTLSAddr", "get-thread-local-storage-address",
12142 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
12143 "qGetTIBAddr", "get-thread-information-block-address",
12146 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
12147 "bc", "reverse-continue", 0);
12149 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
12150 "bs", "reverse-step", 0);
12152 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
12153 "qSupported", "supported-packets", 0);
12155 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
12156 "qSearch:memory", "search-memory", 0);
12158 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
12159 "qTStatus", "trace-status", 0);
12161 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
12162 "vFile:open", "hostio-open", 0);
12164 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
12165 "vFile:pread", "hostio-pread", 0);
12167 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
12168 "vFile:pwrite", "hostio-pwrite", 0);
12170 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
12171 "vFile:close", "hostio-close", 0);
12173 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
12174 "vFile:unlink", "hostio-unlink", 0);
12176 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
12177 "vFile:readlink", "hostio-readlink", 0);
12179 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
12180 "vAttach", "attach", 0);
12182 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
12185 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
12186 "QStartNoAckMode", "noack", 0);
12188 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
12189 "vKill", "kill", 0);
12191 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
12192 "qAttached", "query-attached", 0);
12194 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
12195 "ConditionalTracepoints",
12196 "conditional-tracepoints", 0);
12198 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
12199 "ConditionalBreakpoints",
12200 "conditional-breakpoints", 0);
12202 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
12203 "BreakpointCommands",
12204 "breakpoint-commands", 0);
12206 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
12207 "FastTracepoints", "fast-tracepoints", 0);
12209 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
12210 "TracepointSource", "TracepointSource", 0);
12212 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
12213 "QAllow", "allow", 0);
12215 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
12216 "StaticTracepoints", "static-tracepoints", 0);
12218 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
12219 "InstallInTrace", "install-in-trace", 0);
12221 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
12222 "qXfer:statictrace:read", "read-sdata-object", 0);
12224 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
12225 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12227 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
12228 "QDisableRandomization", "disable-randomization", 0);
12230 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
12231 "QAgent", "agent", 0);
12233 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
12234 "QTBuffer:size", "trace-buffer-size", 0);
12236 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
12237 "Qbtrace:off", "disable-btrace", 0);
12239 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12240 "Qbtrace:bts", "enable-btrace", 0);
12242 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12243 "qXfer:btrace", "read-btrace", 0);
12245 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12246 Z sub-packet has its own set and show commands, but users may
12247 have sets to this variable in their .gdbinit files (or in their
12249 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
12250 &remote_Z_packet_detect
, _("\
12251 Set use of remote protocol `Z' packets"), _("\
12252 Show use of remote protocol `Z' packets "), _("\
12253 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12255 set_remote_protocol_Z_packet_cmd
,
12256 show_remote_protocol_Z_packet_cmd
,
12257 /* FIXME: i18n: Use of remote protocol
12258 `Z' packets is %s. */
12259 &remote_set_cmdlist
, &remote_show_cmdlist
);
12261 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
12262 Manipulate files on the remote system\n\
12263 Transfer files to and from the remote target system."),
12264 &remote_cmdlist
, "remote ",
12265 0 /* allow-unknown */, &cmdlist
);
12267 add_cmd ("put", class_files
, remote_put_command
,
12268 _("Copy a local file to the remote system."),
12271 add_cmd ("get", class_files
, remote_get_command
,
12272 _("Copy a remote file to the local system."),
12275 add_cmd ("delete", class_files
, remote_delete_command
,
12276 _("Delete a remote file."),
12279 remote_exec_file
= xstrdup ("");
12280 add_setshow_string_noescape_cmd ("exec-file", class_files
,
12281 &remote_exec_file
, _("\
12282 Set the remote pathname for \"run\""), _("\
12283 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
12284 &remote_set_cmdlist
, &remote_show_cmdlist
);
12286 add_setshow_boolean_cmd ("range-stepping", class_run
,
12287 &use_range_stepping
, _("\
12288 Enable or disable range stepping."), _("\
12289 Show whether target-assisted range stepping is enabled."), _("\
12290 If on, and the target supports it, when stepping a source line, GDB\n\
12291 tells the target to step the corresponding range of addresses itself instead\n\
12292 of issuing multiple single-steps. This speeds up source level\n\
12293 stepping. If off, GDB always issues single-steps, even if range\n\
12294 stepping is supported by the target. The default is on."),
12295 set_range_stepping
,
12296 show_range_stepping
,
12300 /* Eventually initialize fileio. See fileio.c */
12301 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
12303 /* Take advantage of the fact that the LWP field is not used, to tag
12304 special ptids with it set to != 0. */
12305 magic_null_ptid
= ptid_build (42000, 1, -1);
12306 not_sent_ptid
= ptid_build (42000, 1, -2);
12307 any_thread_ptid
= ptid_build (42000, 1, 0);
12309 target_buf_size
= 2048;
12310 target_buf
= xmalloc (target_buf_size
);