1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 /* See the GDB User Guide for details of the GDB remote protocol. */
27 #include "gdb_string.h"
33 #include "exceptions.h"
35 /*#include "terminal.h" */
38 #include "gdb-stabs.h"
39 #include "gdbthread.h"
43 #include "gdb_assert.h"
49 #include "event-loop.h"
50 #include "event-top.h"
56 #include "gdbcore.h" /* for exec_bfd */
58 #include "remote-fileio.h"
60 /* Prototypes for local functions. */
61 static void cleanup_sigint_signal_handler (void *dummy
);
62 static void initialize_sigint_signal_handler (void);
63 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
65 static void handle_remote_sigint (int);
66 static void handle_remote_sigint_twice (int);
67 static void async_remote_interrupt (gdb_client_data
);
68 void async_remote_interrupt_twice (gdb_client_data
);
70 static void build_remote_gdbarch_data (void);
72 static void remote_files_info (struct target_ops
*ignore
);
74 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
75 int len
, int should_write
,
76 struct mem_attrib
*attrib
,
77 struct target_ops
*target
);
79 static void remote_prepare_to_store (void);
81 static void remote_fetch_registers (int regno
);
83 static void remote_resume (ptid_t ptid
, int step
,
84 enum target_signal siggnal
);
85 static void remote_async_resume (ptid_t ptid
, int step
,
86 enum target_signal siggnal
);
87 static void remote_open (char *name
, int from_tty
);
88 static void remote_async_open (char *name
, int from_tty
);
90 static void extended_remote_open (char *name
, int from_tty
);
91 static void extended_remote_async_open (char *name
, int from_tty
);
93 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
96 static void remote_close (int quitting
);
98 static void remote_store_registers (int regno
);
100 static void remote_mourn (void);
101 static void remote_async_mourn (void);
103 static void extended_remote_restart (void);
105 static void extended_remote_mourn (void);
107 static void remote_mourn_1 (struct target_ops
*);
109 static void remote_send (char *buf
, long sizeof_buf
);
111 static int readchar (int timeout
);
113 static ptid_t
remote_wait (ptid_t ptid
,
114 struct target_waitstatus
*status
);
115 static ptid_t
remote_async_wait (ptid_t ptid
,
116 struct target_waitstatus
*status
);
118 static void remote_kill (void);
119 static void remote_async_kill (void);
121 static int tohex (int nib
);
123 static void remote_detach (char *args
, int from_tty
);
125 static void remote_interrupt (int signo
);
127 static void remote_interrupt_twice (int signo
);
129 static void interrupt_query (void);
131 static void set_thread (int, int);
133 static int remote_thread_alive (ptid_t
);
135 static void get_offsets (void);
137 static long read_frame (char *buf
, long sizeof_buf
);
139 static int remote_insert_breakpoint (CORE_ADDR
, char *);
141 static int remote_remove_breakpoint (CORE_ADDR
, char *);
143 static int hexnumlen (ULONGEST num
);
145 static void init_remote_ops (void);
147 static void init_extended_remote_ops (void);
149 static void remote_stop (void);
151 static int ishex (int ch
, int *val
);
153 static int stubhex (int ch
);
155 static int hexnumstr (char *, ULONGEST
);
157 static int hexnumnstr (char *, ULONGEST
, int);
159 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
161 static void print_packet (char *);
163 static unsigned long crc32 (unsigned char *, int, unsigned int);
165 static void compare_sections_command (char *, int);
167 static void packet_command (char *, int);
169 static int stub_unpack_int (char *buff
, int fieldlength
);
171 static ptid_t
remote_current_thread (ptid_t oldptid
);
173 static void remote_find_new_threads (void);
175 static void record_currthread (int currthread
);
177 static int fromhex (int a
);
179 static int hex2bin (const char *hex
, char *bin
, int count
);
181 static int bin2hex (const char *bin
, char *hex
, int count
);
183 static int putpkt_binary (char *buf
, int cnt
);
185 static void check_binary_download (CORE_ADDR addr
);
187 struct packet_config
;
189 static void show_packet_config_cmd (struct packet_config
*config
);
191 static void update_packet_config (struct packet_config
*config
);
193 void _initialize_remote (void);
195 /* Description of the remote protocol. Strictly speaking, when the
196 target is open()ed, remote.c should create a per-target description
197 of the remote protocol using that target's architecture.
198 Unfortunately, the target stack doesn't include local state. For
199 the moment keep the information in the target's architecture
204 long offset
; /* Offset into G packet. */
205 long regnum
; /* GDB's internal register number. */
206 LONGEST pnum
; /* Remote protocol register number. */
207 int in_g_packet
; /* Always part of G packet. */
208 /* long size in bytes; == register_size (current_gdbarch, regnum);
210 /* char *name; == REGISTER_NAME (regnum); at present. */
215 /* Description of the remote protocol registers. */
216 long sizeof_g_packet
;
218 /* Description of the remote protocol registers indexed by REGNUM
219 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
220 struct packet_reg
*regs
;
222 /* This is the size (in chars) of the first response to the ``g''
223 packet. It is used as a heuristic when determining the maximum
224 size of memory-read and memory-write packets. A target will
225 typically only reserve a buffer large enough to hold the ``g''
226 packet. The size does not include packet overhead (headers and
228 long actual_register_packet_size
;
230 /* This is the maximum size (in chars) of a non read/write packet.
231 It is also used as a cap on the size of read/write packets. */
232 long remote_packet_size
;
236 /* Handle for retreving the remote protocol data from gdbarch. */
237 static struct gdbarch_data
*remote_gdbarch_data_handle
;
239 static struct remote_state
*
240 get_remote_state (void)
242 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
246 init_remote_state (struct gdbarch
*gdbarch
)
249 struct remote_state
*rs
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_state
);
251 if (deprecated_register_bytes () != 0)
252 rs
->sizeof_g_packet
= deprecated_register_bytes ();
254 rs
->sizeof_g_packet
= 0;
256 /* Assume a 1:1 regnum<->pnum table. */
257 rs
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
, NUM_REGS
+ NUM_PSEUDO_REGS
,
259 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
261 struct packet_reg
*r
= &rs
->regs
[regnum
];
264 r
->offset
= DEPRECATED_REGISTER_BYTE (regnum
);
265 r
->in_g_packet
= (regnum
< NUM_REGS
);
266 /* ...name = REGISTER_NAME (regnum); */
268 /* Compute packet size by accumulating the size of all registers. */
269 if (deprecated_register_bytes () == 0)
270 rs
->sizeof_g_packet
+= register_size (current_gdbarch
, regnum
);
273 /* Default maximum number of characters in a packet body. Many
274 remote stubs have a hardwired buffer size of 400 bytes
275 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
276 as the maximum packet-size to ensure that the packet and an extra
277 NUL character can always fit in the buffer. This stops GDB
278 trashing stubs that try to squeeze an extra NUL into what is
279 already a full buffer (As of 1999-12-04 that was most stubs. */
280 rs
->remote_packet_size
= 400 - 1;
282 /* Should rs->sizeof_g_packet needs more space than the
283 default, adjust the size accordingly. Remember that each byte is
284 encoded as two characters. 32 is the overhead for the packet
285 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
286 (``$NN:G...#NN'') is a better guess, the below has been padded a
288 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
289 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
291 /* This one is filled in when a ``g'' packet is received. */
292 rs
->actual_register_packet_size
= 0;
297 static struct packet_reg
*
298 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
300 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
304 struct packet_reg
*r
= &rs
->regs
[regnum
];
305 gdb_assert (r
->regnum
== regnum
);
310 static struct packet_reg
*
311 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
314 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
316 struct packet_reg
*r
= &rs
->regs
[i
];
323 /* FIXME: graces/2002-08-08: These variables should eventually be
324 bound to an instance of the target object (as in gdbarch-tdep()),
325 when such a thing exists. */
327 /* This is set to the data address of the access causing the target
328 to stop for a watchpoint. */
329 static CORE_ADDR remote_watch_data_address
;
331 /* This is non-zero if taregt stopped for a watchpoint. */
332 static int remote_stopped_by_watchpoint_p
;
335 static struct target_ops remote_ops
;
337 static struct target_ops extended_remote_ops
;
339 /* Temporary target ops. Just like the remote_ops and
340 extended_remote_ops, but with asynchronous support. */
341 static struct target_ops remote_async_ops
;
343 static struct target_ops extended_async_remote_ops
;
345 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
346 ``forever'' still use the normal timeout mechanism. This is
347 currently used by the ASYNC code to guarentee that target reads
348 during the initial connect always time-out. Once getpkt has been
349 modified to return a timeout indication and, in turn
350 remote_wait()/wait_for_inferior() have gained a timeout parameter
352 static int wait_forever_enabled_p
= 1;
355 /* This variable chooses whether to send a ^C or a break when the user
356 requests program interruption. Although ^C is usually what remote
357 systems expect, and that is the default here, sometimes a break is
358 preferable instead. */
360 static int remote_break
;
362 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
363 remote_open knows that we don't have a file open when the program
365 static struct serial
*remote_desc
= NULL
;
367 /* This variable sets the number of bits in an address that are to be
368 sent in a memory ("M" or "m") packet. Normally, after stripping
369 leading zeros, the entire address would be sent. This variable
370 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
371 initial implementation of remote.c restricted the address sent in
372 memory packets to ``host::sizeof long'' bytes - (typically 32
373 bits). Consequently, for 64 bit targets, the upper 32 bits of an
374 address was never sent. Since fixing this bug may cause a break in
375 some remote targets this variable is principly provided to
376 facilitate backward compatibility. */
378 static int remote_address_size
;
380 /* Tempoary to track who currently owns the terminal. See
381 target_async_terminal_* for more details. */
383 static int remote_async_terminal_ours_p
;
386 /* User configurable variables for the number of characters in a
387 memory read/write packet. MIN ((rs->remote_packet_size),
388 rs->sizeof_g_packet) is the default. Some targets need smaller
389 values (fifo overruns, et.al.) and some users need larger values
390 (speed up transfers). The variables ``preferred_*'' (the user
391 request), ``current_*'' (what was actually set) and ``forced_*''
392 (Positive - a soft limit, negative - a hard limit). */
394 struct memory_packet_config
401 /* Compute the current size of a read/write packet. Since this makes
402 use of ``actual_register_packet_size'' the computation is dynamic. */
405 get_memory_packet_size (struct memory_packet_config
*config
)
407 struct remote_state
*rs
= get_remote_state ();
408 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
409 law?) that some hosts don't cope very well with large alloca()
410 calls. Eventually the alloca() code will be replaced by calls to
411 xmalloc() and make_cleanups() allowing this restriction to either
412 be lifted or removed. */
413 #ifndef MAX_REMOTE_PACKET_SIZE
414 #define MAX_REMOTE_PACKET_SIZE 16384
416 /* NOTE: 16 is just chosen at random. */
417 #ifndef MIN_REMOTE_PACKET_SIZE
418 #define MIN_REMOTE_PACKET_SIZE 16
423 if (config
->size
<= 0)
424 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
426 what_they_get
= config
->size
;
430 what_they_get
= (rs
->remote_packet_size
);
431 /* Limit the packet to the size specified by the user. */
433 && what_they_get
> config
->size
)
434 what_they_get
= config
->size
;
435 /* Limit it to the size of the targets ``g'' response. */
436 if ((rs
->actual_register_packet_size
) > 0
437 && what_they_get
> (rs
->actual_register_packet_size
))
438 what_they_get
= (rs
->actual_register_packet_size
);
440 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
441 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
442 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
443 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
444 return what_they_get
;
447 /* Update the size of a read/write packet. If they user wants
448 something really big then do a sanity check. */
451 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
453 int fixed_p
= config
->fixed_p
;
454 long size
= config
->size
;
456 error (_("Argument required (integer, `fixed' or `limited')."));
457 else if (strcmp (args
, "hard") == 0
458 || strcmp (args
, "fixed") == 0)
460 else if (strcmp (args
, "soft") == 0
461 || strcmp (args
, "limit") == 0)
466 size
= strtoul (args
, &end
, 0);
468 error (_("Invalid %s (bad syntax)."), config
->name
);
470 /* Instead of explicitly capping the size of a packet to
471 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
472 instead allowed to set the size to something arbitrarily
474 if (size
> MAX_REMOTE_PACKET_SIZE
)
475 error (_("Invalid %s (too large)."), config
->name
);
479 if (fixed_p
&& !config
->fixed_p
)
481 if (! query (_("The target may not be able to correctly handle a %s\n"
482 "of %ld bytes. Change the packet size? "),
484 error (_("Packet size not changed."));
486 /* Update the config. */
487 config
->fixed_p
= fixed_p
;
492 show_memory_packet_size (struct memory_packet_config
*config
)
494 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
496 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
497 get_memory_packet_size (config
));
499 printf_filtered (_("Packets are limited to %ld bytes.\n"),
500 get_memory_packet_size (config
));
503 static struct memory_packet_config memory_write_packet_config
=
505 "memory-write-packet-size",
509 set_memory_write_packet_size (char *args
, int from_tty
)
511 set_memory_packet_size (args
, &memory_write_packet_config
);
515 show_memory_write_packet_size (char *args
, int from_tty
)
517 show_memory_packet_size (&memory_write_packet_config
);
521 get_memory_write_packet_size (void)
523 return get_memory_packet_size (&memory_write_packet_config
);
526 static struct memory_packet_config memory_read_packet_config
=
528 "memory-read-packet-size",
532 set_memory_read_packet_size (char *args
, int from_tty
)
534 set_memory_packet_size (args
, &memory_read_packet_config
);
538 show_memory_read_packet_size (char *args
, int from_tty
)
540 show_memory_packet_size (&memory_read_packet_config
);
544 get_memory_read_packet_size (void)
546 struct remote_state
*rs
= get_remote_state ();
547 long size
= get_memory_packet_size (&memory_read_packet_config
);
548 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
549 extra buffer size argument before the memory read size can be
550 increased beyond (rs->remote_packet_size). */
551 if (size
> (rs
->remote_packet_size
))
552 size
= (rs
->remote_packet_size
);
557 /* Generic configuration support for packets the stub optionally
558 supports. Allows the user to specify the use of the packet as well
559 as allowing GDB to auto-detect support in the remote stub. */
563 PACKET_SUPPORT_UNKNOWN
= 0,
572 enum auto_boolean detect
;
573 enum packet_support support
;
576 /* Analyze a packet's return value and update the packet config
587 update_packet_config (struct packet_config
*config
)
589 switch (config
->detect
)
591 case AUTO_BOOLEAN_TRUE
:
592 config
->support
= PACKET_ENABLE
;
594 case AUTO_BOOLEAN_FALSE
:
595 config
->support
= PACKET_DISABLE
;
597 case AUTO_BOOLEAN_AUTO
:
598 config
->support
= PACKET_SUPPORT_UNKNOWN
;
604 show_packet_config_cmd (struct packet_config
*config
)
606 char *support
= "internal-error";
607 switch (config
->support
)
613 support
= "disabled";
615 case PACKET_SUPPORT_UNKNOWN
:
619 switch (config
->detect
)
621 case AUTO_BOOLEAN_AUTO
:
622 printf_filtered (_("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n"),
623 config
->name
, config
->title
, support
);
625 case AUTO_BOOLEAN_TRUE
:
626 case AUTO_BOOLEAN_FALSE
:
627 printf_filtered (_("Support for remote protocol `%s' (%s) packet is currently %s.\n"),
628 config
->name
, config
->title
, support
);
634 add_packet_config_cmd (struct packet_config
*config
,
637 cmd_sfunc_ftype
*set_func
,
638 show_value_ftype
*show_func
,
639 struct cmd_list_element
**set_remote_list
,
640 struct cmd_list_element
**show_remote_list
,
643 struct cmd_list_element
*set_cmd
;
644 struct cmd_list_element
*show_cmd
;
651 config
->title
= title
;
652 config
->detect
= AUTO_BOOLEAN_AUTO
;
653 config
->support
= PACKET_SUPPORT_UNKNOWN
;
654 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
656 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
658 print
= xstrprintf ("Current use of remote protocol `%s' (%s) is %%s",
660 /* set/show TITLE-packet {auto,on,off} */
661 cmd_name
= xstrprintf ("%s-packet", title
);
662 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
663 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
665 set_remote_list
, show_remote_list
);
666 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
670 legacy_name
= xstrprintf ("%s-packet", name
);
671 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
673 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
678 static enum packet_result
679 packet_ok (const char *buf
, struct packet_config
*config
)
683 /* The stub recognized the packet request. Check that the
684 operation succeeded. */
685 switch (config
->support
)
687 case PACKET_SUPPORT_UNKNOWN
:
689 fprintf_unfiltered (gdb_stdlog
,
690 "Packet %s (%s) is supported\n",
691 config
->name
, config
->title
);
692 config
->support
= PACKET_ENABLE
;
695 internal_error (__FILE__
, __LINE__
,
696 _("packet_ok: attempt to use a disabled packet"));
701 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
702 /* "OK" - definitly OK. */
705 && isxdigit (buf
[1]) && isxdigit (buf
[2])
707 /* "Enn" - definitly an error. */
709 /* The packet may or may not be OK. Just assume it is. */
714 /* The stub does not support the packet. */
715 switch (config
->support
)
718 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
719 /* If the stub previously indicated that the packet was
720 supported then there is a protocol error.. */
721 error (_("Protocol error: %s (%s) conflicting enabled responses."),
722 config
->name
, config
->title
);
724 /* The user set it wrong. */
725 error (_("Enabled packet %s (%s) not recognized by stub"),
726 config
->name
, config
->title
);
728 case PACKET_SUPPORT_UNKNOWN
:
730 fprintf_unfiltered (gdb_stdlog
,
731 "Packet %s (%s) is NOT supported\n",
732 config
->name
, config
->title
);
733 config
->support
= PACKET_DISABLE
;
738 return PACKET_UNKNOWN
;
742 /* Should we try the 'vCont' (descriptive resume) request? */
743 static struct packet_config remote_protocol_vcont
;
746 set_remote_protocol_vcont_packet_cmd (char *args
, int from_tty
,
747 struct cmd_list_element
*c
)
749 update_packet_config (&remote_protocol_vcont
);
753 show_remote_protocol_vcont_packet_cmd (struct ui_file
*file
, int from_tty
,
754 struct cmd_list_element
*c
,
757 deprecated_show_value_hack (file
, from_tty
, c
, value
);
758 show_packet_config_cmd (&remote_protocol_vcont
);
761 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
762 static struct packet_config remote_protocol_qSymbol
;
765 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
766 struct cmd_list_element
*c
)
768 update_packet_config (&remote_protocol_qSymbol
);
772 show_remote_protocol_qSymbol_packet_cmd (struct ui_file
*file
, int from_tty
,
773 struct cmd_list_element
*c
,
776 deprecated_show_value_hack (file
, from_tty
, c
, value
);
777 show_packet_config_cmd (&remote_protocol_qSymbol
);
780 /* Should we try the 'P' (set register) request? */
782 static struct packet_config remote_protocol_P
;
785 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
786 struct cmd_list_element
*c
)
788 update_packet_config (&remote_protocol_P
);
792 show_remote_protocol_P_packet_cmd (struct ui_file
*file
, int from_tty
,
793 struct cmd_list_element
*c
,
796 deprecated_show_value_hack (file
, from_tty
, c
, value
);
797 show_packet_config_cmd (&remote_protocol_P
);
800 /* Should we try one of the 'Z' requests? */
804 Z_PACKET_SOFTWARE_BP
,
805 Z_PACKET_HARDWARE_BP
,
812 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
814 /* FIXME: Instead of having all these boiler plate functions, the
815 command callback should include a context argument. */
818 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
819 struct cmd_list_element
*c
)
821 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
825 show_remote_protocol_Z_software_bp_packet_cmd (struct ui_file
*file
, int from_tty
,
826 struct cmd_list_element
*c
,
829 deprecated_show_value_hack (file
, from_tty
, c
, value
);
830 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
834 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
835 struct cmd_list_element
*c
)
837 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
841 show_remote_protocol_Z_hardware_bp_packet_cmd (struct ui_file
*file
, int from_tty
,
842 struct cmd_list_element
*c
,
845 deprecated_show_value_hack (file
, from_tty
, c
, value
);
846 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
850 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
851 struct cmd_list_element
*c
)
853 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
857 show_remote_protocol_Z_write_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
858 struct cmd_list_element
*c
,
861 deprecated_show_value_hack (file
, from_tty
, c
, value
);
862 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
866 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
867 struct cmd_list_element
*c
)
869 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
873 show_remote_protocol_Z_read_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
874 struct cmd_list_element
*c
,
877 deprecated_show_value_hack (file
, from_tty
, c
, value
);
878 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
882 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
883 struct cmd_list_element
*c
)
885 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
889 show_remote_protocol_Z_access_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
890 struct cmd_list_element
*c
,
893 deprecated_show_value_hack (file
, from_tty
, c
, value
);
894 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
897 /* For compatibility with older distributions. Provide a ``set remote
898 Z-packet ...'' command that updates all the Z packet types. */
900 static enum auto_boolean remote_Z_packet_detect
;
903 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
904 struct cmd_list_element
*c
)
907 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
909 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
910 update_packet_config (&remote_protocol_Z
[i
]);
915 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
916 struct cmd_list_element
*c
,
920 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
922 show_packet_config_cmd (&remote_protocol_Z
[i
]);
926 /* Should we try the 'X' (remote binary download) packet?
928 This variable (available to the user via "set remote X-packet")
929 dictates whether downloads are sent in binary (via the 'X' packet).
930 We assume that the stub can, and attempt to do it. This will be
931 cleared if the stub does not understand it. This switch is still
932 needed, though in cases when the packet is supported in the stub,
933 but the connection does not allow it (i.e., 7-bit serial connection
936 static struct packet_config remote_protocol_binary_download
;
938 /* Should we try the 'ThreadInfo' query packet?
940 This variable (NOT available to the user: auto-detect only!)
941 determines whether GDB will use the new, simpler "ThreadInfo"
942 query or the older, more complex syntax for thread queries.
943 This is an auto-detect variable (set to true at each connect,
944 and set to false when the target fails to recognize it). */
946 static int use_threadinfo_query
;
947 static int use_threadextra_query
;
950 set_remote_protocol_binary_download_cmd (char *args
,
952 struct cmd_list_element
*c
)
954 update_packet_config (&remote_protocol_binary_download
);
958 show_remote_protocol_binary_download_cmd (struct ui_file
*file
, int from_tty
,
959 struct cmd_list_element
*c
,
962 deprecated_show_value_hack (file
, from_tty
, c
, value
);
963 show_packet_config_cmd (&remote_protocol_binary_download
);
966 /* Should we try the 'qPart:auxv' (target auxiliary vector read) request? */
967 static struct packet_config remote_protocol_qPart_auxv
;
970 set_remote_protocol_qPart_auxv_packet_cmd (char *args
, int from_tty
,
971 struct cmd_list_element
*c
)
973 update_packet_config (&remote_protocol_qPart_auxv
);
977 show_remote_protocol_qPart_auxv_packet_cmd (struct ui_file
*file
, int from_tty
,
978 struct cmd_list_element
*c
,
981 deprecated_show_value_hack (file
, from_tty
, c
, value
);
982 show_packet_config_cmd (&remote_protocol_qPart_auxv
);
985 static struct packet_config remote_protocol_p
;
988 set_remote_protocol_p_packet_cmd (char *args
, int from_tty
,
989 struct cmd_list_element
*c
)
991 update_packet_config (&remote_protocol_p
);
995 show_remote_protocol_p_packet_cmd (struct ui_file
*file
, int from_tty
,
996 struct cmd_list_element
*c
,
999 deprecated_show_value_hack (file
, from_tty
, c
, value
);
1000 show_packet_config_cmd (&remote_protocol_p
);
1005 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1006 static void *sigint_remote_twice_token
;
1007 static void *sigint_remote_token
;
1009 /* These are pointers to hook functions that may be set in order to
1010 modify resume/wait behavior for a particular architecture. */
1012 void (*deprecated_target_resume_hook
) (void);
1013 void (*deprecated_target_wait_loop_hook
) (void);
1017 /* These are the threads which we last sent to the remote system.
1018 -1 for all or -2 for not sent yet. */
1019 static int general_thread
;
1020 static int continue_thread
;
1022 /* Call this function as a result of
1023 1) A halt indication (T packet) containing a thread id
1024 2) A direct query of currthread
1025 3) Successful execution of set thread
1029 record_currthread (int currthread
)
1031 general_thread
= currthread
;
1033 /* If this is a new thread, add it to GDB's thread list.
1034 If we leave it up to WFI to do this, bad things will happen. */
1035 if (!in_thread_list (pid_to_ptid (currthread
)))
1037 add_thread (pid_to_ptid (currthread
));
1038 ui_out_text (uiout
, "[New ");
1039 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1040 ui_out_text (uiout
, "]\n");
1044 #define MAGIC_NULL_PID 42000
1047 set_thread (int th
, int gen
)
1049 struct remote_state
*rs
= get_remote_state ();
1050 char *buf
= alloca (rs
->remote_packet_size
);
1051 int state
= gen
? general_thread
: continue_thread
;
1057 buf
[1] = gen
? 'g' : 'c';
1058 if (th
== MAGIC_NULL_PID
)
1064 sprintf (&buf
[2], "-%x", -th
);
1066 sprintf (&buf
[2], "%x", th
);
1068 getpkt (buf
, (rs
->remote_packet_size
), 0);
1070 general_thread
= th
;
1072 continue_thread
= th
;
1075 /* Return nonzero if the thread TH is still alive on the remote system. */
1078 remote_thread_alive (ptid_t ptid
)
1080 int tid
= PIDGET (ptid
);
1084 sprintf (buf
, "T-%08x", -tid
);
1086 sprintf (buf
, "T%08x", tid
);
1088 getpkt (buf
, sizeof (buf
), 0);
1089 return (buf
[0] == 'O' && buf
[1] == 'K');
1092 /* About these extended threadlist and threadinfo packets. They are
1093 variable length packets but, the fields within them are often fixed
1094 length. They are redundent enough to send over UDP as is the
1095 remote protocol in general. There is a matching unit test module
1098 #define OPAQUETHREADBYTES 8
1100 /* a 64 bit opaque identifier */
1101 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1103 /* WARNING: This threadref data structure comes from the remote O.S.,
1104 libstub protocol encoding, and remote.c. it is not particularly
1107 /* Right now, the internal structure is int. We want it to be bigger.
1111 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1113 /* gdb_ext_thread_info is an internal GDB data structure which is
1114 equivalint to the reply of the remote threadinfo packet. */
1116 struct gdb_ext_thread_info
1118 threadref threadid
; /* External form of thread reference. */
1119 int active
; /* Has state interesting to GDB?
1121 char display
[256]; /* Brief state display, name,
1122 blocked/syspended. */
1123 char shortname
[32]; /* To be used to name threads. */
1124 char more_display
[256]; /* Long info, statistics, queue depth,
1128 /* The volume of remote transfers can be limited by submitting
1129 a mask containing bits specifying the desired information.
1130 Use a union of these values as the 'selection' parameter to
1131 get_thread_info. FIXME: Make these TAG names more thread specific.
1134 #define TAG_THREADID 1
1135 #define TAG_EXISTS 2
1136 #define TAG_DISPLAY 4
1137 #define TAG_THREADNAME 8
1138 #define TAG_MOREDISPLAY 16
1140 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1142 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1144 static char *unpack_nibble (char *buf
, int *val
);
1146 static char *pack_nibble (char *buf
, int nibble
);
1148 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1150 static char *unpack_byte (char *buf
, int *value
);
1152 static char *pack_int (char *buf
, int value
);
1154 static char *unpack_int (char *buf
, int *value
);
1156 static char *unpack_string (char *src
, char *dest
, int length
);
1158 static char *pack_threadid (char *pkt
, threadref
*id
);
1160 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1162 void int_to_threadref (threadref
*id
, int value
);
1164 static int threadref_to_int (threadref
*ref
);
1166 static void copy_threadref (threadref
*dest
, threadref
*src
);
1168 static int threadmatch (threadref
*dest
, threadref
*src
);
1170 static char *pack_threadinfo_request (char *pkt
, int mode
,
1173 static int remote_unpack_thread_info_response (char *pkt
,
1174 threadref
*expectedref
,
1175 struct gdb_ext_thread_info
1179 static int remote_get_threadinfo (threadref
*threadid
,
1180 int fieldset
, /*TAG mask */
1181 struct gdb_ext_thread_info
*info
);
1183 static char *pack_threadlist_request (char *pkt
, int startflag
,
1185 threadref
*nextthread
);
1187 static int parse_threadlist_response (char *pkt
,
1189 threadref
*original_echo
,
1190 threadref
*resultlist
,
1193 static int remote_get_threadlist (int startflag
,
1194 threadref
*nextthread
,
1198 threadref
*threadlist
);
1200 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1202 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1203 void *context
, int looplimit
);
1205 static int remote_newthread_step (threadref
*ref
, void *context
);
1207 /* Encode 64 bits in 16 chars of hex. */
1209 static const char hexchars
[] = "0123456789abcdef";
1212 ishex (int ch
, int *val
)
1214 if ((ch
>= 'a') && (ch
<= 'f'))
1216 *val
= ch
- 'a' + 10;
1219 if ((ch
>= 'A') && (ch
<= 'F'))
1221 *val
= ch
- 'A' + 10;
1224 if ((ch
>= '0') && (ch
<= '9'))
1235 if (ch
>= 'a' && ch
<= 'f')
1236 return ch
- 'a' + 10;
1237 if (ch
>= '0' && ch
<= '9')
1239 if (ch
>= 'A' && ch
<= 'F')
1240 return ch
- 'A' + 10;
1245 stub_unpack_int (char *buff
, int fieldlength
)
1252 nibble
= stubhex (*buff
++);
1256 retval
= retval
<< 4;
1262 unpack_varlen_hex (char *buff
, /* packet to parse */
1268 while (ishex (*buff
, &nibble
))
1271 retval
= retval
<< 4;
1272 retval
|= nibble
& 0x0f;
1279 unpack_nibble (char *buf
, int *val
)
1281 ishex (*buf
++, val
);
1286 pack_nibble (char *buf
, int nibble
)
1288 *buf
++ = hexchars
[(nibble
& 0x0f)];
1293 pack_hex_byte (char *pkt
, int byte
)
1295 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1296 *pkt
++ = hexchars
[(byte
& 0xf)];
1301 unpack_byte (char *buf
, int *value
)
1303 *value
= stub_unpack_int (buf
, 2);
1308 pack_int (char *buf
, int value
)
1310 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1311 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1312 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1313 buf
= pack_hex_byte (buf
, (value
& 0xff));
1318 unpack_int (char *buf
, int *value
)
1320 *value
= stub_unpack_int (buf
, 8);
1324 #if 0 /* Currently unused, uncomment when needed. */
1325 static char *pack_string (char *pkt
, char *string
);
1328 pack_string (char *pkt
, char *string
)
1333 len
= strlen (string
);
1335 len
= 200; /* Bigger than most GDB packets, junk??? */
1336 pkt
= pack_hex_byte (pkt
, len
);
1340 if ((ch
== '\0') || (ch
== '#'))
1341 ch
= '*'; /* Protect encapsulation. */
1346 #endif /* 0 (unused) */
1349 unpack_string (char *src
, char *dest
, int length
)
1358 pack_threadid (char *pkt
, threadref
*id
)
1361 unsigned char *altid
;
1363 altid
= (unsigned char *) id
;
1364 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1366 pkt
= pack_hex_byte (pkt
, *altid
++);
1372 unpack_threadid (char *inbuf
, threadref
*id
)
1375 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1378 altref
= (char *) id
;
1380 while (inbuf
< limit
)
1382 x
= stubhex (*inbuf
++);
1383 y
= stubhex (*inbuf
++);
1384 *altref
++ = (x
<< 4) | y
;
1389 /* Externally, threadrefs are 64 bits but internally, they are still
1390 ints. This is due to a mismatch of specifications. We would like
1391 to use 64bit thread references internally. This is an adapter
1395 int_to_threadref (threadref
*id
, int value
)
1397 unsigned char *scan
;
1399 scan
= (unsigned char *) id
;
1405 *scan
++ = (value
>> 24) & 0xff;
1406 *scan
++ = (value
>> 16) & 0xff;
1407 *scan
++ = (value
>> 8) & 0xff;
1408 *scan
++ = (value
& 0xff);
1412 threadref_to_int (threadref
*ref
)
1415 unsigned char *scan
;
1417 scan
= (char *) ref
;
1421 value
= (value
<< 8) | ((*scan
++) & 0xff);
1426 copy_threadref (threadref
*dest
, threadref
*src
)
1429 unsigned char *csrc
, *cdest
;
1431 csrc
= (unsigned char *) src
;
1432 cdest
= (unsigned char *) dest
;
1439 threadmatch (threadref
*dest
, threadref
*src
)
1441 /* Things are broken right now, so just assume we got a match. */
1443 unsigned char *srcp
, *destp
;
1445 srcp
= (char *) src
;
1446 destp
= (char *) dest
;
1450 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1457 threadid:1, # always request threadid
1464 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1467 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1469 *pkt
++ = 'q'; /* Info Query */
1470 *pkt
++ = 'P'; /* process or thread info */
1471 pkt
= pack_int (pkt
, mode
); /* mode */
1472 pkt
= pack_threadid (pkt
, id
); /* threadid */
1473 *pkt
= '\0'; /* terminate */
1477 /* These values tag the fields in a thread info response packet. */
1478 /* Tagging the fields allows us to request specific fields and to
1479 add more fields as time goes by. */
1481 #define TAG_THREADID 1 /* Echo the thread identifier. */
1482 #define TAG_EXISTS 2 /* Is this process defined enough to
1483 fetch registers and its stack? */
1484 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1485 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
1486 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1490 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1491 struct gdb_ext_thread_info
*info
)
1493 struct remote_state
*rs
= get_remote_state ();
1497 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1500 /* info->threadid = 0; FIXME: implement zero_threadref. */
1502 info
->display
[0] = '\0';
1503 info
->shortname
[0] = '\0';
1504 info
->more_display
[0] = '\0';
1506 /* Assume the characters indicating the packet type have been
1508 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1509 pkt
= unpack_threadid (pkt
, &ref
);
1512 warning (_("Incomplete response to threadinfo request."));
1513 if (!threadmatch (&ref
, expectedref
))
1514 { /* This is an answer to a different request. */
1515 warning (_("ERROR RMT Thread info mismatch."));
1518 copy_threadref (&info
->threadid
, &ref
);
1520 /* Loop on tagged fields , try to bail if somthing goes wrong. */
1522 /* Packets are terminated with nulls. */
1523 while ((pkt
< limit
) && mask
&& *pkt
)
1525 pkt
= unpack_int (pkt
, &tag
); /* tag */
1526 pkt
= unpack_byte (pkt
, &length
); /* length */
1527 if (!(tag
& mask
)) /* Tags out of synch with mask. */
1529 warning (_("ERROR RMT: threadinfo tag mismatch."));
1533 if (tag
== TAG_THREADID
)
1537 warning (_("ERROR RMT: length of threadid is not 16."));
1541 pkt
= unpack_threadid (pkt
, &ref
);
1542 mask
= mask
& ~TAG_THREADID
;
1545 if (tag
== TAG_EXISTS
)
1547 info
->active
= stub_unpack_int (pkt
, length
);
1549 mask
= mask
& ~(TAG_EXISTS
);
1552 warning (_("ERROR RMT: 'exists' length too long."));
1558 if (tag
== TAG_THREADNAME
)
1560 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1561 mask
= mask
& ~TAG_THREADNAME
;
1564 if (tag
== TAG_DISPLAY
)
1566 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1567 mask
= mask
& ~TAG_DISPLAY
;
1570 if (tag
== TAG_MOREDISPLAY
)
1572 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1573 mask
= mask
& ~TAG_MOREDISPLAY
;
1576 warning (_("ERROR RMT: unknown thread info tag."));
1577 break; /* Not a tag we know about. */
1583 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1584 struct gdb_ext_thread_info
*info
)
1586 struct remote_state
*rs
= get_remote_state ();
1588 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1590 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1591 putpkt (threadinfo_pkt
);
1592 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1593 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2,
1598 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1601 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1602 threadref
*nextthread
)
1604 *pkt
++ = 'q'; /* info query packet */
1605 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1606 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1607 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1608 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1613 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1616 parse_threadlist_response (char *pkt
, int result_limit
,
1617 threadref
*original_echo
, threadref
*resultlist
,
1620 struct remote_state
*rs
= get_remote_state ();
1622 int count
, resultcount
, done
;
1625 /* Assume the 'q' and 'M chars have been stripped. */
1626 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
);
1627 /* done parse past here */
1628 pkt
= unpack_byte (pkt
, &count
); /* count field */
1629 pkt
= unpack_nibble (pkt
, &done
);
1630 /* The first threadid is the argument threadid. */
1631 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1632 while ((count
-- > 0) && (pkt
< limit
))
1634 pkt
= unpack_threadid (pkt
, resultlist
++);
1635 if (resultcount
++ >= result_limit
)
1644 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1645 int *done
, int *result_count
, threadref
*threadlist
)
1647 struct remote_state
*rs
= get_remote_state ();
1648 static threadref echo_nextthread
;
1649 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1650 char *t_response
= alloca (rs
->remote_packet_size
);
1653 /* Trancate result limit to be smaller than the packet size. */
1654 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1655 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1657 pack_threadlist_request (threadlist_packet
,
1658 startflag
, result_limit
, nextthread
);
1659 putpkt (threadlist_packet
);
1660 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1663 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1666 if (!threadmatch (&echo_nextthread
, nextthread
))
1668 /* FIXME: This is a good reason to drop the packet. */
1669 /* Possably, there is a duplicate response. */
1671 retransmit immediatly - race conditions
1672 retransmit after timeout - yes
1674 wait for packet, then exit
1676 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
1677 return 0; /* I choose simply exiting. */
1679 if (*result_count
<= 0)
1683 warning (_("RMT ERROR : failed to get remote thread list."));
1686 return result
; /* break; */
1688 if (*result_count
> result_limit
)
1691 warning (_("RMT ERROR: threadlist response longer than requested."));
1697 /* This is the interface between remote and threads, remotes upper
1700 /* remote_find_new_threads retrieves the thread list and for each
1701 thread in the list, looks up the thread in GDB's internal list,
1702 ading the thread if it does not already exist. This involves
1703 getting partial thread lists from the remote target so, polling the
1704 quit_flag is required. */
1707 /* About this many threadisds fit in a packet. */
1709 #define MAXTHREADLISTRESULTS 32
1712 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1715 int done
, i
, result_count
;
1719 static threadref nextthread
;
1720 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1725 if (loopcount
++ > looplimit
)
1728 warning (_("Remote fetch threadlist -infinite loop-."));
1731 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1732 &done
, &result_count
, resultthreadlist
))
1737 /* Clear for later iterations. */
1739 /* Setup to resume next batch of thread references, set nextthread. */
1740 if (result_count
>= 1)
1741 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1743 while (result_count
--)
1744 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1751 remote_newthread_step (threadref
*ref
, void *context
)
1755 ptid
= pid_to_ptid (threadref_to_int (ref
));
1757 if (!in_thread_list (ptid
))
1759 return 1; /* continue iterator */
1762 #define CRAZY_MAX_THREADS 1000
1765 remote_current_thread (ptid_t oldpid
)
1767 struct remote_state
*rs
= get_remote_state ();
1768 char *buf
= alloca (rs
->remote_packet_size
);
1771 getpkt (buf
, (rs
->remote_packet_size
), 0);
1772 if (buf
[0] == 'Q' && buf
[1] == 'C')
1773 /* Use strtoul here, so we'll correctly parse values whose highest
1774 bit is set. The protocol carries them as a simple series of
1775 hex digits; in the absence of a sign, strtol will see such
1776 values as positive numbers out of range for signed 'long', and
1777 return LONG_MAX to indicate an overflow. */
1778 return pid_to_ptid (strtoul (&buf
[2], NULL
, 16));
1783 /* Find new threads for info threads command.
1784 * Original version, using John Metzler's thread protocol.
1788 remote_find_new_threads (void)
1790 remote_threadlist_iterator (remote_newthread_step
, 0,
1792 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1793 inferior_ptid
= remote_current_thread (inferior_ptid
);
1797 * Find all threads for info threads command.
1798 * Uses new thread protocol contributed by Cisco.
1799 * Falls back and attempts to use the older method (above)
1800 * if the target doesn't respond to the new method.
1804 remote_threads_info (void)
1806 struct remote_state
*rs
= get_remote_state ();
1807 char *buf
= alloca (rs
->remote_packet_size
);
1811 if (remote_desc
== 0) /* paranoia */
1812 error (_("Command can only be used when connected to the remote target."));
1814 if (use_threadinfo_query
)
1816 putpkt ("qfThreadInfo");
1818 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1819 if (bufp
[0] != '\0') /* q packet recognized */
1821 while (*bufp
++ == 'm') /* reply contains one or more TID */
1825 /* Use strtoul here, so we'll correctly parse values
1826 whose highest bit is set. The protocol carries
1827 them as a simple series of hex digits; in the
1828 absence of a sign, strtol will see such values as
1829 positive numbers out of range for signed 'long',
1830 and return LONG_MAX to indicate an overflow. */
1831 tid
= strtoul (bufp
, &bufp
, 16);
1832 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1833 add_thread (pid_to_ptid (tid
));
1835 while (*bufp
++ == ','); /* comma-separated list */
1836 putpkt ("qsThreadInfo");
1838 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1844 /* Else fall back to old method based on jmetzler protocol. */
1845 use_threadinfo_query
= 0;
1846 remote_find_new_threads ();
1851 * Collect a descriptive string about the given thread.
1852 * The target may say anything it wants to about the thread
1853 * (typically info about its blocked / runnable state, name, etc.).
1854 * This string will appear in the info threads display.
1856 * Optional: targets are not required to implement this function.
1860 remote_threads_extra_info (struct thread_info
*tp
)
1862 struct remote_state
*rs
= get_remote_state ();
1866 struct gdb_ext_thread_info threadinfo
;
1867 static char display_buf
[100]; /* arbitrary... */
1868 char *bufp
= alloca (rs
->remote_packet_size
);
1869 int n
= 0; /* position in display_buf */
1871 if (remote_desc
== 0) /* paranoia */
1872 internal_error (__FILE__
, __LINE__
,
1873 _("remote_threads_extra_info"));
1875 if (use_threadextra_query
)
1877 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1879 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1882 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1883 result
= hex2bin (bufp
, display_buf
, n
);
1884 display_buf
[result
] = '\0';
1889 /* If the above query fails, fall back to the old method. */
1890 use_threadextra_query
= 0;
1891 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1892 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1893 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1894 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1895 if (threadinfo
.active
)
1897 if (*threadinfo
.shortname
)
1898 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1899 if (*threadinfo
.display
)
1900 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1901 if (*threadinfo
.more_display
)
1902 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1903 threadinfo
.more_display
);
1907 /* For purely cosmetic reasons, clear up trailing commas. */
1908 if (',' == display_buf
[n
-1])
1909 display_buf
[n
-1] = ' ';
1918 /* Restart the remote side; this is an extended protocol operation. */
1921 extended_remote_restart (void)
1923 struct remote_state
*rs
= get_remote_state ();
1924 char *buf
= alloca (rs
->remote_packet_size
);
1926 /* Send the restart command; for reasons I don't understand the
1927 remote side really expects a number after the "R". */
1929 sprintf (&buf
[1], "%x", 0);
1932 /* Now query for status so this looks just like we restarted
1933 gdbserver from scratch. */
1935 getpkt (buf
, (rs
->remote_packet_size
), 0);
1938 /* Clean up connection to a remote debugger. */
1941 remote_close (int quitting
)
1944 serial_close (remote_desc
);
1948 /* Query the remote side for the text, data and bss offsets. */
1953 struct remote_state
*rs
= get_remote_state ();
1954 char *buf
= alloca (rs
->remote_packet_size
);
1957 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1958 struct section_offsets
*offs
;
1960 putpkt ("qOffsets");
1962 getpkt (buf
, (rs
->remote_packet_size
), 0);
1964 if (buf
[0] == '\000')
1965 return; /* Return silently. Stub doesn't support
1969 warning (_("Remote failure reply: %s"), buf
);
1973 /* Pick up each field in turn. This used to be done with scanf, but
1974 scanf will make trouble if CORE_ADDR size doesn't match
1975 conversion directives correctly. The following code will work
1976 with any size of CORE_ADDR. */
1977 text_addr
= data_addr
= bss_addr
= 0;
1981 if (strncmp (ptr
, "Text=", 5) == 0)
1984 /* Don't use strtol, could lose on big values. */
1985 while (*ptr
&& *ptr
!= ';')
1986 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1991 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1994 while (*ptr
&& *ptr
!= ';')
1995 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2000 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2003 while (*ptr
&& *ptr
!= ';')
2004 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2010 error (_("Malformed response to offset query, %s"), buf
);
2012 if (symfile_objfile
== NULL
)
2015 offs
= ((struct section_offsets
*)
2016 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2017 memcpy (offs
, symfile_objfile
->section_offsets
,
2018 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2020 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2022 /* This is a temporary kludge to force data and bss to use the same offsets
2023 because that's what nlmconv does now. The real solution requires changes
2024 to the stub and remote.c that I don't have time to do right now. */
2026 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2027 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2029 objfile_relocate (symfile_objfile
, offs
);
2032 /* Stub for catch_errors. */
2035 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2037 start_remote (); /* Initialize gdb process mechanisms. */
2038 /* NOTE: Return something >=0. A -ve value is reserved for
2039 catch_exceptions. */
2044 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2046 immediate_quit
++; /* Allow user to interrupt it. */
2048 /* Ack any packet which the remote side has already sent. */
2049 serial_write (remote_desc
, "+", 1);
2051 /* Let the stub know that we want it to return the thread. */
2054 inferior_ptid
= remote_current_thread (inferior_ptid
);
2056 get_offsets (); /* Get text, data & bss offsets. */
2058 putpkt ("?"); /* Initiate a query from remote machine. */
2061 remote_start_remote_dummy (uiout
, dummy
);
2064 /* Open a connection to a remote debugger.
2065 NAME is the filename used for communication. */
2068 remote_open (char *name
, int from_tty
)
2070 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2073 /* Just like remote_open, but with asynchronous support. */
2075 remote_async_open (char *name
, int from_tty
)
2077 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2080 /* Open a connection to a remote debugger using the extended
2081 remote gdb protocol. NAME is the filename used for communication. */
2084 extended_remote_open (char *name
, int from_tty
)
2086 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2090 /* Just like extended_remote_open, but with asynchronous support. */
2092 extended_remote_async_open (char *name
, int from_tty
)
2094 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2095 1 /*extended_p */, 1 /* async_p */);
2098 /* Generic code for opening a connection to a remote target. */
2101 init_all_packet_configs (void)
2104 update_packet_config (&remote_protocol_P
);
2105 update_packet_config (&remote_protocol_p
);
2106 update_packet_config (&remote_protocol_qSymbol
);
2107 update_packet_config (&remote_protocol_vcont
);
2108 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2109 update_packet_config (&remote_protocol_Z
[i
]);
2110 /* Force remote_write_bytes to check whether target supports binary
2112 update_packet_config (&remote_protocol_binary_download
);
2113 update_packet_config (&remote_protocol_qPart_auxv
);
2116 /* Symbol look-up. */
2119 remote_check_symbols (struct objfile
*objfile
)
2121 struct remote_state
*rs
= get_remote_state ();
2122 char *msg
, *reply
, *tmp
;
2123 struct minimal_symbol
*sym
;
2126 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2129 msg
= alloca (rs
->remote_packet_size
);
2130 reply
= alloca (rs
->remote_packet_size
);
2132 /* Invite target to request symbol lookups. */
2134 putpkt ("qSymbol::");
2135 getpkt (reply
, (rs
->remote_packet_size
), 0);
2136 packet_ok (reply
, &remote_protocol_qSymbol
);
2138 while (strncmp (reply
, "qSymbol:", 8) == 0)
2141 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2143 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2145 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2147 sprintf (msg
, "qSymbol:%s:%s",
2148 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2151 getpkt (reply
, (rs
->remote_packet_size
), 0);
2155 static struct serial
*
2156 remote_serial_open (char *name
)
2158 static int udp_warning
= 0;
2160 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2161 of in ser-tcp.c, because it is the remote protocol assuming that the
2162 serial connection is reliable and not the serial connection promising
2164 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2167 The remote protocol may be unreliable over UDP.\n\
2168 Some events may be lost, rendering further debugging impossible."));
2172 return serial_open (name
);
2176 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2177 int extended_p
, int async_p
)
2179 struct exception ex
;
2180 struct remote_state
*rs
= get_remote_state ();
2182 error (_("To open a remote debug connection, you need to specify what\n"
2183 "serial device is attached to the remote system\n"
2184 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
2186 /* See FIXME above. */
2188 wait_forever_enabled_p
= 1;
2190 reopen_exec_file ();
2193 target_preopen (from_tty
);
2195 unpush_target (target
);
2197 remote_desc
= remote_serial_open (name
);
2199 perror_with_name (name
);
2201 if (baud_rate
!= -1)
2203 if (serial_setbaudrate (remote_desc
, baud_rate
))
2205 /* The requested speed could not be set. Error out to
2206 top level after closing remote_desc. Take care to
2207 set remote_desc to NULL to avoid closing remote_desc
2209 serial_close (remote_desc
);
2211 perror_with_name (name
);
2215 serial_raw (remote_desc
);
2217 /* If there is something sitting in the buffer we might take it as a
2218 response to a command, which would be bad. */
2219 serial_flush_input (remote_desc
);
2223 puts_filtered ("Remote debugging using ");
2224 puts_filtered (name
);
2225 puts_filtered ("\n");
2227 push_target (target
); /* Switch to using remote target now. */
2229 init_all_packet_configs ();
2231 general_thread
= -2;
2232 continue_thread
= -2;
2234 /* Probe for ability to use "ThreadInfo" query, as required. */
2235 use_threadinfo_query
= 1;
2236 use_threadextra_query
= 1;
2238 /* Without this, some commands which require an active target (such
2239 as kill) won't work. This variable serves (at least) double duty
2240 as both the pid of the target process (if it has such), and as a
2241 flag indicating that a target is active. These functions should
2242 be split out into seperate variables, especially since GDB will
2243 someday have a notion of debugging several processes. */
2245 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2249 /* With this target we start out by owning the terminal. */
2250 remote_async_terminal_ours_p
= 1;
2252 /* FIXME: cagney/1999-09-23: During the initial connection it is
2253 assumed that the target is already ready and able to respond to
2254 requests. Unfortunately remote_start_remote() eventually calls
2255 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2256 around this. Eventually a mechanism that allows
2257 wait_for_inferior() to expect/get timeouts will be
2259 wait_forever_enabled_p
= 0;
2262 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2263 /* First delete any symbols previously loaded from shared libraries. */
2264 no_shared_libraries (NULL
, 0);
2267 /* Start the remote connection. If error() or QUIT, discard this
2268 target (we'd otherwise be in an inconsistent state) and then
2269 propogate the error on up the exception chain. This ensures that
2270 the caller doesn't stumble along blindly assuming that the
2271 function succeeded. The CLI doesn't have this problem but other
2272 UI's, such as MI do.
2274 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2275 this function should return an error indication letting the
2276 caller restore the previous state. Unfortunately the command
2277 ``target remote'' is directly wired to this function making that
2278 impossible. On a positive note, the CLI side of this problem has
2279 been fixed - the function set_cmd_context() makes it possible for
2280 all the ``target ....'' commands to share a common callback
2281 function. See cli-dump.c. */
2282 ex
= catch_exception (uiout
, remote_start_remote
, NULL
, RETURN_MASK_ALL
);
2287 wait_forever_enabled_p
= 1;
2288 throw_exception (ex
);
2292 wait_forever_enabled_p
= 1;
2296 /* Tell the remote that we are using the extended protocol. */
2297 char *buf
= alloca (rs
->remote_packet_size
);
2299 getpkt (buf
, (rs
->remote_packet_size
), 0);
2301 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2302 /* FIXME: need a master target_open vector from which all
2303 remote_opens can be called, so that stuff like this can
2304 go there. Failing that, the following code must be copied
2305 to the open function for any remote target that wants to
2306 support svr4 shared libraries. */
2308 /* Set up to detect and load shared libraries. */
2309 if (exec_bfd
) /* No use without an exec file. */
2311 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2312 remote_check_symbols (symfile_objfile
);
2316 observer_notify_inferior_created (¤t_target
, from_tty
);
2319 /* This takes a program previously attached to and detaches it. After
2320 this is done, GDB can be used to debug some other program. We
2321 better not have left any breakpoints in the target program or it'll
2322 die when it hits one. */
2325 remote_detach (char *args
, int from_tty
)
2327 struct remote_state
*rs
= get_remote_state ();
2328 char *buf
= alloca (rs
->remote_packet_size
);
2331 error (_("Argument given to \"detach\" when remotely debugging."));
2333 /* Tell the remote target to detach. */
2335 remote_send (buf
, (rs
->remote_packet_size
));
2337 /* Unregister the file descriptor from the event loop. */
2338 if (target_is_async_p ())
2339 serial_async (remote_desc
, NULL
, 0);
2341 target_mourn_inferior ();
2343 puts_filtered ("Ending remote debugging.\n");
2346 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2349 remote_disconnect (char *args
, int from_tty
)
2351 struct remote_state
*rs
= get_remote_state ();
2352 char *buf
= alloca (rs
->remote_packet_size
);
2355 error (_("Argument given to \"detach\" when remotely debugging."));
2357 /* Unregister the file descriptor from the event loop. */
2358 if (target_is_async_p ())
2359 serial_async (remote_desc
, NULL
, 0);
2361 target_mourn_inferior ();
2363 puts_filtered ("Ending remote debugging.\n");
2366 /* Convert hex digit A to a number. */
2371 if (a
>= '0' && a
<= '9')
2373 else if (a
>= 'a' && a
<= 'f')
2374 return a
- 'a' + 10;
2375 else if (a
>= 'A' && a
<= 'F')
2376 return a
- 'A' + 10;
2378 error (_("Reply contains invalid hex digit %d"), a
);
2382 hex2bin (const char *hex
, char *bin
, int count
)
2386 for (i
= 0; i
< count
; i
++)
2388 if (hex
[0] == 0 || hex
[1] == 0)
2390 /* Hex string is short, or of uneven length.
2391 Return the count that has been converted so far. */
2394 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2400 /* Convert number NIB to a hex digit. */
2408 return 'a' + nib
- 10;
2412 bin2hex (const char *bin
, char *hex
, int count
)
2415 /* May use a length, or a nul-terminated string as input. */
2417 count
= strlen (bin
);
2419 for (i
= 0; i
< count
; i
++)
2421 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2422 *hex
++ = tohex (*bin
++ & 0xf);
2428 /* Check for the availability of vCont. This function should also check
2432 remote_vcont_probe (struct remote_state
*rs
, char *buf
)
2434 strcpy (buf
, "vCont?");
2436 getpkt (buf
, rs
->remote_packet_size
, 0);
2438 /* Make sure that the features we assume are supported. */
2439 if (strncmp (buf
, "vCont", 5) == 0)
2442 int support_s
, support_S
, support_c
, support_C
;
2448 while (p
&& *p
== ';')
2451 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2453 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2455 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2457 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2460 p
= strchr (p
, ';');
2463 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
2464 BUF will make packet_ok disable the packet. */
2465 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
2469 packet_ok (buf
, &remote_protocol_vcont
);
2472 /* Resume the remote inferior by using a "vCont" packet. The thread
2473 to be resumed is PTID; STEP and SIGGNAL indicate whether the
2474 resumed thread should be single-stepped and/or signalled. If PTID's
2475 PID is -1, then all threads are resumed; the thread to be stepped and/or
2476 signalled is given in the global INFERIOR_PTID. This function returns
2477 non-zero iff it resumes the inferior.
2479 This function issues a strict subset of all possible vCont commands at the
2483 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2485 struct remote_state
*rs
= get_remote_state ();
2486 int pid
= PIDGET (ptid
);
2487 char *buf
= NULL
, *outbuf
;
2488 struct cleanup
*old_cleanup
;
2490 buf
= xmalloc (rs
->remote_packet_size
);
2491 old_cleanup
= make_cleanup (xfree
, buf
);
2493 if (remote_protocol_vcont
.support
== PACKET_SUPPORT_UNKNOWN
)
2494 remote_vcont_probe (rs
, buf
);
2496 if (remote_protocol_vcont
.support
== PACKET_DISABLE
)
2498 do_cleanups (old_cleanup
);
2502 /* If we could generate a wider range of packets, we'd have to worry
2503 about overflowing BUF. Should there be a generic
2504 "multi-part-packet" packet? */
2506 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
)
2508 /* MAGIC_NULL_PTID means that we don't have any active threads, so we
2509 don't have any PID numbers the inferior will understand. Make sure
2510 to only send forms that do not specify a PID. */
2511 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2512 outbuf
= xstrprintf ("vCont;S%02x", siggnal
);
2514 outbuf
= xstrprintf ("vCont;s");
2515 else if (siggnal
!= TARGET_SIGNAL_0
)
2516 outbuf
= xstrprintf ("vCont;C%02x", siggnal
);
2518 outbuf
= xstrprintf ("vCont;c");
2522 /* Resume all threads, with preference for INFERIOR_PTID. */
2523 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2524 outbuf
= xstrprintf ("vCont;S%02x:%x;c", siggnal
,
2525 PIDGET (inferior_ptid
));
2527 outbuf
= xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid
));
2528 else if (siggnal
!= TARGET_SIGNAL_0
)
2529 outbuf
= xstrprintf ("vCont;C%02x:%x;c", siggnal
,
2530 PIDGET (inferior_ptid
));
2532 outbuf
= xstrprintf ("vCont;c");
2536 /* Scheduler locking; resume only PTID. */
2537 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2538 outbuf
= xstrprintf ("vCont;S%02x:%x", siggnal
, pid
);
2540 outbuf
= xstrprintf ("vCont;s:%x", pid
);
2541 else if (siggnal
!= TARGET_SIGNAL_0
)
2542 outbuf
= xstrprintf ("vCont;C%02x:%x", siggnal
, pid
);
2544 outbuf
= xstrprintf ("vCont;c:%x", pid
);
2547 gdb_assert (outbuf
&& strlen (outbuf
) < rs
->remote_packet_size
);
2548 make_cleanup (xfree
, outbuf
);
2552 do_cleanups (old_cleanup
);
2557 /* Tell the remote machine to resume. */
2559 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2561 static int last_sent_step
;
2564 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2566 struct remote_state
*rs
= get_remote_state ();
2567 char *buf
= alloca (rs
->remote_packet_size
);
2568 int pid
= PIDGET (ptid
);
2571 last_sent_signal
= siggnal
;
2572 last_sent_step
= step
;
2574 /* A hook for when we need to do something at the last moment before
2576 if (deprecated_target_resume_hook
)
2577 (*deprecated_target_resume_hook
) ();
2579 /* The vCont packet doesn't need to specify threads via Hc. */
2580 if (remote_vcont_resume (ptid
, step
, siggnal
))
2583 /* All other supported resume packets do use Hc, so call set_thread. */
2585 set_thread (0, 0); /* Run any thread. */
2587 set_thread (pid
, 0); /* Run this thread. */
2589 if (siggnal
!= TARGET_SIGNAL_0
)
2591 buf
[0] = step
? 'S' : 'C';
2592 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2593 buf
[2] = tohex (((int) siggnal
) & 0xf);
2597 strcpy (buf
, step
? "s" : "c");
2602 /* Same as remote_resume, but with async support. */
2604 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2606 remote_resume (ptid
, step
, siggnal
);
2608 /* We are about to start executing the inferior, let's register it
2609 with the event loop. NOTE: this is the one place where all the
2610 execution commands end up. We could alternatively do this in each
2611 of the execution commands in infcmd.c. */
2612 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2613 into infcmd.c in order to allow inferior function calls to work
2614 NOT asynchronously. */
2615 if (target_can_async_p ())
2616 target_async (inferior_event_handler
, 0);
2617 /* Tell the world that the target is now executing. */
2618 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2619 this? Instead, should the client of target just assume (for
2620 async targets) that the target is going to start executing? Is
2621 this information already found in the continuation block? */
2622 if (target_is_async_p ())
2623 target_executing
= 1;
2627 /* Set up the signal handler for SIGINT, while the target is
2628 executing, ovewriting the 'regular' SIGINT signal handler. */
2630 initialize_sigint_signal_handler (void)
2632 sigint_remote_token
=
2633 create_async_signal_handler (async_remote_interrupt
, NULL
);
2634 signal (SIGINT
, handle_remote_sigint
);
2637 /* Signal handler for SIGINT, while the target is executing. */
2639 handle_remote_sigint (int sig
)
2641 signal (sig
, handle_remote_sigint_twice
);
2642 sigint_remote_twice_token
=
2643 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2644 mark_async_signal_handler_wrapper (sigint_remote_token
);
2647 /* Signal handler for SIGINT, installed after SIGINT has already been
2648 sent once. It will take effect the second time that the user sends
2651 handle_remote_sigint_twice (int sig
)
2653 signal (sig
, handle_sigint
);
2654 sigint_remote_twice_token
=
2655 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2656 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2659 /* Perform the real interruption of the target execution, in response
2662 async_remote_interrupt (gdb_client_data arg
)
2665 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2670 /* Perform interrupt, if the first attempt did not succeed. Just give
2671 up on the target alltogether. */
2673 async_remote_interrupt_twice (gdb_client_data arg
)
2676 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2677 /* Do something only if the target was not killed by the previous
2679 if (target_executing
)
2682 signal (SIGINT
, handle_remote_sigint
);
2686 /* Reinstall the usual SIGINT handlers, after the target has
2689 cleanup_sigint_signal_handler (void *dummy
)
2691 signal (SIGINT
, handle_sigint
);
2692 if (sigint_remote_twice_token
)
2693 delete_async_signal_handler ((struct async_signal_handler
**)
2694 &sigint_remote_twice_token
);
2695 if (sigint_remote_token
)
2696 delete_async_signal_handler ((struct async_signal_handler
**)
2697 &sigint_remote_token
);
2700 /* Send ^C to target to halt it. Target will respond, and send us a
2702 static void (*ofunc
) (int);
2704 /* The command line interface's stop routine. This function is installed
2705 as a signal handler for SIGINT. The first time a user requests a
2706 stop, we call remote_stop to send a break or ^C. If there is no
2707 response from the target (it didn't stop when the user requested it),
2708 we ask the user if he'd like to detach from the target. */
2710 remote_interrupt (int signo
)
2712 /* If this doesn't work, try more severe steps. */
2713 signal (signo
, remote_interrupt_twice
);
2716 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2721 /* The user typed ^C twice. */
2724 remote_interrupt_twice (int signo
)
2726 signal (signo
, ofunc
);
2728 signal (signo
, remote_interrupt
);
2731 /* This is the generic stop called via the target vector. When a target
2732 interrupt is requested, either by the command line or the GUI, we
2733 will eventually end up here. */
2737 /* Send a break or a ^C, depending on user preference. */
2739 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2742 serial_send_break (remote_desc
);
2744 serial_write (remote_desc
, "\003", 1);
2747 /* Ask the user what to do when an interrupt is received. */
2750 interrupt_query (void)
2752 target_terminal_ours ();
2754 if (query ("Interrupted while waiting for the program.\n\
2755 Give up (and stop debugging it)? "))
2757 target_mourn_inferior ();
2758 deprecated_throw_reason (RETURN_QUIT
);
2761 target_terminal_inferior ();
2764 /* Enable/disable target terminal ownership. Most targets can use
2765 terminal groups to control terminal ownership. Remote targets are
2766 different in that explicit transfer of ownership to/from GDB/target
2770 remote_async_terminal_inferior (void)
2772 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2773 sync_execution here. This function should only be called when
2774 GDB is resuming the inferior in the forground. A background
2775 resume (``run&'') should leave GDB in control of the terminal and
2776 consequently should not call this code. */
2777 if (!sync_execution
)
2779 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2780 calls target_terminal_*() idenpotent. The event-loop GDB talking
2781 to an asynchronous target with a synchronous command calls this
2782 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2783 stops trying to transfer the terminal to the target when it
2784 shouldn't this guard can go away. */
2785 if (!remote_async_terminal_ours_p
)
2787 delete_file_handler (input_fd
);
2788 remote_async_terminal_ours_p
= 0;
2789 initialize_sigint_signal_handler ();
2790 /* NOTE: At this point we could also register our selves as the
2791 recipient of all input. Any characters typed could then be
2792 passed on down to the target. */
2796 remote_async_terminal_ours (void)
2798 /* See FIXME in remote_async_terminal_inferior. */
2799 if (!sync_execution
)
2801 /* See FIXME in remote_async_terminal_inferior. */
2802 if (remote_async_terminal_ours_p
)
2804 cleanup_sigint_signal_handler (NULL
);
2805 add_file_handler (input_fd
, stdin_event_handler
, 0);
2806 remote_async_terminal_ours_p
= 1;
2809 /* If nonzero, ignore the next kill. */
2814 remote_console_output (char *msg
)
2818 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2821 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2824 fputs_unfiltered (tb
, gdb_stdtarg
);
2826 gdb_flush (gdb_stdtarg
);
2829 /* Wait until the remote machine stops, then return,
2830 storing status in STATUS just as `wait' would.
2831 Returns "pid", which in the case of a multi-threaded
2832 remote OS, is the thread-id. */
2835 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2837 struct remote_state
*rs
= get_remote_state ();
2838 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2839 ULONGEST thread_num
= -1;
2842 status
->kind
= TARGET_WAITKIND_EXITED
;
2843 status
->value
.integer
= 0;
2849 ofunc
= signal (SIGINT
, remote_interrupt
);
2850 getpkt (buf
, (rs
->remote_packet_size
), 1);
2851 signal (SIGINT
, ofunc
);
2853 /* This is a hook for when we need to do something (perhaps the
2854 collection of trace data) every time the target stops. */
2855 if (deprecated_target_wait_loop_hook
)
2856 (*deprecated_target_wait_loop_hook
) ();
2858 remote_stopped_by_watchpoint_p
= 0;
2862 case 'E': /* Error of some sort. */
2863 warning (_("Remote failure reply: %s"), buf
);
2865 case 'F': /* File-I/O request. */
2866 remote_fileio_request (buf
);
2868 case 'T': /* Status with PC, SP, FP, ... */
2871 char regs
[MAX_REGISTER_SIZE
];
2873 /* Expedited reply, containing Signal, {regno, reg} repeat. */
2874 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2876 n... = register number
2877 r... = register contents
2879 p
= &buf
[3]; /* after Txx */
2888 /* If the packet contains a register number save it in
2889 pnum and set p1 to point to the character following
2890 it. Otherwise p1 points to p. */
2892 /* If this packet is an awatch packet, don't parse the
2893 'a' as a register number. */
2895 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
2897 /* Read the ``P'' register number. */
2898 pnum
= strtol (p
, &p_temp
, 16);
2899 p1
= (unsigned char *) p_temp
;
2904 if (p1
== p
) /* No register number present here. */
2906 p1
= (unsigned char *) strchr (p
, ':');
2908 warning (_("Malformed packet(a) (missing colon): %s\n\
2911 if (strncmp (p
, "thread", p1
- p
) == 0)
2913 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2914 record_currthread (thread_num
);
2915 p
= (unsigned char *) p_temp
;
2917 else if ((strncmp (p
, "watch", p1
- p
) == 0)
2918 || (strncmp (p
, "rwatch", p1
- p
) == 0)
2919 || (strncmp (p
, "awatch", p1
- p
) == 0))
2921 remote_stopped_by_watchpoint_p
= 1;
2922 p
= unpack_varlen_hex (++p1
, &addr
);
2923 remote_watch_data_address
= (CORE_ADDR
)addr
;
2927 /* Silently skip unknown optional info. */
2928 p_temp
= strchr (p1
+ 1, ';');
2930 p
= (unsigned char *) p_temp
;
2935 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
2939 error (_("Malformed packet(b) (missing colon): %s\n\
2944 error (_("Remote sent bad register number %s: %s\n\
2946 phex_nz (pnum
, 0), p
, buf
);
2948 fieldsize
= hex2bin (p
, regs
,
2949 register_size (current_gdbarch
,
2952 if (fieldsize
< register_size (current_gdbarch
,
2954 warning (_("Remote reply is too short: %s"), buf
);
2955 regcache_raw_supply (current_regcache
,
2960 error (_("Remote register badly formatted: %s\nhere: %s"),
2965 case 'S': /* Old style status, just signal only. */
2966 status
->kind
= TARGET_WAITKIND_STOPPED
;
2967 status
->value
.sig
= (enum target_signal
)
2968 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2972 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2973 record_currthread (thread_num
);
2976 case 'W': /* Target exited. */
2978 /* The remote process exited. */
2979 status
->kind
= TARGET_WAITKIND_EXITED
;
2980 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2984 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2985 status
->value
.sig
= (enum target_signal
)
2986 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2990 case 'O': /* Console output. */
2991 remote_console_output (buf
+ 1);
2994 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2996 /* Zero length reply means that we tried 'S' or 'C' and
2997 the remote system doesn't support it. */
2998 target_terminal_ours_for_output ();
3000 ("Can't send signals to this remote system. %s not sent.\n",
3001 target_signal_to_name (last_sent_signal
));
3002 last_sent_signal
= TARGET_SIGNAL_0
;
3003 target_terminal_inferior ();
3005 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3006 putpkt ((char *) buf
);
3009 /* else fallthrough */
3011 warning (_("Invalid remote reply: %s"), buf
);
3016 if (thread_num
!= -1)
3018 return pid_to_ptid (thread_num
);
3020 return inferior_ptid
;
3023 /* Async version of remote_wait. */
3025 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3027 struct remote_state
*rs
= get_remote_state ();
3028 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3029 ULONGEST thread_num
= -1;
3032 status
->kind
= TARGET_WAITKIND_EXITED
;
3033 status
->value
.integer
= 0;
3035 remote_stopped_by_watchpoint_p
= 0;
3041 if (!target_is_async_p ())
3042 ofunc
= signal (SIGINT
, remote_interrupt
);
3043 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3044 _never_ wait for ever -> test on target_is_async_p().
3045 However, before we do that we need to ensure that the caller
3046 knows how to take the target into/out of async mode. */
3047 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3048 if (!target_is_async_p ())
3049 signal (SIGINT
, ofunc
);
3051 /* This is a hook for when we need to do something (perhaps the
3052 collection of trace data) every time the target stops. */
3053 if (deprecated_target_wait_loop_hook
)
3054 (*deprecated_target_wait_loop_hook
) ();
3058 case 'E': /* Error of some sort. */
3059 warning (_("Remote failure reply: %s"), buf
);
3061 case 'F': /* File-I/O request. */
3062 remote_fileio_request (buf
);
3064 case 'T': /* Status with PC, SP, FP, ... */
3067 char regs
[MAX_REGISTER_SIZE
];
3069 /* Expedited reply, containing Signal, {regno, reg} repeat. */
3070 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3072 n... = register number
3073 r... = register contents
3075 p
= &buf
[3]; /* after Txx */
3084 /* If the packet contains a register number, save it
3085 in pnum and set p1 to point to the character
3086 following it. Otherwise p1 points to p. */
3088 /* If this packet is an awatch packet, don't parse the 'a'
3089 as a register number. */
3091 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3093 /* Read the register number. */
3094 pnum
= strtol (p
, &p_temp
, 16);
3095 p1
= (unsigned char *) p_temp
;
3100 if (p1
== p
) /* No register number present here. */
3102 p1
= (unsigned char *) strchr (p
, ':');
3104 error (_("Malformed packet(a) (missing colon): %s\n\
3107 if (strncmp (p
, "thread", p1
- p
) == 0)
3109 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3110 record_currthread (thread_num
);
3111 p
= (unsigned char *) p_temp
;
3113 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3114 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3115 || (strncmp (p
, "awatch", p1
- p
) == 0))
3117 remote_stopped_by_watchpoint_p
= 1;
3118 p
= unpack_varlen_hex (++p1
, &addr
);
3119 remote_watch_data_address
= (CORE_ADDR
)addr
;
3123 /* Silently skip unknown optional info. */
3124 p_temp
= (unsigned char *) strchr (p1
+ 1, ';');
3132 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3135 error (_("Malformed packet(b) (missing colon): %s\n\
3140 error (_("Remote sent bad register number %ld: %s\n\
3144 fieldsize
= hex2bin (p
, regs
,
3145 register_size (current_gdbarch
,
3148 if (fieldsize
< register_size (current_gdbarch
,
3150 warning (_("Remote reply is too short: %s"), buf
);
3151 regcache_raw_supply (current_regcache
, reg
->regnum
, regs
);
3155 error (_("Remote register badly formatted: %s\nhere: %s"),
3160 case 'S': /* Old style status, just signal only. */
3161 status
->kind
= TARGET_WAITKIND_STOPPED
;
3162 status
->value
.sig
= (enum target_signal
)
3163 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3167 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3168 record_currthread (thread_num
);
3171 case 'W': /* Target exited. */
3173 /* The remote process exited. */
3174 status
->kind
= TARGET_WAITKIND_EXITED
;
3175 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3179 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3180 status
->value
.sig
= (enum target_signal
)
3181 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3185 case 'O': /* Console output. */
3186 remote_console_output (buf
+ 1);
3187 /* Return immediately to the event loop. The event loop will
3188 still be waiting on the inferior afterwards. */
3189 status
->kind
= TARGET_WAITKIND_IGNORE
;
3192 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3194 /* Zero length reply means that we tried 'S' or 'C' and
3195 the remote system doesn't support it. */
3196 target_terminal_ours_for_output ();
3198 ("Can't send signals to this remote system. %s not sent.\n",
3199 target_signal_to_name (last_sent_signal
));
3200 last_sent_signal
= TARGET_SIGNAL_0
;
3201 target_terminal_inferior ();
3203 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3204 putpkt ((char *) buf
);
3207 /* else fallthrough */
3209 warning (_("Invalid remote reply: %s"), buf
);
3214 if (thread_num
!= -1)
3216 return pid_to_ptid (thread_num
);
3218 return inferior_ptid
;
3221 /* Number of bytes of registers this stub implements. */
3223 static int register_bytes_found
;
3225 /* Read the remote registers into the block REGS. */
3226 /* Currently we just read all the registers, so we don't use regnum. */
3229 fetch_register_using_p (int regnum
)
3231 struct remote_state
*rs
= get_remote_state ();
3232 char *buf
= alloca (rs
->remote_packet_size
), *p
;
3233 char regp
[MAX_REGISTER_SIZE
];
3238 p
+= hexnumstr (p
, regnum
);
3240 remote_send (buf
, rs
->remote_packet_size
);
3242 /* If the stub didn't recognize the packet, or if we got an error,
3244 if (buf
[0] == '\0' || buf
[0] == 'E')
3247 /* If this register is unfetchable, tell the regcache. */
3250 regcache_raw_supply (current_regcache
, regnum
, NULL
);
3251 set_register_cached (regnum
, -1);
3255 /* Otherwise, parse and supply the value. */
3262 error (_("fetch_register_using_p: early buf termination"));
3266 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3269 regcache_raw_supply (current_regcache
, regnum
, regp
);
3274 remote_fetch_registers (int regnum
)
3276 struct remote_state
*rs
= get_remote_state ();
3277 char *buf
= alloca (rs
->remote_packet_size
);
3280 char *regs
= alloca (rs
->sizeof_g_packet
);
3282 set_thread (PIDGET (inferior_ptid
), 1);
3286 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3287 gdb_assert (reg
!= NULL
);
3288 if (!reg
->in_g_packet
)
3289 internal_error (__FILE__
, __LINE__
,
3290 _("Attempt to fetch a non G-packet register when this "
3291 "remote.c does not support the p-packet."));
3293 switch (remote_protocol_p
.support
)
3295 case PACKET_DISABLE
:
3298 if (fetch_register_using_p (regnum
))
3301 error (_("Protocol error: p packet not recognized by stub"));
3302 case PACKET_SUPPORT_UNKNOWN
:
3303 if (fetch_register_using_p (regnum
))
3305 /* The stub recognized the 'p' packet. Remember this. */
3306 remote_protocol_p
.support
= PACKET_ENABLE
;
3311 /* The stub does not support the 'P' packet. Use 'G'
3312 instead, and don't try using 'P' in the future (it
3313 will just waste our time). */
3314 remote_protocol_p
.support
= PACKET_DISABLE
;
3320 remote_send (buf
, (rs
->remote_packet_size
));
3322 /* Save the size of the packet sent to us by the target. Its used
3323 as a heuristic when determining the max size of packets that the
3324 target can safely receive. */
3325 if ((rs
->actual_register_packet_size
) == 0)
3326 (rs
->actual_register_packet_size
) = strlen (buf
);
3328 /* Unimplemented registers read as all bits zero. */
3329 memset (regs
, 0, rs
->sizeof_g_packet
);
3331 /* We can get out of synch in various cases. If the first character
3332 in the buffer is not a hex character, assume that has happened
3333 and try to fetch another packet to read. */
3334 while ((buf
[0] < '0' || buf
[0] > '9')
3335 && (buf
[0] < 'a' || buf
[0] > 'f')
3336 && buf
[0] != 'x') /* New: unavailable register value. */
3339 fprintf_unfiltered (gdb_stdlog
,
3340 "Bad register packet; fetching a new packet\n");
3341 getpkt (buf
, (rs
->remote_packet_size
), 0);
3344 /* Reply describes registers byte by byte, each byte encoded as two
3345 hex characters. Suck them all up, then supply them to the
3346 register cacheing/storage mechanism. */
3349 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3355 warning (_("Remote reply is of odd length: %s"), buf
);
3356 /* Don't change register_bytes_found in this case, and don't
3357 print a second warning. */
3360 if (p
[0] == 'x' && p
[1] == 'x')
3361 regs
[i
] = 0; /* 'x' */
3363 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3367 if (i
!= register_bytes_found
)
3369 register_bytes_found
= i
;
3370 if (REGISTER_BYTES_OK_P ()
3371 && !REGISTER_BYTES_OK (i
))
3372 warning (_("Remote reply is too short: %s"), buf
);
3378 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3380 struct packet_reg
*r
= &rs
->regs
[i
];
3383 if (r
->offset
* 2 >= strlen (buf
))
3384 /* A short packet that didn't include the register's
3385 value, this implies that the register is zero (and
3386 not that the register is unavailable). Supply that
3388 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3389 else if (buf
[r
->offset
* 2] == 'x')
3391 gdb_assert (r
->offset
* 2 < strlen (buf
));
3392 /* The register isn't available, mark it as such (at
3393 the same time setting the value to zero). */
3394 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3395 set_register_cached (i
, -1);
3398 regcache_raw_supply (current_regcache
, r
->regnum
,
3405 /* Prepare to store registers. Since we may send them all (using a
3406 'G' request), we have to read out the ones we don't want to change
3410 remote_prepare_to_store (void)
3412 struct remote_state
*rs
= get_remote_state ();
3414 char buf
[MAX_REGISTER_SIZE
];
3416 /* Make sure the entire registers array is valid. */
3417 switch (remote_protocol_P
.support
)
3419 case PACKET_DISABLE
:
3420 case PACKET_SUPPORT_UNKNOWN
:
3421 /* Make sure all the necessary registers are cached. */
3422 for (i
= 0; i
< NUM_REGS
; i
++)
3423 if (rs
->regs
[i
].in_g_packet
)
3424 regcache_raw_read (current_regcache
, rs
->regs
[i
].regnum
, buf
);
3431 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3432 packet was not recognized. */
3435 store_register_using_P (int regnum
)
3437 struct remote_state
*rs
= get_remote_state ();
3438 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3439 /* Try storing a single register. */
3440 char *buf
= alloca (rs
->remote_packet_size
);
3441 char regp
[MAX_REGISTER_SIZE
];
3445 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3446 p
= buf
+ strlen (buf
);
3447 regcache_raw_collect (current_regcache
, reg
->regnum
, regp
);
3448 bin2hex (regp
, p
, register_size (current_gdbarch
, reg
->regnum
));
3449 remote_send (buf
, rs
->remote_packet_size
);
3451 return buf
[0] != '\0';
3455 /* Store register REGNUM, or all registers if REGNUM == -1, from the
3456 contents of the register cache buffer. FIXME: ignores errors. */
3459 remote_store_registers (int regnum
)
3461 struct remote_state
*rs
= get_remote_state ();
3467 set_thread (PIDGET (inferior_ptid
), 1);
3471 switch (remote_protocol_P
.support
)
3473 case PACKET_DISABLE
:
3476 if (store_register_using_P (regnum
))
3479 error (_("Protocol error: P packet not recognized by stub"));
3480 case PACKET_SUPPORT_UNKNOWN
:
3481 if (store_register_using_P (regnum
))
3483 /* The stub recognized the 'P' packet. Remember this. */
3484 remote_protocol_P
.support
= PACKET_ENABLE
;
3489 /* The stub does not support the 'P' packet. Use 'G'
3490 instead, and don't try using 'P' in the future (it
3491 will just waste our time). */
3492 remote_protocol_P
.support
= PACKET_DISABLE
;
3498 /* Extract all the registers in the regcache copying them into a
3502 regs
= alloca (rs
->sizeof_g_packet
);
3503 memset (regs
, rs
->sizeof_g_packet
, 0);
3504 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3506 struct packet_reg
*r
= &rs
->regs
[i
];
3508 regcache_raw_collect (current_regcache
, r
->regnum
, regs
+ r
->offset
);
3512 /* Command describes registers byte by byte,
3513 each byte encoded as two hex characters. */
3514 buf
= alloca (rs
->remote_packet_size
);
3517 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3518 bin2hex (regs
, p
, register_bytes_found
);
3519 remote_send (buf
, (rs
->remote_packet_size
));
3523 /* Return the number of hex digits in num. */
3526 hexnumlen (ULONGEST num
)
3530 for (i
= 0; num
!= 0; i
++)
3536 /* Set BUF to the minimum number of hex digits representing NUM. */
3539 hexnumstr (char *buf
, ULONGEST num
)
3541 int len
= hexnumlen (num
);
3542 return hexnumnstr (buf
, num
, len
);
3546 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3549 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3555 for (i
= width
- 1; i
>= 0; i
--)
3557 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3564 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3567 remote_address_masked (CORE_ADDR addr
)
3569 if (remote_address_size
> 0
3570 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3572 /* Only create a mask when that mask can safely be constructed
3573 in a ULONGEST variable. */
3575 mask
= (mask
<< remote_address_size
) - 1;
3581 /* Determine whether the remote target supports binary downloading.
3582 This is accomplished by sending a no-op memory write of zero length
3583 to the target at the specified address. It does not suffice to send
3584 the whole packet, since many stubs strip the eighth bit and
3585 subsequently compute a wrong checksum, which causes real havoc with
3588 NOTE: This can still lose if the serial line is not eight-bit
3589 clean. In cases like this, the user should clear "remote
3593 check_binary_download (CORE_ADDR addr
)
3595 struct remote_state
*rs
= get_remote_state ();
3596 switch (remote_protocol_binary_download
.support
)
3598 case PACKET_DISABLE
:
3602 case PACKET_SUPPORT_UNKNOWN
:
3604 char *buf
= alloca (rs
->remote_packet_size
);
3609 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3611 p
+= hexnumstr (p
, (ULONGEST
) 0);
3615 putpkt_binary (buf
, (int) (p
- buf
));
3616 getpkt (buf
, (rs
->remote_packet_size
), 0);
3621 fprintf_unfiltered (gdb_stdlog
,
3622 "binary downloading NOT suppported by target\n");
3623 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3628 fprintf_unfiltered (gdb_stdlog
,
3629 "binary downloading suppported by target\n");
3630 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3637 /* Write memory data directly to the remote machine.
3638 This does not inform the data cache; the data cache uses this.
3639 MEMADDR is the address in the remote memory space.
3640 MYADDR is the address of the buffer in our space.
3641 LEN is the number of bytes.
3643 Returns number of bytes transferred, or 0 (setting errno) for
3644 error. Only transfer a single packet. */
3647 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3651 unsigned char *plen
;
3657 unsigned char *payload_start
;
3659 /* Verify that the target can support a binary download. */
3660 check_binary_download (memaddr
);
3662 /* Compute the size, and then allocate space for the largest
3663 possible packet. Include space for an extra trailing NULL. */
3664 sizeof_buf
= get_memory_write_packet_size () + 1;
3665 buf
= alloca (sizeof_buf
);
3667 /* Compute the size of the actual payload by subtracting out the
3668 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
3669 payload_size
= (get_memory_write_packet_size () - (strlen ("$M,:#NN")
3670 + hexnumlen (memaddr
)
3671 + hexnumlen (len
)));
3673 /* Construct the packet header: "[MX]<memaddr>,<len>:". */
3675 /* Append "[XM]". Compute a best guess of the number of bytes
3676 actually transfered. */
3678 switch (remote_protocol_binary_download
.support
)
3682 /* Best guess at number of bytes that will fit. */
3683 todo
= min (len
, payload_size
);
3685 case PACKET_DISABLE
:
3687 /* Num bytes that will fit. */
3688 todo
= min (len
, payload_size
/ 2);
3690 case PACKET_SUPPORT_UNKNOWN
:
3691 internal_error (__FILE__
, __LINE__
,
3692 _("remote_write_bytes: bad internal state"));
3694 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3697 /* Append "<memaddr>". */
3698 memaddr
= remote_address_masked (memaddr
);
3699 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3704 /* Append <len>. Retain the location/size of <len>. It may need to
3705 be adjusted once the packet body has been created. */
3707 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3714 /* Append the packet body. */
3716 switch (remote_protocol_binary_download
.support
)
3719 /* Binary mode. Send target system values byte by byte, in
3720 increasing byte addresses. Only escape certain critical
3723 (nr_bytes
< todo
) && (p
- payload_start
) < payload_size
;
3726 switch (myaddr
[nr_bytes
] & 0xff)
3731 /* These must be escaped. */
3733 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3736 *p
++ = myaddr
[nr_bytes
] & 0xff;
3740 if (nr_bytes
< todo
)
3742 /* Escape chars have filled up the buffer prematurely,
3743 and we have actually sent fewer bytes than planned.
3744 Fix-up the length field of the packet. Use the same
3745 number of characters as before. */
3746 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3747 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3750 case PACKET_DISABLE
:
3751 /* Normal mode: Send target system values byte by byte, in
3752 increasing byte addresses. Each byte is encoded as a two hex
3754 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3757 case PACKET_SUPPORT_UNKNOWN
:
3758 internal_error (__FILE__
, __LINE__
,
3759 _("remote_write_bytes: bad internal state"));
3761 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3764 putpkt_binary (buf
, (int) (p
- buf
));
3765 getpkt (buf
, sizeof_buf
, 0);
3769 /* There is no correspondance between what the remote protocol
3770 uses for errors and errno codes. We would like a cleaner way
3771 of representing errors (big enough to include errno codes,
3772 bfd_error codes, and others). But for now just return EIO. */
3777 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
3778 fewer bytes than we'd planned. */
3782 /* Read memory data directly from the remote machine.
3783 This does not use the data cache; the data cache uses this.
3784 MEMADDR is the address in the remote memory space.
3785 MYADDR is the address of the buffer in our space.
3786 LEN is the number of bytes.
3788 Returns number of bytes transferred, or 0 for error. */
3790 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3791 remote targets) shouldn't attempt to read the entire buffer.
3792 Instead it should read a single packet worth of data and then
3793 return the byte size of that packet to the caller. The caller (its
3794 caller and its callers caller ;-) already contains code for
3795 handling partial reads. */
3798 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3801 int max_buf_size
; /* Max size of packet output buffer. */
3805 /* Create a buffer big enough for this packet. */
3806 max_buf_size
= get_memory_read_packet_size ();
3807 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NULL. */
3808 buf
= alloca (sizeof_buf
);
3817 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3819 /* construct "m"<memaddr>","<len>" */
3820 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3821 memaddr
= remote_address_masked (memaddr
);
3824 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3826 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3830 getpkt (buf
, sizeof_buf
, 0);
3833 && isxdigit (buf
[1]) && isxdigit (buf
[2])
3836 /* There is no correspondance between what the remote
3837 protocol uses for errors and errno codes. We would like
3838 a cleaner way of representing errors (big enough to
3839 include errno codes, bfd_error codes, and others). But
3840 for now just return EIO. */
3845 /* Reply describes memory byte by byte,
3846 each byte encoded as two hex characters. */
3849 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3851 /* Reply is short. This means that we were able to read
3852 only part of what we wanted to. */
3853 return i
+ (origlen
- len
);
3862 /* Read or write LEN bytes from inferior memory at MEMADDR,
3863 transferring to or from debugger address BUFFER. Write to inferior
3864 if SHOULD_WRITE is nonzero. Returns length of data written or
3865 read; 0 for error. TARGET is unused. */
3868 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3869 int should_write
, struct mem_attrib
*attrib
,
3870 struct target_ops
*target
)
3872 CORE_ADDR targ_addr
;
3876 /* Should this be the selected frame? */
3877 gdbarch_remote_translate_xfer_address (current_gdbarch
,
3880 &targ_addr
, &targ_len
);
3885 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3887 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3893 remote_files_info (struct target_ops
*ignore
)
3895 puts_filtered ("Debugging a target over a serial line.\n");
3898 /* Stuff for dealing with the packets which are part of this protocol.
3899 See comment at top of file for details. */
3901 /* Read a single character from the remote end, masking it down to 7
3905 readchar (int timeout
)
3909 ch
= serial_readchar (remote_desc
, timeout
);
3914 switch ((enum serial_rc
) ch
)
3917 target_mourn_inferior ();
3918 error (_("Remote connection closed"));
3921 perror_with_name (_("Remote communication error"));
3923 case SERIAL_TIMEOUT
:
3929 /* Send the command in BUF to the remote machine, and read the reply
3930 into BUF. Report an error if we get an error reply. */
3933 remote_send (char *buf
,
3937 getpkt (buf
, sizeof_buf
, 0);
3940 error (_("Remote failure reply: %s"), buf
);
3943 /* Display a null-terminated packet on stdout, for debugging, using C
3947 print_packet (char *buf
)
3949 puts_filtered ("\"");
3950 fputstr_filtered (buf
, '"', gdb_stdout
);
3951 puts_filtered ("\"");
3957 return putpkt_binary (buf
, strlen (buf
));
3960 /* Send a packet to the remote machine, with error checking. The data
3961 of the packet is in BUF. The string in BUF can be at most
3962 (rs->remote_packet_size) - 5 to account for the $, # and checksum,
3963 and for a possible /0 if we are debugging (remote_debug) and want
3964 to print the sent packet as a string. */
3967 putpkt_binary (char *buf
, int cnt
)
3969 struct remote_state
*rs
= get_remote_state ();
3971 unsigned char csum
= 0;
3972 char *buf2
= alloca (cnt
+ 6);
3973 long sizeof_junkbuf
= (rs
->remote_packet_size
);
3974 char *junkbuf
= alloca (sizeof_junkbuf
);
3980 /* Copy the packet into buffer BUF2, encapsulating it
3981 and giving it a checksum. */
3986 for (i
= 0; i
< cnt
; i
++)
3992 *p
++ = tohex ((csum
>> 4) & 0xf);
3993 *p
++ = tohex (csum
& 0xf);
3995 /* Send it over and over until we get a positive ack. */
3999 int started_error_output
= 0;
4004 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4005 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4006 fprintf_unfiltered (gdb_stdlog
, "...");
4007 gdb_flush (gdb_stdlog
);
4009 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4010 perror_with_name (_("putpkt: write failed"));
4012 /* Read until either a timeout occurs (-2) or '+' is read. */
4015 ch
= readchar (remote_timeout
);
4023 case SERIAL_TIMEOUT
:
4025 if (started_error_output
)
4027 putchar_unfiltered ('\n');
4028 started_error_output
= 0;
4037 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4041 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4042 case SERIAL_TIMEOUT
:
4046 break; /* Retransmit buffer. */
4050 fprintf_unfiltered (gdb_stdlog
,
4051 "Packet instead of Ack, ignoring it\n");
4052 /* It's probably an old response sent because an ACK
4053 was lost. Gobble up the packet and ack it so it
4054 doesn't get retransmitted when we resend this
4056 read_frame (junkbuf
, sizeof_junkbuf
);
4057 serial_write (remote_desc
, "+", 1);
4058 continue; /* Now, go look for +. */
4063 if (!started_error_output
)
4065 started_error_output
= 1;
4066 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4068 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4072 break; /* Here to retransmit. */
4076 /* This is wrong. If doing a long backtrace, the user should be
4077 able to get out next time we call QUIT, without anything as
4078 violent as interrupt_query. If we want to provide a way out of
4079 here without getting to the next QUIT, it should be based on
4080 hitting ^C twice as in remote_wait. */
4090 /* Come here after finding the start of the frame. Collect the rest
4091 into BUF, verifying the checksum, length, and handling run-length
4092 compression. No more than sizeof_buf-1 characters are read so that
4093 the buffer can be NUL terminated.
4095 Returns -1 on error, number of characters in buffer (ignoring the
4096 trailing NULL) on success. (could be extended to return one of the
4097 SERIAL status indications). */
4100 read_frame (char *buf
,
4112 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NULL. */
4113 c
= readchar (remote_timeout
);
4116 case SERIAL_TIMEOUT
:
4118 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4122 fputs_filtered ("Saw new packet start in middle of old one\n",
4124 return -1; /* Start a new packet, count retries. */
4127 unsigned char pktcsum
;
4133 check_0
= readchar (remote_timeout
);
4135 check_1
= readchar (remote_timeout
);
4137 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4140 fputs_filtered ("Timeout in checksum, retrying\n",
4144 else if (check_0
< 0 || check_1
< 0)
4147 fputs_filtered ("Communication error in checksum\n",
4152 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4153 if (csum
== pktcsum
)
4158 fprintf_filtered (gdb_stdlog
,
4159 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4161 fputs_filtered (buf
, gdb_stdlog
);
4162 fputs_filtered ("\n", gdb_stdlog
);
4164 /* Number of characters in buffer ignoring trailing
4168 case '*': /* Run length encoding. */
4173 c
= readchar (remote_timeout
);
4175 repeat
= c
- ' ' + 3; /* Compute repeat count. */
4177 /* The character before ``*'' is repeated. */
4179 if (repeat
> 0 && repeat
<= 255
4181 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4183 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4189 printf_filtered (_("Repeat count %d too large for buffer: "),
4191 puts_filtered (buf
);
4192 puts_filtered ("\n");
4196 if (bc
< sizeof_buf
- 1)
4204 puts_filtered ("Remote packet too long: ");
4205 puts_filtered (buf
);
4206 puts_filtered ("\n");
4213 /* Read a packet from the remote machine, with error checking, and
4214 store it in BUF. If FOREVER, wait forever rather than timing out;
4215 this is used (in synchronous mode) to wait for a target that is is
4216 executing user code to stop. */
4217 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4218 don't have to change all the calls to getpkt to deal with the
4219 return value, because at the moment I don't know what the right
4220 thing to do it for those. */
4228 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4232 /* Read a packet from the remote machine, with error checking, and
4233 store it in BUF. If FOREVER, wait forever rather than timing out;
4234 this is used (in synchronous mode) to wait for a target that is is
4235 executing user code to stop. If FOREVER == 0, this function is
4236 allowed to time out gracefully and return an indication of this to
4239 getpkt_sane (char *buf
,
4248 strcpy (buf
, "timeout");
4252 timeout
= watchdog
> 0 ? watchdog
: -1;
4256 timeout
= remote_timeout
;
4260 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4262 /* This can loop forever if the remote side sends us characters
4263 continuously, but if it pauses, we'll get a zero from
4264 readchar because of timeout. Then we'll count that as a
4267 /* Note that we will only wait forever prior to the start of a
4268 packet. After that, we expect characters to arrive at a
4269 brisk pace. They should show up within remote_timeout
4274 c
= readchar (timeout
);
4276 if (c
== SERIAL_TIMEOUT
)
4278 if (forever
) /* Watchdog went off? Kill the target. */
4281 target_mourn_inferior ();
4282 error (_("Watchdog has expired. Target detached."));
4285 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4291 /* We've found the start of a packet, now collect the data. */
4293 val
= read_frame (buf
, sizeof_buf
);
4299 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4300 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4301 fprintf_unfiltered (gdb_stdlog
, "\n");
4303 serial_write (remote_desc
, "+", 1);
4307 /* Try the whole thing again. */
4309 serial_write (remote_desc
, "-", 1);
4312 /* We have tried hard enough, and just can't receive the packet.
4315 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
4316 serial_write (remote_desc
, "+", 1);
4323 /* For some mysterious reason, wait_for_inferior calls kill instead of
4324 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4328 target_mourn_inferior ();
4332 /* Use catch_errors so the user can quit from gdb even when we aren't on
4333 speaking terms with the remote system. */
4334 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4336 /* Don't wait for it to die. I'm not really sure it matters whether
4337 we do or not. For the existing stubs, kill is a noop. */
4338 target_mourn_inferior ();
4341 /* Async version of remote_kill. */
4343 remote_async_kill (void)
4345 /* Unregister the file descriptor from the event loop. */
4346 if (target_is_async_p ())
4347 serial_async (remote_desc
, NULL
, 0);
4349 /* For some mysterious reason, wait_for_inferior calls kill instead of
4350 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4354 target_mourn_inferior ();
4358 /* Use catch_errors so the user can quit from gdb even when we
4359 aren't on speaking terms with the remote system. */
4360 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4362 /* Don't wait for it to die. I'm not really sure it matters whether
4363 we do or not. For the existing stubs, kill is a noop. */
4364 target_mourn_inferior ();
4370 remote_mourn_1 (&remote_ops
);
4374 remote_async_mourn (void)
4376 remote_mourn_1 (&remote_async_ops
);
4380 extended_remote_mourn (void)
4382 /* We do _not_ want to mourn the target like this; this will
4383 remove the extended remote target from the target stack,
4384 and the next time the user says "run" it'll fail.
4386 FIXME: What is the right thing to do here? */
4388 remote_mourn_1 (&extended_remote_ops
);
4392 /* Worker function for remote_mourn. */
4394 remote_mourn_1 (struct target_ops
*target
)
4396 unpush_target (target
);
4397 generic_mourn_inferior ();
4400 /* In the extended protocol we want to be able to do things like
4401 "run" and have them basically work as expected. So we need
4402 a special create_inferior function.
4404 FIXME: One day add support for changing the exec file
4405 we're debugging, arguments and an environment. */
4408 extended_remote_create_inferior (char *exec_file
, char *args
,
4409 char **env
, int from_tty
)
4411 /* Rip out the breakpoints; we'll reinsert them after restarting
4412 the remote server. */
4413 remove_breakpoints ();
4415 /* Now restart the remote server. */
4416 extended_remote_restart ();
4418 /* Now put the breakpoints back in. This way we're safe if the
4419 restart function works via a unix fork on the remote side. */
4420 insert_breakpoints ();
4422 /* Clean up from the last time we were running. */
4423 clear_proceed_status ();
4425 /* Let the remote process run. */
4426 proceed (-1, TARGET_SIGNAL_0
, 0);
4429 /* Async version of extended_remote_create_inferior. */
4431 extended_remote_async_create_inferior (char *exec_file
, char *args
,
4432 char **env
, int from_tty
)
4434 /* Rip out the breakpoints; we'll reinsert them after restarting
4435 the remote server. */
4436 remove_breakpoints ();
4438 /* If running asynchronously, register the target file descriptor
4439 with the event loop. */
4440 if (target_can_async_p ())
4441 target_async (inferior_event_handler
, 0);
4443 /* Now restart the remote server. */
4444 extended_remote_restart ();
4446 /* Now put the breakpoints back in. This way we're safe if the
4447 restart function works via a unix fork on the remote side. */
4448 insert_breakpoints ();
4450 /* Clean up from the last time we were running. */
4451 clear_proceed_status ();
4453 /* Let the remote process run. */
4454 proceed (-1, TARGET_SIGNAL_0
, 0);
4458 /* On some machines, e.g. 68k, we may use a different breakpoint
4459 instruction than other targets; in those use
4460 DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
4461 Also, bi-endian targets may define
4462 DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
4463 DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we
4464 just call the standard routines that are in mem-break.c. */
4466 /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator
4467 target should use an identical BREAKPOINT_FROM_PC. As for native,
4468 the ARCH-OS-tdep.c code can override the default. */
4470 #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
4471 #define DEPRECATED_REMOTE_BREAKPOINT
4474 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4476 /* If the target isn't bi-endian, just pretend it is. */
4477 #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
4478 #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4479 #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4482 static unsigned char big_break_insn
[] = DEPRECATED_BIG_REMOTE_BREAKPOINT
;
4483 static unsigned char little_break_insn
[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT
;
4485 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4487 /* Insert a breakpoint on targets that don't have any better
4488 breakpoint support. We read the contents of the target location
4489 and stash it, then overwrite it with a breakpoint instruction.
4490 ADDR is the target location in the target machine. CONTENTS_CACHE
4491 is a pointer to memory allocated for saving the target contents.
4492 It is guaranteed by the caller to be long enough to save the number
4493 of bytes returned by BREAKPOINT_FROM_PC. */
4496 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4498 struct remote_state
*rs
= get_remote_state ();
4499 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4504 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4505 If it succeeds, then set the support to PACKET_ENABLE. If it
4506 fails, and the user has explicitly requested the Z support then
4507 report an error, otherwise, mark it disabled and go on. */
4509 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4511 char *buf
= alloca (rs
->remote_packet_size
);
4514 addr
= remote_address_masked (addr
);
4518 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4519 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4520 sprintf (p
, ",%d", bp_size
);
4523 getpkt (buf
, (rs
->remote_packet_size
), 0);
4525 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4531 case PACKET_UNKNOWN
:
4536 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4537 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4541 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4542 val
= target_write_memory (addr
, (char *) big_break_insn
,
4543 sizeof big_break_insn
);
4545 val
= target_write_memory (addr
, (char *) little_break_insn
,
4546 sizeof little_break_insn
);
4551 return memory_insert_breakpoint (addr
, contents_cache
);
4552 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4556 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4558 struct remote_state
*rs
= get_remote_state ();
4561 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4563 char *buf
= alloca (rs
->remote_packet_size
);
4570 addr
= remote_address_masked (addr
);
4571 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4572 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4573 sprintf (p
, ",%d", bp_size
);
4576 getpkt (buf
, (rs
->remote_packet_size
), 0);
4578 return (buf
[0] == 'E');
4581 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4582 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4584 return memory_remove_breakpoint (addr
, contents_cache
);
4585 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4589 watchpoint_to_Z_packet (int type
)
4603 internal_error (__FILE__
, __LINE__
,
4604 _("hw_bp_to_z: bad watchpoint type %d"), type
);
4609 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4611 struct remote_state
*rs
= get_remote_state ();
4612 char *buf
= alloca (rs
->remote_packet_size
);
4614 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4616 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4617 error (_("Can't set hardware watchpoints without the '%s' (%s) packet."),
4618 remote_protocol_Z
[packet
].name
,
4619 remote_protocol_Z
[packet
].title
);
4621 sprintf (buf
, "Z%x,", packet
);
4622 p
= strchr (buf
, '\0');
4623 addr
= remote_address_masked (addr
);
4624 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4625 sprintf (p
, ",%x", len
);
4628 getpkt (buf
, (rs
->remote_packet_size
), 0);
4630 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4633 case PACKET_UNKNOWN
:
4638 internal_error (__FILE__
, __LINE__
,
4639 _("remote_insert_watchpoint: reached end of function"));
4644 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4646 struct remote_state
*rs
= get_remote_state ();
4647 char *buf
= alloca (rs
->remote_packet_size
);
4649 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4651 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4652 error (_("Can't clear hardware watchpoints without the '%s' (%s) packet."),
4653 remote_protocol_Z
[packet
].name
,
4654 remote_protocol_Z
[packet
].title
);
4656 sprintf (buf
, "z%x,", packet
);
4657 p
= strchr (buf
, '\0');
4658 addr
= remote_address_masked (addr
);
4659 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4660 sprintf (p
, ",%x", len
);
4662 getpkt (buf
, (rs
->remote_packet_size
), 0);
4664 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4667 case PACKET_UNKNOWN
:
4672 internal_error (__FILE__
, __LINE__
,
4673 _("remote_remove_watchpoint: reached end of function"));
4677 int remote_hw_watchpoint_limit
= -1;
4678 int remote_hw_breakpoint_limit
= -1;
4681 remote_check_watch_resources (int type
, int cnt
, int ot
)
4683 if (type
== bp_hardware_breakpoint
)
4685 if (remote_hw_breakpoint_limit
== 0)
4687 else if (remote_hw_breakpoint_limit
< 0)
4689 else if (cnt
<= remote_hw_breakpoint_limit
)
4694 if (remote_hw_watchpoint_limit
== 0)
4696 else if (remote_hw_watchpoint_limit
< 0)
4700 else if (cnt
<= remote_hw_watchpoint_limit
)
4707 remote_stopped_by_watchpoint (void)
4709 return remote_stopped_by_watchpoint_p
;
4712 extern int stepped_after_stopped_by_watchpoint
;
4715 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
4718 if (remote_stopped_by_watchpoint ()
4719 || stepped_after_stopped_by_watchpoint
)
4721 *addr_p
= remote_watch_data_address
;
4730 remote_insert_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4733 struct remote_state
*rs
= get_remote_state ();
4734 char *buf
= alloca (rs
->remote_packet_size
);
4737 /* The length field should be set to the size of a breakpoint
4740 BREAKPOINT_FROM_PC (&addr
, &len
);
4742 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4743 error (_("Can't set hardware breakpoint without the '%s' (%s) packet."),
4744 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4745 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4751 addr
= remote_address_masked (addr
);
4752 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4753 sprintf (p
, ",%x", len
);
4756 getpkt (buf
, (rs
->remote_packet_size
), 0);
4758 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4761 case PACKET_UNKNOWN
:
4766 internal_error (__FILE__
, __LINE__
,
4767 _("remote_insert_hw_breakpoint: reached end of function"));
4772 remote_remove_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4775 struct remote_state
*rs
= get_remote_state ();
4776 char *buf
= alloca (rs
->remote_packet_size
);
4779 /* The length field should be set to the size of a breakpoint
4782 BREAKPOINT_FROM_PC (&addr
, &len
);
4784 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4785 error (_("Can't clear hardware breakpoint without the '%s' (%s) packet."),
4786 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4787 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4793 addr
= remote_address_masked (addr
);
4794 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4795 sprintf (p
, ",%x", len
);
4798 getpkt (buf
, (rs
->remote_packet_size
), 0);
4800 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4803 case PACKET_UNKNOWN
:
4808 internal_error (__FILE__
, __LINE__
,
4809 _("remote_remove_hw_breakpoint: reached end of function"));
4812 /* Some targets are only capable of doing downloads, and afterwards
4813 they switch to the remote serial protocol. This function provides
4814 a clean way to get from the download target to the remote target.
4815 It's basically just a wrapper so that we don't have to expose any
4816 of the internal workings of remote.c.
4818 Prior to calling this routine, you should shutdown the current
4819 target code, else you will get the "A program is being debugged
4820 already..." message. Usually a call to pop_target() suffices. */
4823 push_remote_target (char *name
, int from_tty
)
4825 printf_filtered (_("Switching to remote protocol\n"));
4826 remote_open (name
, from_tty
);
4829 /* Table used by the crc32 function to calcuate the checksum. */
4831 static unsigned long crc32_table
[256] =
4834 static unsigned long
4835 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4837 if (!crc32_table
[1])
4839 /* Initialize the CRC table and the decoding table. */
4843 for (i
= 0; i
< 256; i
++)
4845 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4846 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4853 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4859 /* compare-sections command
4861 With no arguments, compares each loadable section in the exec bfd
4862 with the same memory range on the target, and reports mismatches.
4863 Useful for verifying the image on the target against the exec file.
4864 Depends on the target understanding the new "qCRC:" request. */
4866 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4867 target method (target verify memory) and generic version of the
4868 actual command. This will allow other high-level code (especially
4869 generic_load()) to make use of this target functionality. */
4872 compare_sections_command (char *args
, int from_tty
)
4874 struct remote_state
*rs
= get_remote_state ();
4876 unsigned long host_crc
, target_crc
;
4877 extern bfd
*exec_bfd
;
4878 struct cleanup
*old_chain
;
4881 const char *sectname
;
4882 char *buf
= alloca (rs
->remote_packet_size
);
4889 error (_("command cannot be used without an exec file"));
4890 if (!current_target
.to_shortname
||
4891 strcmp (current_target
.to_shortname
, "remote") != 0)
4892 error (_("command can only be used with remote target"));
4894 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4896 if (!(s
->flags
& SEC_LOAD
))
4897 continue; /* skip non-loadable section */
4899 size
= bfd_get_section_size (s
);
4901 continue; /* skip zero-length section */
4903 sectname
= bfd_get_section_name (exec_bfd
, s
);
4904 if (args
&& strcmp (args
, sectname
) != 0)
4905 continue; /* not the section selected by user */
4907 matched
= 1; /* do this section */
4909 /* FIXME: assumes lma can fit into long. */
4910 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
4913 /* Be clever; compute the host_crc before waiting for target
4915 sectdata
= xmalloc (size
);
4916 old_chain
= make_cleanup (xfree
, sectdata
);
4917 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4918 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4920 getpkt (buf
, (rs
->remote_packet_size
), 0);
4922 error (_("target memory fault, section %s, range 0x%s -- 0x%s"),
4923 sectname
, paddr (lma
), paddr (lma
+ size
));
4925 error (_("remote target does not support this operation"));
4927 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4928 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4930 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4931 sectname
, paddr (lma
), paddr (lma
+ size
));
4932 if (host_crc
== target_crc
)
4933 printf_filtered ("matched.\n");
4936 printf_filtered ("MIS-MATCHED!\n");
4940 do_cleanups (old_chain
);
4943 warning (_("One or more sections of the remote executable does not match\n\
4944 the loaded file\n"));
4945 if (args
&& !matched
)
4946 printf_filtered (_("No loaded section named '%s'.\n"), args
);
4950 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
4951 const char *annex
, void *readbuf
, const void *writebuf
,
4952 ULONGEST offset
, LONGEST len
)
4954 struct remote_state
*rs
= get_remote_state ();
4956 char *buf2
= alloca (rs
->remote_packet_size
);
4957 char *p2
= &buf2
[0];
4960 /* Handle memory using remote_xfer_memory. */
4961 if (object
== TARGET_OBJECT_MEMORY
)
4966 if (writebuf
!= NULL
)
4968 void *buffer
= xmalloc (len
);
4969 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
4970 memcpy (buffer
, writebuf
, len
);
4971 xfered
= remote_xfer_memory (offset
, buffer
, len
, 1, NULL
, ops
);
4972 do_cleanups (cleanup
);
4975 xfered
= remote_xfer_memory (offset
, readbuf
, len
, 0, NULL
, ops
);
4979 else if (xfered
== 0 && errno
== 0)
4985 /* Only handle reads. */
4986 if (writebuf
!= NULL
|| readbuf
== NULL
)
4989 /* Map pre-existing objects onto letters. DO NOT do this for new
4990 objects!!! Instead specify new query packets. */
4993 case TARGET_OBJECT_KOD
:
4996 case TARGET_OBJECT_AVR
:
5000 case TARGET_OBJECT_AUXV
:
5001 if (remote_protocol_qPart_auxv
.support
!= PACKET_DISABLE
)
5003 unsigned int total
= 0;
5006 LONGEST n
= min ((rs
->remote_packet_size
- 2) / 2, len
);
5007 snprintf (buf2
, rs
->remote_packet_size
,
5008 "qPart:auxv:read::%s,%s",
5009 phex_nz (offset
, sizeof offset
),
5010 phex_nz (n
, sizeof n
));
5013 return total
> 0 ? total
: i
;
5015 getpkt (buf2
, rs
->remote_packet_size
, 0);
5016 if (packet_ok (buf2
, &remote_protocol_qPart_auxv
) != PACKET_OK
)
5017 return total
> 0 ? total
: -1;
5018 if (buf2
[0] == 'O' && buf2
[1] == 'K' && buf2
[2] == '\0')
5019 break; /* Got EOF indicator. */
5020 /* Got some data. */
5021 i
= hex2bin (buf2
, readbuf
, len
);
5024 readbuf
= (void *) ((char *) readbuf
+ i
);
5038 /* Note: a zero OFFSET and LEN can be used to query the minimum
5040 if (offset
== 0 && len
== 0)
5041 return (rs
->remote_packet_size
);
5042 /* Minimum outbuf size is (rs->remote_packet_size) - if bufsiz is
5043 not large enough let the caller. */
5044 if (len
< (rs
->remote_packet_size
))
5046 len
= rs
->remote_packet_size
;
5048 /* Except for querying the minimum buffer size, target must be open. */
5050 error (_("remote query is only available after target open"));
5052 gdb_assert (annex
!= NULL
);
5053 gdb_assert (readbuf
!= NULL
);
5058 /* We used one buffer char for the remote protocol q command and
5059 another for the query type. As the remote protocol encapsulation
5060 uses 4 chars plus one extra in case we are debugging
5061 (remote_debug), we have PBUFZIZ - 7 left to pack the query
5064 while (annex
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5066 /* Bad caller may have sent forbidden characters. */
5067 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
5072 gdb_assert (annex
[i
] == '\0');
5078 getpkt (readbuf
, len
, 0);
5080 return strlen (readbuf
);
5084 remote_rcmd (char *command
,
5085 struct ui_file
*outbuf
)
5087 struct remote_state
*rs
= get_remote_state ();
5089 char *buf
= alloca (rs
->remote_packet_size
);
5093 error (_("remote rcmd is only available after target open"));
5095 /* Send a NULL command across as an empty command. */
5096 if (command
== NULL
)
5099 /* The query prefix. */
5100 strcpy (buf
, "qRcmd,");
5101 p
= strchr (buf
, '\0');
5103 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5104 error (_("\"monitor\" command ``%s'' is too long."), command
);
5106 /* Encode the actual command. */
5107 bin2hex (command
, p
, 0);
5109 if (putpkt (buf
) < 0)
5110 error (_("Communication problem with target."));
5112 /* get/display the response */
5115 /* XXX - see also tracepoint.c:remote_get_noisy_reply(). */
5117 getpkt (buf
, (rs
->remote_packet_size
), 0);
5119 error (_("Target does not support this command."));
5120 if (buf
[0] == 'O' && buf
[1] != 'K')
5122 remote_console_output (buf
+ 1); /* 'O' message from stub. */
5125 if (strcmp (buf
, "OK") == 0)
5127 if (strlen (buf
) == 3 && buf
[0] == 'E'
5128 && isdigit (buf
[1]) && isdigit (buf
[2]))
5130 error (_("Protocol error with Rcmd"));
5132 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5134 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5135 fputc_unfiltered (c
, outbuf
);
5142 packet_command (char *args
, int from_tty
)
5144 struct remote_state
*rs
= get_remote_state ();
5145 char *buf
= alloca (rs
->remote_packet_size
);
5148 error (_("command can only be used with remote target"));
5151 error (_("remote-packet command requires packet text as argument"));
5153 puts_filtered ("sending: ");
5154 print_packet (args
);
5155 puts_filtered ("\n");
5158 getpkt (buf
, (rs
->remote_packet_size
), 0);
5159 puts_filtered ("received: ");
5161 puts_filtered ("\n");
5165 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
5167 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5169 static void threadset_test_cmd (char *cmd
, int tty
);
5171 static void threadalive_test (char *cmd
, int tty
);
5173 static void threadlist_test_cmd (char *cmd
, int tty
);
5175 int get_and_display_threadinfo (threadref
*ref
);
5177 static void threadinfo_test_cmd (char *cmd
, int tty
);
5179 static int thread_display_step (threadref
*ref
, void *context
);
5181 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5183 static void init_remote_threadtests (void);
5185 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
5188 threadset_test_cmd (char *cmd
, int tty
)
5190 int sample_thread
= SAMPLE_THREAD
;
5192 printf_filtered (_("Remote threadset test\n"));
5193 set_thread (sample_thread
, 1);
5198 threadalive_test (char *cmd
, int tty
)
5200 int sample_thread
= SAMPLE_THREAD
;
5202 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5203 printf_filtered ("PASS: Thread alive test\n");
5205 printf_filtered ("FAIL: Thread alive test\n");
5208 void output_threadid (char *title
, threadref
*ref
);
5211 output_threadid (char *title
, threadref
*ref
)
5215 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
5217 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5221 threadlist_test_cmd (char *cmd
, int tty
)
5224 threadref nextthread
;
5225 int done
, result_count
;
5226 threadref threadlist
[3];
5228 printf_filtered ("Remote Threadlist test\n");
5229 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5230 &result_count
, &threadlist
[0]))
5231 printf_filtered ("FAIL: threadlist test\n");
5234 threadref
*scan
= threadlist
;
5235 threadref
*limit
= scan
+ result_count
;
5237 while (scan
< limit
)
5238 output_threadid (" thread ", scan
++);
5243 display_thread_info (struct gdb_ext_thread_info
*info
)
5245 output_threadid ("Threadid: ", &info
->threadid
);
5246 printf_filtered ("Name: %s\n ", info
->shortname
);
5247 printf_filtered ("State: %s\n", info
->display
);
5248 printf_filtered ("other: %s\n\n", info
->more_display
);
5252 get_and_display_threadinfo (threadref
*ref
)
5256 struct gdb_ext_thread_info threadinfo
;
5258 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5259 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5260 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5261 display_thread_info (&threadinfo
);
5266 threadinfo_test_cmd (char *cmd
, int tty
)
5268 int athread
= SAMPLE_THREAD
;
5272 int_to_threadref (&thread
, athread
);
5273 printf_filtered ("Remote Threadinfo test\n");
5274 if (!get_and_display_threadinfo (&thread
))
5275 printf_filtered ("FAIL cannot get thread info\n");
5279 thread_display_step (threadref
*ref
, void *context
)
5281 /* output_threadid(" threadstep ",ref); *//* simple test */
5282 return get_and_display_threadinfo (ref
);
5286 threadlist_update_test_cmd (char *cmd
, int tty
)
5288 printf_filtered ("Remote Threadlist update test\n");
5289 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5293 init_remote_threadtests (void)
5295 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
5296 Fetch and print the remote list of thread identifiers, one pkt only"));
5297 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5298 _("Fetch and display info about one thread"));
5299 add_com ("tset", class_obscure
, threadset_test_cmd
,
5300 _("Test setting to a different thread"));
5301 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5302 _("Iterate through updating all remote thread info"));
5303 add_com ("talive", class_obscure
, threadalive_test
,
5304 _(" Remote thread alive test "));
5309 /* Convert a thread ID to a string. Returns the string in a static
5313 remote_pid_to_str (ptid_t ptid
)
5315 static char buf
[30];
5317 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5322 init_remote_ops (void)
5324 remote_ops
.to_shortname
= "remote";
5325 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5327 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5328 Specify the serial device it is connected to\n\
5329 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5330 remote_ops
.to_open
= remote_open
;
5331 remote_ops
.to_close
= remote_close
;
5332 remote_ops
.to_detach
= remote_detach
;
5333 remote_ops
.to_disconnect
= remote_disconnect
;
5334 remote_ops
.to_resume
= remote_resume
;
5335 remote_ops
.to_wait
= remote_wait
;
5336 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5337 remote_ops
.to_store_registers
= remote_store_registers
;
5338 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5339 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5340 remote_ops
.to_files_info
= remote_files_info
;
5341 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5342 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5343 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5344 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5345 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5346 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5347 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5348 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5349 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5350 remote_ops
.to_kill
= remote_kill
;
5351 remote_ops
.to_load
= generic_load
;
5352 remote_ops
.to_mourn_inferior
= remote_mourn
;
5353 remote_ops
.to_thread_alive
= remote_thread_alive
;
5354 remote_ops
.to_find_new_threads
= remote_threads_info
;
5355 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5356 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5357 remote_ops
.to_stop
= remote_stop
;
5358 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
5359 remote_ops
.to_rcmd
= remote_rcmd
;
5360 remote_ops
.to_stratum
= process_stratum
;
5361 remote_ops
.to_has_all_memory
= 1;
5362 remote_ops
.to_has_memory
= 1;
5363 remote_ops
.to_has_stack
= 1;
5364 remote_ops
.to_has_registers
= 1;
5365 remote_ops
.to_has_execution
= 1;
5366 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5367 remote_ops
.to_magic
= OPS_MAGIC
;
5370 /* Set up the extended remote vector by making a copy of the standard
5371 remote vector and adding to it. */
5374 init_extended_remote_ops (void)
5376 extended_remote_ops
= remote_ops
;
5378 extended_remote_ops
.to_shortname
= "extended-remote";
5379 extended_remote_ops
.to_longname
=
5380 "Extended remote serial target in gdb-specific protocol";
5381 extended_remote_ops
.to_doc
=
5382 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5383 Specify the serial device it is connected to (e.g. /dev/ttya).",
5384 extended_remote_ops
.to_open
= extended_remote_open
;
5385 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5386 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5390 remote_can_async_p (void)
5392 /* We're async whenever the serial device is. */
5393 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5397 remote_is_async_p (void)
5399 /* We're async whenever the serial device is. */
5400 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5403 /* Pass the SERIAL event on and up to the client. One day this code
5404 will be able to delay notifying the client of an event until the
5405 point where an entire packet has been received. */
5407 static void (*async_client_callback
) (enum inferior_event_type event_type
,
5409 static void *async_client_context
;
5410 static serial_event_ftype remote_async_serial_handler
;
5413 remote_async_serial_handler (struct serial
*scb
, void *context
)
5415 /* Don't propogate error information up to the client. Instead let
5416 the client find out about the error by querying the target. */
5417 async_client_callback (INF_REG_EVENT
, async_client_context
);
5421 remote_async (void (*callback
) (enum inferior_event_type event_type
,
5422 void *context
), void *context
)
5424 if (current_target
.to_async_mask_value
== 0)
5425 internal_error (__FILE__
, __LINE__
,
5426 _("Calling remote_async when async is masked"));
5428 if (callback
!= NULL
)
5430 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5431 async_client_callback
= callback
;
5432 async_client_context
= context
;
5435 serial_async (remote_desc
, NULL
, NULL
);
5438 /* Target async and target extended-async.
5440 This are temporary targets, until it is all tested. Eventually
5441 async support will be incorporated int the usual 'remote'
5445 init_remote_async_ops (void)
5447 remote_async_ops
.to_shortname
= "async";
5448 remote_async_ops
.to_longname
=
5449 "Remote serial target in async version of the gdb-specific protocol";
5450 remote_async_ops
.to_doc
=
5451 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5452 Specify the serial device it is connected to (e.g. /dev/ttya).";
5453 remote_async_ops
.to_open
= remote_async_open
;
5454 remote_async_ops
.to_close
= remote_close
;
5455 remote_async_ops
.to_detach
= remote_detach
;
5456 remote_async_ops
.to_disconnect
= remote_disconnect
;
5457 remote_async_ops
.to_resume
= remote_async_resume
;
5458 remote_async_ops
.to_wait
= remote_async_wait
;
5459 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5460 remote_async_ops
.to_store_registers
= remote_store_registers
;
5461 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5462 remote_async_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5463 remote_async_ops
.to_files_info
= remote_files_info
;
5464 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5465 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5466 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5467 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5468 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5469 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5470 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5471 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5472 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5473 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5474 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5475 remote_async_ops
.to_kill
= remote_async_kill
;
5476 remote_async_ops
.to_load
= generic_load
;
5477 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5478 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5479 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5480 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5481 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5482 remote_async_ops
.to_stop
= remote_stop
;
5483 remote_async_ops
.to_xfer_partial
= remote_xfer_partial
;
5484 remote_async_ops
.to_rcmd
= remote_rcmd
;
5485 remote_async_ops
.to_stratum
= process_stratum
;
5486 remote_async_ops
.to_has_all_memory
= 1;
5487 remote_async_ops
.to_has_memory
= 1;
5488 remote_async_ops
.to_has_stack
= 1;
5489 remote_async_ops
.to_has_registers
= 1;
5490 remote_async_ops
.to_has_execution
= 1;
5491 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5492 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5493 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5494 remote_async_ops
.to_async
= remote_async
;
5495 remote_async_ops
.to_async_mask_value
= 1;
5496 remote_async_ops
.to_magic
= OPS_MAGIC
;
5499 /* Set up the async extended remote vector by making a copy of the standard
5500 remote vector and adding to it. */
5503 init_extended_async_remote_ops (void)
5505 extended_async_remote_ops
= remote_async_ops
;
5507 extended_async_remote_ops
.to_shortname
= "extended-async";
5508 extended_async_remote_ops
.to_longname
=
5509 "Extended remote serial target in async gdb-specific protocol";
5510 extended_async_remote_ops
.to_doc
=
5511 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5512 Specify the serial device it is connected to (e.g. /dev/ttya).",
5513 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5514 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5515 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5519 set_remote_cmd (char *args
, int from_tty
)
5524 show_remote_cmd (char *args
, int from_tty
)
5526 /* FIXME: cagney/2002-06-15: This function should iterate over
5527 remote_show_cmdlist for a list of sub commands to show. */
5528 show_remote_protocol_Z_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5529 show_remote_protocol_P_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5530 show_remote_protocol_p_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5531 show_remote_protocol_qSymbol_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5532 show_remote_protocol_vcont_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5533 show_remote_protocol_binary_download_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5534 show_remote_protocol_qPart_auxv_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5538 build_remote_gdbarch_data (void)
5540 remote_address_size
= TARGET_ADDR_BIT
;
5543 /* Saved pointer to previous owner of the new_objfile event. */
5544 static void (*remote_new_objfile_chain
) (struct objfile
*);
5546 /* Function to be called whenever a new objfile (shlib) is detected. */
5548 remote_new_objfile (struct objfile
*objfile
)
5550 if (remote_desc
!= 0) /* Have a remote connection. */
5552 remote_check_symbols (objfile
);
5554 /* Call predecessor on chain, if any. */
5555 if (remote_new_objfile_chain
!= 0 &&
5557 remote_new_objfile_chain (objfile
);
5561 _initialize_remote (void)
5563 static struct cmd_list_element
*remote_set_cmdlist
;
5564 static struct cmd_list_element
*remote_show_cmdlist
;
5565 struct cmd_list_element
*tmpcmd
;
5567 /* architecture specific data */
5568 remote_gdbarch_data_handle
=
5569 gdbarch_data_register_post_init (init_remote_state
);
5571 /* Old tacky stuff. NOTE: This comes after the remote protocol so
5572 that the remote protocol has been initialized. */
5573 DEPRECATED_REGISTER_GDBARCH_SWAP (remote_address_size
);
5574 deprecated_register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5577 add_target (&remote_ops
);
5579 init_extended_remote_ops ();
5580 add_target (&extended_remote_ops
);
5582 init_remote_async_ops ();
5583 add_target (&remote_async_ops
);
5585 init_extended_async_remote_ops ();
5586 add_target (&extended_async_remote_ops
);
5588 /* Hook into new objfile notification. */
5589 remote_new_objfile_chain
= deprecated_target_new_objfile_hook
;
5590 deprecated_target_new_objfile_hook
= remote_new_objfile
;
5593 init_remote_threadtests ();
5596 /* set/show remote ... */
5598 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
5599 Remote protocol specific variables\n\
5600 Configure various remote-protocol specific variables such as\n\
5601 the packets being used"),
5602 &remote_set_cmdlist
, "set remote ",
5603 0 /* allow-unknown */, &setlist
);
5604 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
5605 Remote protocol specific variables\n\
5606 Configure various remote-protocol specific variables such as\n\
5607 the packets being used"),
5608 &remote_show_cmdlist
, "show remote ",
5609 0 /* allow-unknown */, &showlist
);
5611 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
5612 Compare section data on target to the exec file.\n\
5613 Argument is a single section name (default: all loaded sections)."),
5616 add_cmd ("packet", class_maintenance
, packet_command
, _("\
5617 Send an arbitrary packet to a remote target.\n\
5618 maintenance packet TEXT\n\
5619 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5620 this command sends the string TEXT to the inferior, and displays the\n\
5621 response packet. GDB supplies the initial `$' character, and the\n\
5622 terminating `#' character and checksum."),
5625 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
5626 Set whether to send break if interrupted."), _("\
5627 Show whether to send break if interrupted."), _("\
5628 If set, a break, instead of a cntrl-c, is sent to the remote target."),
5629 NULL
, NULL
, /* FIXME: i18n: Whether to send break if interrupted is %s. */
5630 &setlist
, &showlist
);
5632 /* Install commands for configuring memory read/write packets. */
5634 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
5635 Set the maximum number of bytes per memory write packet (deprecated)."),
5637 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
5638 Show the maximum number of bytes per memory write packet (deprecated)."),
5640 add_cmd ("memory-write-packet-size", no_class
,
5641 set_memory_write_packet_size
, _("\
5642 Set the maximum number of bytes per memory-write packet.\n\
5643 Specify the number of bytes in a packet or 0 (zero) for the\n\
5644 default packet size. The actual limit is further reduced\n\
5645 dependent on the target. Specify ``fixed'' to disable the\n\
5646 further restriction and ``limit'' to enable that restriction."),
5647 &remote_set_cmdlist
);
5648 add_cmd ("memory-read-packet-size", no_class
,
5649 set_memory_read_packet_size
, _("\
5650 Set the maximum number of bytes per memory-read packet.\n\
5651 Specify the number of bytes in a packet or 0 (zero) for the\n\
5652 default packet size. The actual limit is further reduced\n\
5653 dependent on the target. Specify ``fixed'' to disable the\n\
5654 further restriction and ``limit'' to enable that restriction."),
5655 &remote_set_cmdlist
);
5656 add_cmd ("memory-write-packet-size", no_class
,
5657 show_memory_write_packet_size
,
5658 _("Show the maximum number of bytes per memory-write packet."),
5659 &remote_show_cmdlist
);
5660 add_cmd ("memory-read-packet-size", no_class
,
5661 show_memory_read_packet_size
,
5662 _("Show the maximum number of bytes per memory-read packet."),
5663 &remote_show_cmdlist
);
5665 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
5666 &remote_hw_watchpoint_limit
, _("\
5667 Set the maximum number of target hardware watchpoints."), _("\
5668 Show the maximum number of target hardware watchpoints."), _("\
5669 Specify a negative limit for unlimited."),
5670 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
5671 &remote_set_cmdlist
, &remote_show_cmdlist
);
5672 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
5673 &remote_hw_breakpoint_limit
, _("\
5674 Set the maximum number of target hardware breakpoints."), _("\
5675 Show the maximum number of target hardware breakpoints."), _("\
5676 Specify a negative limit for unlimited."),
5677 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
5678 &remote_set_cmdlist
, &remote_show_cmdlist
);
5680 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
5681 &remote_address_size
, _("\
5682 Set the maximum size of the address (in bits) in a memory packet."), _("\
5683 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
5685 NULL
, /* FIXME: i18n: */
5686 &setlist
, &showlist
);
5688 add_packet_config_cmd (&remote_protocol_binary_download
,
5689 "X", "binary-download",
5690 set_remote_protocol_binary_download_cmd
,
5691 show_remote_protocol_binary_download_cmd
,
5692 &remote_set_cmdlist
, &remote_show_cmdlist
,
5695 add_packet_config_cmd (&remote_protocol_vcont
,
5696 "vCont", "verbose-resume",
5697 set_remote_protocol_vcont_packet_cmd
,
5698 show_remote_protocol_vcont_packet_cmd
,
5699 &remote_set_cmdlist
, &remote_show_cmdlist
,
5702 add_packet_config_cmd (&remote_protocol_qSymbol
,
5703 "qSymbol", "symbol-lookup",
5704 set_remote_protocol_qSymbol_packet_cmd
,
5705 show_remote_protocol_qSymbol_packet_cmd
,
5706 &remote_set_cmdlist
, &remote_show_cmdlist
,
5709 add_packet_config_cmd (&remote_protocol_P
,
5710 "P", "set-register",
5711 set_remote_protocol_P_packet_cmd
,
5712 show_remote_protocol_P_packet_cmd
,
5713 &remote_set_cmdlist
, &remote_show_cmdlist
,
5716 add_packet_config_cmd (&remote_protocol_p
,
5717 "p", "fetch-register",
5718 set_remote_protocol_p_packet_cmd
,
5719 show_remote_protocol_p_packet_cmd
,
5720 &remote_set_cmdlist
, &remote_show_cmdlist
,
5723 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
5724 "Z0", "software-breakpoint",
5725 set_remote_protocol_Z_software_bp_packet_cmd
,
5726 show_remote_protocol_Z_software_bp_packet_cmd
,
5727 &remote_set_cmdlist
, &remote_show_cmdlist
,
5730 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
5731 "Z1", "hardware-breakpoint",
5732 set_remote_protocol_Z_hardware_bp_packet_cmd
,
5733 show_remote_protocol_Z_hardware_bp_packet_cmd
,
5734 &remote_set_cmdlist
, &remote_show_cmdlist
,
5737 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
5738 "Z2", "write-watchpoint",
5739 set_remote_protocol_Z_write_wp_packet_cmd
,
5740 show_remote_protocol_Z_write_wp_packet_cmd
,
5741 &remote_set_cmdlist
, &remote_show_cmdlist
,
5744 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
5745 "Z3", "read-watchpoint",
5746 set_remote_protocol_Z_read_wp_packet_cmd
,
5747 show_remote_protocol_Z_read_wp_packet_cmd
,
5748 &remote_set_cmdlist
, &remote_show_cmdlist
,
5751 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
5752 "Z4", "access-watchpoint",
5753 set_remote_protocol_Z_access_wp_packet_cmd
,
5754 show_remote_protocol_Z_access_wp_packet_cmd
,
5755 &remote_set_cmdlist
, &remote_show_cmdlist
,
5758 add_packet_config_cmd (&remote_protocol_qPart_auxv
,
5759 "qPart_auxv", "read-aux-vector",
5760 set_remote_protocol_qPart_auxv_packet_cmd
,
5761 show_remote_protocol_qPart_auxv_packet_cmd
,
5762 &remote_set_cmdlist
, &remote_show_cmdlist
,
5765 /* Keep the old ``set remote Z-packet ...'' working. */
5766 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
5767 &remote_Z_packet_detect
, _("\
5768 Set use of remote protocol `Z' packets"), _("\
5769 Show use of remote protocol `Z' packets "), _("\
5770 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
5772 set_remote_protocol_Z_packet_cmd
,
5773 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
5774 &remote_set_cmdlist
, &remote_show_cmdlist
);
5776 /* Eventually initialize fileio. See fileio.c */
5777 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);