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"
50 #include "event-loop.h"
51 #include "event-top.h"
57 #include "gdbcore.h" /* for exec_bfd */
59 #include "remote-fileio.h"
61 /* Prototypes for local functions. */
62 static void cleanup_sigint_signal_handler (void *dummy
);
63 static void initialize_sigint_signal_handler (void);
64 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
66 static void handle_remote_sigint (int);
67 static void handle_remote_sigint_twice (int);
68 static void async_remote_interrupt (gdb_client_data
);
69 void async_remote_interrupt_twice (gdb_client_data
);
71 static void build_remote_gdbarch_data (void);
73 static void remote_files_info (struct target_ops
*ignore
);
75 static void remote_prepare_to_store (void);
77 static void remote_fetch_registers (int regno
);
79 static void remote_resume (ptid_t ptid
, int step
,
80 enum target_signal siggnal
);
81 static void remote_async_resume (ptid_t ptid
, int step
,
82 enum target_signal siggnal
);
83 static void remote_open (char *name
, int from_tty
);
84 static void remote_async_open (char *name
, int from_tty
);
86 static void extended_remote_open (char *name
, int from_tty
);
87 static void extended_remote_async_open (char *name
, int from_tty
);
89 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
92 static void remote_close (int quitting
);
94 static void remote_store_registers (int regno
);
96 static void remote_mourn (void);
97 static void remote_async_mourn (void);
99 static void extended_remote_restart (void);
101 static void extended_remote_mourn (void);
103 static void remote_mourn_1 (struct target_ops
*);
105 static void remote_send (char *buf
, long sizeof_buf
);
107 static int readchar (int timeout
);
109 static ptid_t
remote_wait (ptid_t ptid
,
110 struct target_waitstatus
*status
);
111 static ptid_t
remote_async_wait (ptid_t ptid
,
112 struct target_waitstatus
*status
);
114 static void remote_kill (void);
115 static void remote_async_kill (void);
117 static int tohex (int nib
);
119 static void remote_detach (char *args
, int from_tty
);
121 static void remote_interrupt (int signo
);
123 static void remote_interrupt_twice (int signo
);
125 static void interrupt_query (void);
127 static void set_thread (int, int);
129 static int remote_thread_alive (ptid_t
);
131 static void get_offsets (void);
133 static long read_frame (char *buf
, long sizeof_buf
);
135 static int remote_insert_breakpoint (CORE_ADDR
, bfd_byte
*);
137 static int remote_remove_breakpoint (CORE_ADDR
, bfd_byte
*);
139 static int hexnumlen (ULONGEST num
);
141 static void init_remote_ops (void);
143 static void init_extended_remote_ops (void);
145 static void remote_stop (void);
147 static int ishex (int ch
, int *val
);
149 static int stubhex (int ch
);
151 static int hexnumstr (char *, ULONGEST
);
153 static int hexnumnstr (char *, ULONGEST
, int);
155 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
157 static void print_packet (char *);
159 static unsigned long crc32 (unsigned char *, int, unsigned int);
161 static void compare_sections_command (char *, int);
163 static void packet_command (char *, int);
165 static int stub_unpack_int (char *buff
, int fieldlength
);
167 static ptid_t
remote_current_thread (ptid_t oldptid
);
169 static void remote_find_new_threads (void);
171 static void record_currthread (int currthread
);
173 static int fromhex (int a
);
175 static int hex2bin (const char *hex
, char *bin
, int count
);
177 static int bin2hex (const char *bin
, char *hex
, int count
);
179 static int putpkt_binary (char *buf
, int cnt
);
181 static void check_binary_download (CORE_ADDR addr
);
183 struct packet_config
;
185 static void show_packet_config_cmd (struct packet_config
*config
);
187 static void update_packet_config (struct packet_config
*config
);
189 void _initialize_remote (void);
191 /* Description of the remote protocol. Strictly speaking, when the
192 target is open()ed, remote.c should create a per-target description
193 of the remote protocol using that target's architecture.
194 Unfortunately, the target stack doesn't include local state. For
195 the moment keep the information in the target's architecture
200 long offset
; /* Offset into G packet. */
201 long regnum
; /* GDB's internal register number. */
202 LONGEST pnum
; /* Remote protocol register number. */
203 int in_g_packet
; /* Always part of G packet. */
204 /* long size in bytes; == register_size (current_gdbarch, regnum);
206 /* char *name; == REGISTER_NAME (regnum); at present. */
211 /* Description of the remote protocol registers. */
212 long sizeof_g_packet
;
214 /* Description of the remote protocol registers indexed by REGNUM
215 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
216 struct packet_reg
*regs
;
218 /* This is the size (in chars) of the first response to the ``g''
219 packet. It is used as a heuristic when determining the maximum
220 size of memory-read and memory-write packets. A target will
221 typically only reserve a buffer large enough to hold the ``g''
222 packet. The size does not include packet overhead (headers and
224 long actual_register_packet_size
;
226 /* This is the maximum size (in chars) of a non read/write packet.
227 It is also used as a cap on the size of read/write packets. */
228 long remote_packet_size
;
232 /* Handle for retreving the remote protocol data from gdbarch. */
233 static struct gdbarch_data
*remote_gdbarch_data_handle
;
235 static struct remote_state
*
236 get_remote_state (void)
238 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
242 init_remote_state (struct gdbarch
*gdbarch
)
245 struct remote_state
*rs
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_state
);
247 rs
->sizeof_g_packet
= 0;
249 /* Assume a 1:1 regnum<->pnum table. */
250 rs
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
, NUM_REGS
+ NUM_PSEUDO_REGS
,
252 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
254 struct packet_reg
*r
= &rs
->regs
[regnum
];
257 r
->offset
= DEPRECATED_REGISTER_BYTE (regnum
);
258 r
->in_g_packet
= (regnum
< NUM_REGS
);
259 /* ...name = REGISTER_NAME (regnum); */
261 /* Compute packet size by accumulating the size of all registers. */
262 if (regnum
< NUM_REGS
)
263 rs
->sizeof_g_packet
+= register_size (current_gdbarch
, regnum
);
266 /* Default maximum number of characters in a packet body. Many
267 remote stubs have a hardwired buffer size of 400 bytes
268 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
269 as the maximum packet-size to ensure that the packet and an extra
270 NUL character can always fit in the buffer. This stops GDB
271 trashing stubs that try to squeeze an extra NUL into what is
272 already a full buffer (As of 1999-12-04 that was most stubs. */
273 rs
->remote_packet_size
= 400 - 1;
275 /* Should rs->sizeof_g_packet needs more space than the
276 default, adjust the size accordingly. Remember that each byte is
277 encoded as two characters. 32 is the overhead for the packet
278 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
279 (``$NN:G...#NN'') is a better guess, the below has been padded a
281 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
282 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
284 /* This one is filled in when a ``g'' packet is received. */
285 rs
->actual_register_packet_size
= 0;
290 static struct packet_reg
*
291 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
293 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
297 struct packet_reg
*r
= &rs
->regs
[regnum
];
298 gdb_assert (r
->regnum
== regnum
);
303 static struct packet_reg
*
304 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
307 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
309 struct packet_reg
*r
= &rs
->regs
[i
];
316 /* FIXME: graces/2002-08-08: These variables should eventually be
317 bound to an instance of the target object (as in gdbarch-tdep()),
318 when such a thing exists. */
320 /* This is set to the data address of the access causing the target
321 to stop for a watchpoint. */
322 static CORE_ADDR remote_watch_data_address
;
324 /* This is non-zero if taregt stopped for a watchpoint. */
325 static int remote_stopped_by_watchpoint_p
;
328 static struct target_ops remote_ops
;
330 static struct target_ops extended_remote_ops
;
332 /* Temporary target ops. Just like the remote_ops and
333 extended_remote_ops, but with asynchronous support. */
334 static struct target_ops remote_async_ops
;
336 static struct target_ops extended_async_remote_ops
;
338 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
339 ``forever'' still use the normal timeout mechanism. This is
340 currently used by the ASYNC code to guarentee that target reads
341 during the initial connect always time-out. Once getpkt has been
342 modified to return a timeout indication and, in turn
343 remote_wait()/wait_for_inferior() have gained a timeout parameter
345 static int wait_forever_enabled_p
= 1;
348 /* This variable chooses whether to send a ^C or a break when the user
349 requests program interruption. Although ^C is usually what remote
350 systems expect, and that is the default here, sometimes a break is
351 preferable instead. */
353 static int remote_break
;
355 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
356 remote_open knows that we don't have a file open when the program
358 static struct serial
*remote_desc
= NULL
;
360 /* This variable sets the number of bits in an address that are to be
361 sent in a memory ("M" or "m") packet. Normally, after stripping
362 leading zeros, the entire address would be sent. This variable
363 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
364 initial implementation of remote.c restricted the address sent in
365 memory packets to ``host::sizeof long'' bytes - (typically 32
366 bits). Consequently, for 64 bit targets, the upper 32 bits of an
367 address was never sent. Since fixing this bug may cause a break in
368 some remote targets this variable is principly provided to
369 facilitate backward compatibility. */
371 static int remote_address_size
;
373 /* Tempoary to track who currently owns the terminal. See
374 target_async_terminal_* for more details. */
376 static int remote_async_terminal_ours_p
;
379 /* User configurable variables for the number of characters in a
380 memory read/write packet. MIN ((rs->remote_packet_size),
381 rs->sizeof_g_packet) is the default. Some targets need smaller
382 values (fifo overruns, et.al.) and some users need larger values
383 (speed up transfers). The variables ``preferred_*'' (the user
384 request), ``current_*'' (what was actually set) and ``forced_*''
385 (Positive - a soft limit, negative - a hard limit). */
387 struct memory_packet_config
394 /* Compute the current size of a read/write packet. Since this makes
395 use of ``actual_register_packet_size'' the computation is dynamic. */
398 get_memory_packet_size (struct memory_packet_config
*config
)
400 struct remote_state
*rs
= get_remote_state ();
401 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
402 law?) that some hosts don't cope very well with large alloca()
403 calls. Eventually the alloca() code will be replaced by calls to
404 xmalloc() and make_cleanups() allowing this restriction to either
405 be lifted or removed. */
406 #ifndef MAX_REMOTE_PACKET_SIZE
407 #define MAX_REMOTE_PACKET_SIZE 16384
409 /* NOTE: 20 ensures we can write at least one byte. */
410 #ifndef MIN_REMOTE_PACKET_SIZE
411 #define MIN_REMOTE_PACKET_SIZE 20
416 if (config
->size
<= 0)
417 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
419 what_they_get
= config
->size
;
423 what_they_get
= (rs
->remote_packet_size
);
424 /* Limit the packet to the size specified by the user. */
426 && what_they_get
> config
->size
)
427 what_they_get
= config
->size
;
428 /* Limit it to the size of the targets ``g'' response. */
429 if ((rs
->actual_register_packet_size
) > 0
430 && what_they_get
> (rs
->actual_register_packet_size
))
431 what_they_get
= (rs
->actual_register_packet_size
);
433 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
434 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
435 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
436 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
437 return what_they_get
;
440 /* Update the size of a read/write packet. If they user wants
441 something really big then do a sanity check. */
444 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
446 int fixed_p
= config
->fixed_p
;
447 long size
= config
->size
;
449 error (_("Argument required (integer, `fixed' or `limited')."));
450 else if (strcmp (args
, "hard") == 0
451 || strcmp (args
, "fixed") == 0)
453 else if (strcmp (args
, "soft") == 0
454 || strcmp (args
, "limit") == 0)
459 size
= strtoul (args
, &end
, 0);
461 error (_("Invalid %s (bad syntax)."), config
->name
);
463 /* Instead of explicitly capping the size of a packet to
464 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
465 instead allowed to set the size to something arbitrarily
467 if (size
> MAX_REMOTE_PACKET_SIZE
)
468 error (_("Invalid %s (too large)."), config
->name
);
472 if (fixed_p
&& !config
->fixed_p
)
474 if (! query (_("The target may not be able to correctly handle a %s\n"
475 "of %ld bytes. Change the packet size? "),
477 error (_("Packet size not changed."));
479 /* Update the config. */
480 config
->fixed_p
= fixed_p
;
485 show_memory_packet_size (struct memory_packet_config
*config
)
487 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
489 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
490 get_memory_packet_size (config
));
492 printf_filtered (_("Packets are limited to %ld bytes.\n"),
493 get_memory_packet_size (config
));
496 static struct memory_packet_config memory_write_packet_config
=
498 "memory-write-packet-size",
502 set_memory_write_packet_size (char *args
, int from_tty
)
504 set_memory_packet_size (args
, &memory_write_packet_config
);
508 show_memory_write_packet_size (char *args
, int from_tty
)
510 show_memory_packet_size (&memory_write_packet_config
);
514 get_memory_write_packet_size (void)
516 return get_memory_packet_size (&memory_write_packet_config
);
519 static struct memory_packet_config memory_read_packet_config
=
521 "memory-read-packet-size",
525 set_memory_read_packet_size (char *args
, int from_tty
)
527 set_memory_packet_size (args
, &memory_read_packet_config
);
531 show_memory_read_packet_size (char *args
, int from_tty
)
533 show_memory_packet_size (&memory_read_packet_config
);
537 get_memory_read_packet_size (void)
539 struct remote_state
*rs
= get_remote_state ();
540 long size
= get_memory_packet_size (&memory_read_packet_config
);
541 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
542 extra buffer size argument before the memory read size can be
543 increased beyond (rs->remote_packet_size). */
544 if (size
> (rs
->remote_packet_size
))
545 size
= (rs
->remote_packet_size
);
550 /* Generic configuration support for packets the stub optionally
551 supports. Allows the user to specify the use of the packet as well
552 as allowing GDB to auto-detect support in the remote stub. */
556 PACKET_SUPPORT_UNKNOWN
= 0,
565 enum auto_boolean detect
;
566 enum packet_support support
;
569 /* Analyze a packet's return value and update the packet config
580 update_packet_config (struct packet_config
*config
)
582 switch (config
->detect
)
584 case AUTO_BOOLEAN_TRUE
:
585 config
->support
= PACKET_ENABLE
;
587 case AUTO_BOOLEAN_FALSE
:
588 config
->support
= PACKET_DISABLE
;
590 case AUTO_BOOLEAN_AUTO
:
591 config
->support
= PACKET_SUPPORT_UNKNOWN
;
597 show_packet_config_cmd (struct packet_config
*config
)
599 char *support
= "internal-error";
600 switch (config
->support
)
606 support
= "disabled";
608 case PACKET_SUPPORT_UNKNOWN
:
612 switch (config
->detect
)
614 case AUTO_BOOLEAN_AUTO
:
615 printf_filtered (_("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n"),
616 config
->name
, config
->title
, support
);
618 case AUTO_BOOLEAN_TRUE
:
619 case AUTO_BOOLEAN_FALSE
:
620 printf_filtered (_("Support for remote protocol `%s' (%s) packet is currently %s.\n"),
621 config
->name
, config
->title
, support
);
627 add_packet_config_cmd (struct packet_config
*config
,
630 cmd_sfunc_ftype
*set_func
,
631 show_value_ftype
*show_func
,
632 struct cmd_list_element
**set_remote_list
,
633 struct cmd_list_element
**show_remote_list
,
641 config
->title
= title
;
642 config
->detect
= AUTO_BOOLEAN_AUTO
;
643 config
->support
= PACKET_SUPPORT_UNKNOWN
;
644 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
646 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
648 /* set/show TITLE-packet {auto,on,off} */
649 cmd_name
= xstrprintf ("%s-packet", title
);
650 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
651 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
653 set_remote_list
, show_remote_list
);
654 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
658 legacy_name
= xstrprintf ("%s-packet", name
);
659 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
661 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
666 static enum packet_result
667 packet_ok (const char *buf
, struct packet_config
*config
)
671 /* The stub recognized the packet request. Check that the
672 operation succeeded. */
673 switch (config
->support
)
675 case PACKET_SUPPORT_UNKNOWN
:
677 fprintf_unfiltered (gdb_stdlog
,
678 "Packet %s (%s) is supported\n",
679 config
->name
, config
->title
);
680 config
->support
= PACKET_ENABLE
;
683 internal_error (__FILE__
, __LINE__
,
684 _("packet_ok: attempt to use a disabled packet"));
689 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
690 /* "OK" - definitly OK. */
693 && isxdigit (buf
[1]) && isxdigit (buf
[2])
695 /* "Enn" - definitly an error. */
697 /* The packet may or may not be OK. Just assume it is. */
702 /* The stub does not support the packet. */
703 switch (config
->support
)
706 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
707 /* If the stub previously indicated that the packet was
708 supported then there is a protocol error.. */
709 error (_("Protocol error: %s (%s) conflicting enabled responses."),
710 config
->name
, config
->title
);
712 /* The user set it wrong. */
713 error (_("Enabled packet %s (%s) not recognized by stub"),
714 config
->name
, config
->title
);
716 case PACKET_SUPPORT_UNKNOWN
:
718 fprintf_unfiltered (gdb_stdlog
,
719 "Packet %s (%s) is NOT supported\n",
720 config
->name
, config
->title
);
721 config
->support
= PACKET_DISABLE
;
726 return PACKET_UNKNOWN
;
730 /* Should we try the 'vCont' (descriptive resume) request? */
731 static struct packet_config remote_protocol_vcont
;
734 set_remote_protocol_vcont_packet_cmd (char *args
, int from_tty
,
735 struct cmd_list_element
*c
)
737 update_packet_config (&remote_protocol_vcont
);
741 show_remote_protocol_vcont_packet_cmd (struct ui_file
*file
, int from_tty
,
742 struct cmd_list_element
*c
,
745 show_packet_config_cmd (&remote_protocol_vcont
);
748 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
749 static struct packet_config remote_protocol_qSymbol
;
752 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
753 struct cmd_list_element
*c
)
755 update_packet_config (&remote_protocol_qSymbol
);
759 show_remote_protocol_qSymbol_packet_cmd (struct ui_file
*file
, int from_tty
,
760 struct cmd_list_element
*c
,
763 show_packet_config_cmd (&remote_protocol_qSymbol
);
766 /* Should we try the 'P' (set register) request? */
768 static struct packet_config remote_protocol_P
;
771 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
772 struct cmd_list_element
*c
)
774 update_packet_config (&remote_protocol_P
);
778 show_remote_protocol_P_packet_cmd (struct ui_file
*file
, int from_tty
,
779 struct cmd_list_element
*c
,
782 show_packet_config_cmd (&remote_protocol_P
);
785 /* Should we try one of the 'Z' requests? */
789 Z_PACKET_SOFTWARE_BP
,
790 Z_PACKET_HARDWARE_BP
,
797 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
799 /* FIXME: Instead of having all these boiler plate functions, the
800 command callback should include a context argument. */
803 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
804 struct cmd_list_element
*c
)
806 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
810 show_remote_protocol_Z_software_bp_packet_cmd (struct ui_file
*file
, int from_tty
,
811 struct cmd_list_element
*c
,
814 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
818 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
819 struct cmd_list_element
*c
)
821 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
825 show_remote_protocol_Z_hardware_bp_packet_cmd (struct ui_file
*file
, int from_tty
,
826 struct cmd_list_element
*c
,
829 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
833 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
834 struct cmd_list_element
*c
)
836 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
840 show_remote_protocol_Z_write_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
841 struct cmd_list_element
*c
,
844 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
848 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
849 struct cmd_list_element
*c
)
851 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
855 show_remote_protocol_Z_read_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
856 struct cmd_list_element
*c
,
859 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
863 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
864 struct cmd_list_element
*c
)
866 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
870 show_remote_protocol_Z_access_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
871 struct cmd_list_element
*c
,
874 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
877 /* For compatibility with older distributions. Provide a ``set remote
878 Z-packet ...'' command that updates all the Z packet types. */
880 static enum auto_boolean remote_Z_packet_detect
;
883 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
884 struct cmd_list_element
*c
)
887 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
889 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
890 update_packet_config (&remote_protocol_Z
[i
]);
895 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
896 struct cmd_list_element
*c
,
900 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
902 show_packet_config_cmd (&remote_protocol_Z
[i
]);
906 /* Should we try the 'X' (remote binary download) packet?
908 This variable (available to the user via "set remote X-packet")
909 dictates whether downloads are sent in binary (via the 'X' packet).
910 We assume that the stub can, and attempt to do it. This will be
911 cleared if the stub does not understand it. This switch is still
912 needed, though in cases when the packet is supported in the stub,
913 but the connection does not allow it (i.e., 7-bit serial connection
916 static struct packet_config remote_protocol_binary_download
;
918 /* Should we try the 'ThreadInfo' query packet?
920 This variable (NOT available to the user: auto-detect only!)
921 determines whether GDB will use the new, simpler "ThreadInfo"
922 query or the older, more complex syntax for thread queries.
923 This is an auto-detect variable (set to true at each connect,
924 and set to false when the target fails to recognize it). */
926 static int use_threadinfo_query
;
927 static int use_threadextra_query
;
930 set_remote_protocol_binary_download_cmd (char *args
,
932 struct cmd_list_element
*c
)
934 update_packet_config (&remote_protocol_binary_download
);
938 show_remote_protocol_binary_download_cmd (struct ui_file
*file
, int from_tty
,
939 struct cmd_list_element
*c
,
942 show_packet_config_cmd (&remote_protocol_binary_download
);
945 /* Should we try the 'qPart:auxv' (target auxiliary vector read) request? */
946 static struct packet_config remote_protocol_qPart_auxv
;
949 set_remote_protocol_qPart_auxv_packet_cmd (char *args
, int from_tty
,
950 struct cmd_list_element
*c
)
952 update_packet_config (&remote_protocol_qPart_auxv
);
956 show_remote_protocol_qPart_auxv_packet_cmd (struct ui_file
*file
, int from_tty
,
957 struct cmd_list_element
*c
,
960 show_packet_config_cmd (&remote_protocol_qPart_auxv
);
963 /* Should we try the 'qGetTLSAddr' (Get Thread Local Storage Address) request? */
964 static struct packet_config remote_protocol_qGetTLSAddr
;
967 set_remote_protocol_qGetTLSAddr_packet_cmd (char *args
, int from_tty
,
968 struct cmd_list_element
*c
)
970 update_packet_config (&remote_protocol_qGetTLSAddr
);
974 show_remote_protocol_qGetTLSAddr_packet_cmd (struct ui_file
*file
, int from_tty
,
975 struct cmd_list_element
*c
,
978 show_packet_config_cmd (&remote_protocol_qGetTLSAddr
);
981 static struct packet_config remote_protocol_p
;
984 set_remote_protocol_p_packet_cmd (char *args
, int from_tty
,
985 struct cmd_list_element
*c
)
987 update_packet_config (&remote_protocol_p
);
991 show_remote_protocol_p_packet_cmd (struct ui_file
*file
, int from_tty
,
992 struct cmd_list_element
*c
,
995 show_packet_config_cmd (&remote_protocol_p
);
1000 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1001 static void *sigint_remote_twice_token
;
1002 static void *sigint_remote_token
;
1004 /* These are pointers to hook functions that may be set in order to
1005 modify resume/wait behavior for a particular architecture. */
1007 void (*deprecated_target_resume_hook
) (void);
1008 void (*deprecated_target_wait_loop_hook
) (void);
1012 /* These are the threads which we last sent to the remote system.
1013 -1 for all or -2 for not sent yet. */
1014 static int general_thread
;
1015 static int continue_thread
;
1017 /* Call this function as a result of
1018 1) A halt indication (T packet) containing a thread id
1019 2) A direct query of currthread
1020 3) Successful execution of set thread
1024 record_currthread (int currthread
)
1026 general_thread
= currthread
;
1028 /* If this is a new thread, add it to GDB's thread list.
1029 If we leave it up to WFI to do this, bad things will happen. */
1030 if (!in_thread_list (pid_to_ptid (currthread
)))
1032 add_thread (pid_to_ptid (currthread
));
1033 ui_out_text (uiout
, "[New ");
1034 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1035 ui_out_text (uiout
, "]\n");
1039 #define MAGIC_NULL_PID 42000
1042 set_thread (int th
, int gen
)
1044 struct remote_state
*rs
= get_remote_state ();
1045 char *buf
= alloca (rs
->remote_packet_size
);
1046 int state
= gen
? general_thread
: continue_thread
;
1052 buf
[1] = gen
? 'g' : 'c';
1053 if (th
== MAGIC_NULL_PID
)
1059 xsnprintf (&buf
[2], rs
->remote_packet_size
- 2, "-%x", -th
);
1061 xsnprintf (&buf
[2], rs
->remote_packet_size
- 2, "%x", th
);
1063 getpkt (buf
, (rs
->remote_packet_size
), 0);
1065 general_thread
= th
;
1067 continue_thread
= th
;
1070 /* Return nonzero if the thread TH is still alive on the remote system. */
1073 remote_thread_alive (ptid_t ptid
)
1075 int tid
= PIDGET (ptid
);
1079 xsnprintf (buf
, sizeof (buf
), "T-%08x", -tid
);
1081 xsnprintf (buf
, sizeof (buf
), "T%08x", tid
);
1083 getpkt (buf
, sizeof (buf
), 0);
1084 return (buf
[0] == 'O' && buf
[1] == 'K');
1087 /* About these extended threadlist and threadinfo packets. They are
1088 variable length packets but, the fields within them are often fixed
1089 length. They are redundent enough to send over UDP as is the
1090 remote protocol in general. There is a matching unit test module
1093 #define OPAQUETHREADBYTES 8
1095 /* a 64 bit opaque identifier */
1096 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1098 /* WARNING: This threadref data structure comes from the remote O.S.,
1099 libstub protocol encoding, and remote.c. it is not particularly
1102 /* Right now, the internal structure is int. We want it to be bigger.
1106 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1108 /* gdb_ext_thread_info is an internal GDB data structure which is
1109 equivalint to the reply of the remote threadinfo packet. */
1111 struct gdb_ext_thread_info
1113 threadref threadid
; /* External form of thread reference. */
1114 int active
; /* Has state interesting to GDB?
1116 char display
[256]; /* Brief state display, name,
1117 blocked/suspended. */
1118 char shortname
[32]; /* To be used to name threads. */
1119 char more_display
[256]; /* Long info, statistics, queue depth,
1123 /* The volume of remote transfers can be limited by submitting
1124 a mask containing bits specifying the desired information.
1125 Use a union of these values as the 'selection' parameter to
1126 get_thread_info. FIXME: Make these TAG names more thread specific.
1129 #define TAG_THREADID 1
1130 #define TAG_EXISTS 2
1131 #define TAG_DISPLAY 4
1132 #define TAG_THREADNAME 8
1133 #define TAG_MOREDISPLAY 16
1135 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1137 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1139 static char *unpack_nibble (char *buf
, int *val
);
1141 static char *pack_nibble (char *buf
, int nibble
);
1143 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1145 static char *unpack_byte (char *buf
, int *value
);
1147 static char *pack_int (char *buf
, int value
);
1149 static char *unpack_int (char *buf
, int *value
);
1151 static char *unpack_string (char *src
, char *dest
, int length
);
1153 static char *pack_threadid (char *pkt
, threadref
*id
);
1155 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1157 void int_to_threadref (threadref
*id
, int value
);
1159 static int threadref_to_int (threadref
*ref
);
1161 static void copy_threadref (threadref
*dest
, threadref
*src
);
1163 static int threadmatch (threadref
*dest
, threadref
*src
);
1165 static char *pack_threadinfo_request (char *pkt
, int mode
,
1168 static int remote_unpack_thread_info_response (char *pkt
,
1169 threadref
*expectedref
,
1170 struct gdb_ext_thread_info
1174 static int remote_get_threadinfo (threadref
*threadid
,
1175 int fieldset
, /*TAG mask */
1176 struct gdb_ext_thread_info
*info
);
1178 static char *pack_threadlist_request (char *pkt
, int startflag
,
1180 threadref
*nextthread
);
1182 static int parse_threadlist_response (char *pkt
,
1184 threadref
*original_echo
,
1185 threadref
*resultlist
,
1188 static int remote_get_threadlist (int startflag
,
1189 threadref
*nextthread
,
1193 threadref
*threadlist
);
1195 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1197 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1198 void *context
, int looplimit
);
1200 static int remote_newthread_step (threadref
*ref
, void *context
);
1202 /* Encode 64 bits in 16 chars of hex. */
1204 static const char hexchars
[] = "0123456789abcdef";
1207 ishex (int ch
, int *val
)
1209 if ((ch
>= 'a') && (ch
<= 'f'))
1211 *val
= ch
- 'a' + 10;
1214 if ((ch
>= 'A') && (ch
<= 'F'))
1216 *val
= ch
- 'A' + 10;
1219 if ((ch
>= '0') && (ch
<= '9'))
1230 if (ch
>= 'a' && ch
<= 'f')
1231 return ch
- 'a' + 10;
1232 if (ch
>= '0' && ch
<= '9')
1234 if (ch
>= 'A' && ch
<= 'F')
1235 return ch
- 'A' + 10;
1240 stub_unpack_int (char *buff
, int fieldlength
)
1247 nibble
= stubhex (*buff
++);
1251 retval
= retval
<< 4;
1257 unpack_varlen_hex (char *buff
, /* packet to parse */
1263 while (ishex (*buff
, &nibble
))
1266 retval
= retval
<< 4;
1267 retval
|= nibble
& 0x0f;
1274 unpack_nibble (char *buf
, int *val
)
1276 ishex (*buf
++, val
);
1281 pack_nibble (char *buf
, int nibble
)
1283 *buf
++ = hexchars
[(nibble
& 0x0f)];
1288 pack_hex_byte (char *pkt
, int byte
)
1290 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1291 *pkt
++ = hexchars
[(byte
& 0xf)];
1296 unpack_byte (char *buf
, int *value
)
1298 *value
= stub_unpack_int (buf
, 2);
1303 pack_int (char *buf
, int value
)
1305 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1306 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1307 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1308 buf
= pack_hex_byte (buf
, (value
& 0xff));
1313 unpack_int (char *buf
, int *value
)
1315 *value
= stub_unpack_int (buf
, 8);
1319 #if 0 /* Currently unused, uncomment when needed. */
1320 static char *pack_string (char *pkt
, char *string
);
1323 pack_string (char *pkt
, char *string
)
1328 len
= strlen (string
);
1330 len
= 200; /* Bigger than most GDB packets, junk??? */
1331 pkt
= pack_hex_byte (pkt
, len
);
1335 if ((ch
== '\0') || (ch
== '#'))
1336 ch
= '*'; /* Protect encapsulation. */
1341 #endif /* 0 (unused) */
1344 unpack_string (char *src
, char *dest
, int length
)
1353 pack_threadid (char *pkt
, threadref
*id
)
1356 unsigned char *altid
;
1358 altid
= (unsigned char *) id
;
1359 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1361 pkt
= pack_hex_byte (pkt
, *altid
++);
1367 unpack_threadid (char *inbuf
, threadref
*id
)
1370 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1373 altref
= (char *) id
;
1375 while (inbuf
< limit
)
1377 x
= stubhex (*inbuf
++);
1378 y
= stubhex (*inbuf
++);
1379 *altref
++ = (x
<< 4) | y
;
1384 /* Externally, threadrefs are 64 bits but internally, they are still
1385 ints. This is due to a mismatch of specifications. We would like
1386 to use 64bit thread references internally. This is an adapter
1390 int_to_threadref (threadref
*id
, int value
)
1392 unsigned char *scan
;
1394 scan
= (unsigned char *) id
;
1400 *scan
++ = (value
>> 24) & 0xff;
1401 *scan
++ = (value
>> 16) & 0xff;
1402 *scan
++ = (value
>> 8) & 0xff;
1403 *scan
++ = (value
& 0xff);
1407 threadref_to_int (threadref
*ref
)
1410 unsigned char *scan
;
1412 scan
= (char *) ref
;
1416 value
= (value
<< 8) | ((*scan
++) & 0xff);
1421 copy_threadref (threadref
*dest
, threadref
*src
)
1424 unsigned char *csrc
, *cdest
;
1426 csrc
= (unsigned char *) src
;
1427 cdest
= (unsigned char *) dest
;
1434 threadmatch (threadref
*dest
, threadref
*src
)
1436 /* Things are broken right now, so just assume we got a match. */
1438 unsigned char *srcp
, *destp
;
1440 srcp
= (char *) src
;
1441 destp
= (char *) dest
;
1445 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1452 threadid:1, # always request threadid
1459 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1462 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1464 *pkt
++ = 'q'; /* Info Query */
1465 *pkt
++ = 'P'; /* process or thread info */
1466 pkt
= pack_int (pkt
, mode
); /* mode */
1467 pkt
= pack_threadid (pkt
, id
); /* threadid */
1468 *pkt
= '\0'; /* terminate */
1472 /* These values tag the fields in a thread info response packet. */
1473 /* Tagging the fields allows us to request specific fields and to
1474 add more fields as time goes by. */
1476 #define TAG_THREADID 1 /* Echo the thread identifier. */
1477 #define TAG_EXISTS 2 /* Is this process defined enough to
1478 fetch registers and its stack? */
1479 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1480 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
1481 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1485 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1486 struct gdb_ext_thread_info
*info
)
1488 struct remote_state
*rs
= get_remote_state ();
1492 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausible parsing limit */
1495 /* info->threadid = 0; FIXME: implement zero_threadref. */
1497 info
->display
[0] = '\0';
1498 info
->shortname
[0] = '\0';
1499 info
->more_display
[0] = '\0';
1501 /* Assume the characters indicating the packet type have been
1503 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1504 pkt
= unpack_threadid (pkt
, &ref
);
1507 warning (_("Incomplete response to threadinfo request."));
1508 if (!threadmatch (&ref
, expectedref
))
1509 { /* This is an answer to a different request. */
1510 warning (_("ERROR RMT Thread info mismatch."));
1513 copy_threadref (&info
->threadid
, &ref
);
1515 /* Loop on tagged fields , try to bail if somthing goes wrong. */
1517 /* Packets are terminated with nulls. */
1518 while ((pkt
< limit
) && mask
&& *pkt
)
1520 pkt
= unpack_int (pkt
, &tag
); /* tag */
1521 pkt
= unpack_byte (pkt
, &length
); /* length */
1522 if (!(tag
& mask
)) /* Tags out of synch with mask. */
1524 warning (_("ERROR RMT: threadinfo tag mismatch."));
1528 if (tag
== TAG_THREADID
)
1532 warning (_("ERROR RMT: length of threadid is not 16."));
1536 pkt
= unpack_threadid (pkt
, &ref
);
1537 mask
= mask
& ~TAG_THREADID
;
1540 if (tag
== TAG_EXISTS
)
1542 info
->active
= stub_unpack_int (pkt
, length
);
1544 mask
= mask
& ~(TAG_EXISTS
);
1547 warning (_("ERROR RMT: 'exists' length too long."));
1553 if (tag
== TAG_THREADNAME
)
1555 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1556 mask
= mask
& ~TAG_THREADNAME
;
1559 if (tag
== TAG_DISPLAY
)
1561 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1562 mask
= mask
& ~TAG_DISPLAY
;
1565 if (tag
== TAG_MOREDISPLAY
)
1567 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1568 mask
= mask
& ~TAG_MOREDISPLAY
;
1571 warning (_("ERROR RMT: unknown thread info tag."));
1572 break; /* Not a tag we know about. */
1578 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1579 struct gdb_ext_thread_info
*info
)
1581 struct remote_state
*rs
= get_remote_state ();
1583 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1585 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1586 putpkt (threadinfo_pkt
);
1587 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1588 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2,
1593 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1596 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1597 threadref
*nextthread
)
1599 *pkt
++ = 'q'; /* info query packet */
1600 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1601 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1602 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1603 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1608 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1611 parse_threadlist_response (char *pkt
, int result_limit
,
1612 threadref
*original_echo
, threadref
*resultlist
,
1615 struct remote_state
*rs
= get_remote_state ();
1617 int count
, resultcount
, done
;
1620 /* Assume the 'q' and 'M chars have been stripped. */
1621 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
);
1622 /* done parse past here */
1623 pkt
= unpack_byte (pkt
, &count
); /* count field */
1624 pkt
= unpack_nibble (pkt
, &done
);
1625 /* The first threadid is the argument threadid. */
1626 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1627 while ((count
-- > 0) && (pkt
< limit
))
1629 pkt
= unpack_threadid (pkt
, resultlist
++);
1630 if (resultcount
++ >= result_limit
)
1639 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1640 int *done
, int *result_count
, threadref
*threadlist
)
1642 struct remote_state
*rs
= get_remote_state ();
1643 static threadref echo_nextthread
;
1644 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1645 char *t_response
= alloca (rs
->remote_packet_size
);
1648 /* Trancate result limit to be smaller than the packet size. */
1649 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1650 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1652 pack_threadlist_request (threadlist_packet
,
1653 startflag
, result_limit
, nextthread
);
1654 putpkt (threadlist_packet
);
1655 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1658 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1661 if (!threadmatch (&echo_nextthread
, nextthread
))
1663 /* FIXME: This is a good reason to drop the packet. */
1664 /* Possably, there is a duplicate response. */
1666 retransmit immediatly - race conditions
1667 retransmit after timeout - yes
1669 wait for packet, then exit
1671 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
1672 return 0; /* I choose simply exiting. */
1674 if (*result_count
<= 0)
1678 warning (_("RMT ERROR : failed to get remote thread list."));
1681 return result
; /* break; */
1683 if (*result_count
> result_limit
)
1686 warning (_("RMT ERROR: threadlist response longer than requested."));
1692 /* This is the interface between remote and threads, remotes upper
1695 /* remote_find_new_threads retrieves the thread list and for each
1696 thread in the list, looks up the thread in GDB's internal list,
1697 ading the thread if it does not already exist. This involves
1698 getting partial thread lists from the remote target so, polling the
1699 quit_flag is required. */
1702 /* About this many threadisds fit in a packet. */
1704 #define MAXTHREADLISTRESULTS 32
1707 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1710 int done
, i
, result_count
;
1714 static threadref nextthread
;
1715 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1720 if (loopcount
++ > looplimit
)
1723 warning (_("Remote fetch threadlist -infinite loop-."));
1726 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1727 &done
, &result_count
, resultthreadlist
))
1732 /* Clear for later iterations. */
1734 /* Setup to resume next batch of thread references, set nextthread. */
1735 if (result_count
>= 1)
1736 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1738 while (result_count
--)
1739 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1746 remote_newthread_step (threadref
*ref
, void *context
)
1750 ptid
= pid_to_ptid (threadref_to_int (ref
));
1752 if (!in_thread_list (ptid
))
1754 return 1; /* continue iterator */
1757 #define CRAZY_MAX_THREADS 1000
1760 remote_current_thread (ptid_t oldpid
)
1762 struct remote_state
*rs
= get_remote_state ();
1763 char *buf
= alloca (rs
->remote_packet_size
);
1766 getpkt (buf
, (rs
->remote_packet_size
), 0);
1767 if (buf
[0] == 'Q' && buf
[1] == 'C')
1768 /* Use strtoul here, so we'll correctly parse values whose highest
1769 bit is set. The protocol carries them as a simple series of
1770 hex digits; in the absence of a sign, strtol will see such
1771 values as positive numbers out of range for signed 'long', and
1772 return LONG_MAX to indicate an overflow. */
1773 return pid_to_ptid (strtoul (&buf
[2], NULL
, 16));
1778 /* Find new threads for info threads command.
1779 * Original version, using John Metzler's thread protocol.
1783 remote_find_new_threads (void)
1785 remote_threadlist_iterator (remote_newthread_step
, 0,
1787 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1788 inferior_ptid
= remote_current_thread (inferior_ptid
);
1792 * Find all threads for info threads command.
1793 * Uses new thread protocol contributed by Cisco.
1794 * Falls back and attempts to use the older method (above)
1795 * if the target doesn't respond to the new method.
1799 remote_threads_info (void)
1801 struct remote_state
*rs
= get_remote_state ();
1802 char *buf
= alloca (rs
->remote_packet_size
);
1806 if (remote_desc
== 0) /* paranoia */
1807 error (_("Command can only be used when connected to the remote target."));
1809 if (use_threadinfo_query
)
1811 putpkt ("qfThreadInfo");
1813 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1814 if (bufp
[0] != '\0') /* q packet recognized */
1816 while (*bufp
++ == 'm') /* reply contains one or more TID */
1820 /* Use strtoul here, so we'll correctly parse values
1821 whose highest bit is set. The protocol carries
1822 them as a simple series of hex digits; in the
1823 absence of a sign, strtol will see such values as
1824 positive numbers out of range for signed 'long',
1825 and return LONG_MAX to indicate an overflow. */
1826 tid
= strtoul (bufp
, &bufp
, 16);
1827 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1828 add_thread (pid_to_ptid (tid
));
1830 while (*bufp
++ == ','); /* comma-separated list */
1831 putpkt ("qsThreadInfo");
1833 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1839 /* Else fall back to old method based on jmetzler protocol. */
1840 use_threadinfo_query
= 0;
1841 remote_find_new_threads ();
1846 * Collect a descriptive string about the given thread.
1847 * The target may say anything it wants to about the thread
1848 * (typically info about its blocked / runnable state, name, etc.).
1849 * This string will appear in the info threads display.
1851 * Optional: targets are not required to implement this function.
1855 remote_threads_extra_info (struct thread_info
*tp
)
1857 struct remote_state
*rs
= get_remote_state ();
1861 struct gdb_ext_thread_info threadinfo
;
1862 static char display_buf
[100]; /* arbitrary... */
1863 char *bufp
= alloca (rs
->remote_packet_size
);
1864 int n
= 0; /* position in display_buf */
1866 if (remote_desc
== 0) /* paranoia */
1867 internal_error (__FILE__
, __LINE__
,
1868 _("remote_threads_extra_info"));
1870 if (use_threadextra_query
)
1872 xsnprintf (bufp
, rs
->remote_packet_size
, "qThreadExtraInfo,%x",
1875 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1878 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1879 result
= hex2bin (bufp
, display_buf
, n
);
1880 display_buf
[result
] = '\0';
1885 /* If the above query fails, fall back to the old method. */
1886 use_threadextra_query
= 0;
1887 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1888 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1889 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1890 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1891 if (threadinfo
.active
)
1893 if (*threadinfo
.shortname
)
1894 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
1895 " Name: %s,", threadinfo
.shortname
);
1896 if (*threadinfo
.display
)
1897 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
1898 " State: %s,", threadinfo
.display
);
1899 if (*threadinfo
.more_display
)
1900 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
1901 " Priority: %s", threadinfo
.more_display
);
1905 /* For purely cosmetic reasons, clear up trailing commas. */
1906 if (',' == display_buf
[n
-1])
1907 display_buf
[n
-1] = ' ';
1916 /* Restart the remote side; this is an extended protocol operation. */
1919 extended_remote_restart (void)
1921 struct remote_state
*rs
= get_remote_state ();
1922 char *buf
= alloca (rs
->remote_packet_size
);
1924 /* Send the restart command; for reasons I don't understand the
1925 remote side really expects a number after the "R". */
1926 xsnprintf (buf
, rs
->remote_packet_size
, "R%x", 0);
1929 /* Now query for status so this looks just like we restarted
1930 gdbserver from scratch. */
1932 getpkt (buf
, (rs
->remote_packet_size
), 0);
1935 /* Clean up connection to a remote debugger. */
1938 remote_close (int quitting
)
1941 serial_close (remote_desc
);
1945 /* Query the remote side for the text, data and bss offsets. */
1950 struct remote_state
*rs
= get_remote_state ();
1951 char *buf
= alloca (rs
->remote_packet_size
);
1954 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1955 struct section_offsets
*offs
;
1957 putpkt ("qOffsets");
1959 getpkt (buf
, (rs
->remote_packet_size
), 0);
1961 if (buf
[0] == '\000')
1962 return; /* Return silently. Stub doesn't support
1966 warning (_("Remote failure reply: %s"), buf
);
1970 /* Pick up each field in turn. This used to be done with scanf, but
1971 scanf will make trouble if CORE_ADDR size doesn't match
1972 conversion directives correctly. The following code will work
1973 with any size of CORE_ADDR. */
1974 text_addr
= data_addr
= bss_addr
= 0;
1978 if (strncmp (ptr
, "Text=", 5) == 0)
1981 /* Don't use strtol, could lose on big values. */
1982 while (*ptr
&& *ptr
!= ';')
1983 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1988 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1991 while (*ptr
&& *ptr
!= ';')
1992 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1997 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2000 while (*ptr
&& *ptr
!= ';')
2001 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2007 error (_("Malformed response to offset query, %s"), buf
);
2009 if (symfile_objfile
== NULL
)
2012 offs
= ((struct section_offsets
*)
2013 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2014 memcpy (offs
, symfile_objfile
->section_offsets
,
2015 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2017 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2019 /* This is a temporary kludge to force data and bss to use the same offsets
2020 because that's what nlmconv does now. The real solution requires changes
2021 to the stub and remote.c that I don't have time to do right now. */
2023 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2024 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2026 objfile_relocate (symfile_objfile
, offs
);
2029 /* Stub for catch_errors. */
2032 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2034 start_remote (); /* Initialize gdb process mechanisms. */
2035 /* NOTE: Return something >=0. A -ve value is reserved for
2036 catch_exceptions. */
2041 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2043 immediate_quit
++; /* Allow user to interrupt it. */
2045 /* Ack any packet which the remote side has already sent. */
2046 serial_write (remote_desc
, "+", 1);
2048 /* Let the stub know that we want it to return the thread. */
2051 inferior_ptid
= remote_current_thread (inferior_ptid
);
2053 get_offsets (); /* Get text, data & bss offsets. */
2055 putpkt ("?"); /* Initiate a query from remote machine. */
2058 remote_start_remote_dummy (uiout
, dummy
);
2061 /* Open a connection to a remote debugger.
2062 NAME is the filename used for communication. */
2065 remote_open (char *name
, int from_tty
)
2067 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2070 /* Just like remote_open, but with asynchronous support. */
2072 remote_async_open (char *name
, int from_tty
)
2074 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2077 /* Open a connection to a remote debugger using the extended
2078 remote gdb protocol. NAME is the filename used for communication. */
2081 extended_remote_open (char *name
, int from_tty
)
2083 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2087 /* Just like extended_remote_open, but with asynchronous support. */
2089 extended_remote_async_open (char *name
, int from_tty
)
2091 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2092 1 /*extended_p */, 1 /* async_p */);
2095 /* Generic code for opening a connection to a remote target. */
2098 init_all_packet_configs (void)
2101 update_packet_config (&remote_protocol_P
);
2102 update_packet_config (&remote_protocol_p
);
2103 update_packet_config (&remote_protocol_qSymbol
);
2104 update_packet_config (&remote_protocol_vcont
);
2105 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2106 update_packet_config (&remote_protocol_Z
[i
]);
2107 /* Force remote_write_bytes to check whether target supports binary
2109 update_packet_config (&remote_protocol_binary_download
);
2110 update_packet_config (&remote_protocol_qPart_auxv
);
2111 update_packet_config (&remote_protocol_qGetTLSAddr
);
2114 /* Symbol look-up. */
2117 remote_check_symbols (struct objfile
*objfile
)
2119 struct remote_state
*rs
= get_remote_state ();
2120 char *msg
, *reply
, *tmp
;
2121 struct minimal_symbol
*sym
;
2124 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2127 msg
= alloca (rs
->remote_packet_size
);
2128 reply
= alloca (rs
->remote_packet_size
);
2130 /* Invite target to request symbol lookups. */
2132 putpkt ("qSymbol::");
2133 getpkt (reply
, (rs
->remote_packet_size
), 0);
2134 packet_ok (reply
, &remote_protocol_qSymbol
);
2136 while (strncmp (reply
, "qSymbol:", 8) == 0)
2139 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2141 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2143 xsnprintf (msg
, rs
->remote_packet_size
, "qSymbol::%s", &reply
[8]);
2145 xsnprintf (msg
, rs
->remote_packet_size
, "qSymbol:%s:%s",
2146 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2149 getpkt (reply
, (rs
->remote_packet_size
), 0);
2153 static struct serial
*
2154 remote_serial_open (char *name
)
2156 static int udp_warning
= 0;
2158 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2159 of in ser-tcp.c, because it is the remote protocol assuming that the
2160 serial connection is reliable and not the serial connection promising
2162 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2165 The remote protocol may be unreliable over UDP.\n\
2166 Some events may be lost, rendering further debugging impossible."));
2170 return serial_open (name
);
2174 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2175 int extended_p
, int async_p
)
2177 struct remote_state
*rs
= get_remote_state ();
2179 error (_("To open a remote debug connection, you need to specify what\n"
2180 "serial device is attached to the remote system\n"
2181 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
2183 /* See FIXME above. */
2185 wait_forever_enabled_p
= 1;
2187 reopen_exec_file ();
2190 target_preopen (from_tty
);
2192 unpush_target (target
);
2194 remote_desc
= remote_serial_open (name
);
2196 perror_with_name (name
);
2198 if (baud_rate
!= -1)
2200 if (serial_setbaudrate (remote_desc
, baud_rate
))
2202 /* The requested speed could not be set. Error out to
2203 top level after closing remote_desc. Take care to
2204 set remote_desc to NULL to avoid closing remote_desc
2206 serial_close (remote_desc
);
2208 perror_with_name (name
);
2212 serial_raw (remote_desc
);
2214 /* If there is something sitting in the buffer we might take it as a
2215 response to a command, which would be bad. */
2216 serial_flush_input (remote_desc
);
2220 puts_filtered ("Remote debugging using ");
2221 puts_filtered (name
);
2222 puts_filtered ("\n");
2224 push_target (target
); /* Switch to using remote target now. */
2226 init_all_packet_configs ();
2228 general_thread
= -2;
2229 continue_thread
= -2;
2231 /* Probe for ability to use "ThreadInfo" query, as required. */
2232 use_threadinfo_query
= 1;
2233 use_threadextra_query
= 1;
2235 /* Without this, some commands which require an active target (such
2236 as kill) won't work. This variable serves (at least) double duty
2237 as both the pid of the target process (if it has such), and as a
2238 flag indicating that a target is active. These functions should
2239 be split out into seperate variables, especially since GDB will
2240 someday have a notion of debugging several processes. */
2242 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2246 /* With this target we start out by owning the terminal. */
2247 remote_async_terminal_ours_p
= 1;
2249 /* FIXME: cagney/1999-09-23: During the initial connection it is
2250 assumed that the target is already ready and able to respond to
2251 requests. Unfortunately remote_start_remote() eventually calls
2252 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2253 around this. Eventually a mechanism that allows
2254 wait_for_inferior() to expect/get timeouts will be
2256 wait_forever_enabled_p
= 0;
2259 /* First delete any symbols previously loaded from shared libraries. */
2260 no_shared_libraries (NULL
, 0);
2262 /* Start the remote connection. If error() or QUIT, discard this
2263 target (we'd otherwise be in an inconsistent state) and then
2264 propogate the error on up the exception chain. This ensures that
2265 the caller doesn't stumble along blindly assuming that the
2266 function succeeded. The CLI doesn't have this problem but other
2267 UI's, such as MI do.
2269 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2270 this function should return an error indication letting the
2271 caller restore the previous state. Unfortunately the command
2272 ``target remote'' is directly wired to this function making that
2273 impossible. On a positive note, the CLI side of this problem has
2274 been fixed - the function set_cmd_context() makes it possible for
2275 all the ``target ....'' commands to share a common callback
2276 function. See cli-dump.c. */
2278 struct gdb_exception ex
2279 = catch_exception (uiout
, remote_start_remote
, NULL
, RETURN_MASK_ALL
);
2284 wait_forever_enabled_p
= 1;
2285 throw_exception (ex
);
2290 wait_forever_enabled_p
= 1;
2294 /* Tell the remote that we are using the extended protocol. */
2295 char *buf
= alloca (rs
->remote_packet_size
);
2297 getpkt (buf
, (rs
->remote_packet_size
), 0);
2300 /* FIXME: need a master target_open vector from which all
2301 remote_opens can be called, so that stuff like this can
2302 go there. Failing that, the following code must be copied
2303 to the open function for any remote target that wants to
2304 support svr4 shared libraries. */
2306 /* Set up to detect and load shared libraries. */
2307 if (exec_bfd
) /* No use without an exec file. */
2309 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2310 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2312 solib_create_inferior_hook ();
2314 remote_check_symbols (symfile_objfile
);
2317 observer_notify_inferior_created (¤t_target
, from_tty
);
2320 /* This takes a program previously attached to and detaches it. After
2321 this is done, GDB can be used to debug some other program. We
2322 better not have left any breakpoints in the target program or it'll
2323 die when it hits one. */
2326 remote_detach (char *args
, int from_tty
)
2328 struct remote_state
*rs
= get_remote_state ();
2329 char *buf
= alloca (rs
->remote_packet_size
);
2332 error (_("Argument given to \"detach\" when remotely debugging."));
2334 /* Tell the remote target to detach. */
2336 remote_send (buf
, (rs
->remote_packet_size
));
2338 /* Unregister the file descriptor from the event loop. */
2339 if (target_is_async_p ())
2340 serial_async (remote_desc
, NULL
, 0);
2342 target_mourn_inferior ();
2344 puts_filtered ("Ending remote debugging.\n");
2347 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2350 remote_disconnect (char *args
, int from_tty
)
2353 error (_("Argument given to \"detach\" when remotely debugging."));
2355 /* Unregister the file descriptor from the event loop. */
2356 if (target_is_async_p ())
2357 serial_async (remote_desc
, NULL
, 0);
2359 target_mourn_inferior ();
2361 puts_filtered ("Ending remote debugging.\n");
2364 /* Convert hex digit A to a number. */
2369 if (a
>= '0' && a
<= '9')
2371 else if (a
>= 'a' && a
<= 'f')
2372 return a
- 'a' + 10;
2373 else if (a
>= 'A' && a
<= 'F')
2374 return a
- 'A' + 10;
2376 error (_("Reply contains invalid hex digit %d"), a
);
2380 hex2bin (const char *hex
, char *bin
, int count
)
2384 for (i
= 0; i
< count
; i
++)
2386 if (hex
[0] == 0 || hex
[1] == 0)
2388 /* Hex string is short, or of uneven length.
2389 Return the count that has been converted so far. */
2392 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2398 /* Convert number NIB to a hex digit. */
2406 return 'a' + nib
- 10;
2410 bin2hex (const char *bin
, char *hex
, int count
)
2413 /* May use a length, or a nul-terminated string as input. */
2415 count
= strlen (bin
);
2417 for (i
= 0; i
< count
; i
++)
2419 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2420 *hex
++ = tohex (*bin
++ & 0xf);
2426 /* Check for the availability of vCont. This function should also check
2430 remote_vcont_probe (struct remote_state
*rs
, char *buf
)
2432 strcpy (buf
, "vCont?");
2434 getpkt (buf
, rs
->remote_packet_size
, 0);
2436 /* Make sure that the features we assume are supported. */
2437 if (strncmp (buf
, "vCont", 5) == 0)
2440 int support_s
, support_S
, support_c
, support_C
;
2446 while (p
&& *p
== ';')
2449 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2451 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2453 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2455 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2458 p
= strchr (p
, ';');
2461 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
2462 BUF will make packet_ok disable the packet. */
2463 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
2467 packet_ok (buf
, &remote_protocol_vcont
);
2470 /* Resume the remote inferior by using a "vCont" packet. The thread
2471 to be resumed is PTID; STEP and SIGGNAL indicate whether the
2472 resumed thread should be single-stepped and/or signalled. If PTID's
2473 PID is -1, then all threads are resumed; the thread to be stepped and/or
2474 signalled is given in the global INFERIOR_PTID. This function returns
2475 non-zero iff it resumes the inferior.
2477 This function issues a strict subset of all possible vCont commands at the
2481 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2483 struct remote_state
*rs
= get_remote_state ();
2484 int pid
= PIDGET (ptid
);
2485 char *buf
= NULL
, *outbuf
;
2486 struct cleanup
*old_cleanup
;
2488 buf
= xmalloc (rs
->remote_packet_size
);
2489 old_cleanup
= make_cleanup (xfree
, buf
);
2491 if (remote_protocol_vcont
.support
== PACKET_SUPPORT_UNKNOWN
)
2492 remote_vcont_probe (rs
, buf
);
2494 if (remote_protocol_vcont
.support
== PACKET_DISABLE
)
2496 do_cleanups (old_cleanup
);
2500 /* If we could generate a wider range of packets, we'd have to worry
2501 about overflowing BUF. Should there be a generic
2502 "multi-part-packet" packet? */
2504 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
)
2506 /* MAGIC_NULL_PTID means that we don't have any active threads, so we
2507 don't have any PID numbers the inferior will understand. Make sure
2508 to only send forms that do not specify a PID. */
2509 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2510 outbuf
= xstrprintf ("vCont;S%02x", siggnal
);
2512 outbuf
= xstrprintf ("vCont;s");
2513 else if (siggnal
!= TARGET_SIGNAL_0
)
2514 outbuf
= xstrprintf ("vCont;C%02x", siggnal
);
2516 outbuf
= xstrprintf ("vCont;c");
2520 /* Resume all threads, with preference for INFERIOR_PTID. */
2521 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2522 outbuf
= xstrprintf ("vCont;S%02x:%x;c", siggnal
,
2523 PIDGET (inferior_ptid
));
2525 outbuf
= xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid
));
2526 else if (siggnal
!= TARGET_SIGNAL_0
)
2527 outbuf
= xstrprintf ("vCont;C%02x:%x;c", siggnal
,
2528 PIDGET (inferior_ptid
));
2530 outbuf
= xstrprintf ("vCont;c");
2534 /* Scheduler locking; resume only PTID. */
2535 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2536 outbuf
= xstrprintf ("vCont;S%02x:%x", siggnal
, pid
);
2538 outbuf
= xstrprintf ("vCont;s:%x", pid
);
2539 else if (siggnal
!= TARGET_SIGNAL_0
)
2540 outbuf
= xstrprintf ("vCont;C%02x:%x", siggnal
, pid
);
2542 outbuf
= xstrprintf ("vCont;c:%x", pid
);
2545 gdb_assert (outbuf
&& strlen (outbuf
) < rs
->remote_packet_size
);
2546 make_cleanup (xfree
, outbuf
);
2550 do_cleanups (old_cleanup
);
2555 /* Tell the remote machine to resume. */
2557 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2559 static int last_sent_step
;
2562 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2564 struct remote_state
*rs
= get_remote_state ();
2565 char *buf
= alloca (rs
->remote_packet_size
);
2566 int pid
= PIDGET (ptid
);
2568 last_sent_signal
= siggnal
;
2569 last_sent_step
= step
;
2571 /* A hook for when we need to do something at the last moment before
2573 if (deprecated_target_resume_hook
)
2574 (*deprecated_target_resume_hook
) ();
2576 /* The vCont packet doesn't need to specify threads via Hc. */
2577 if (remote_vcont_resume (ptid
, step
, siggnal
))
2580 /* All other supported resume packets do use Hc, so call set_thread. */
2582 set_thread (0, 0); /* Run any thread. */
2584 set_thread (pid
, 0); /* Run this thread. */
2586 if (siggnal
!= TARGET_SIGNAL_0
)
2588 buf
[0] = step
? 'S' : 'C';
2589 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2590 buf
[2] = tohex (((int) siggnal
) & 0xf);
2594 strcpy (buf
, step
? "s" : "c");
2599 /* Same as remote_resume, but with async support. */
2601 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2603 remote_resume (ptid
, step
, siggnal
);
2605 /* We are about to start executing the inferior, let's register it
2606 with the event loop. NOTE: this is the one place where all the
2607 execution commands end up. We could alternatively do this in each
2608 of the execution commands in infcmd.c. */
2609 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2610 into infcmd.c in order to allow inferior function calls to work
2611 NOT asynchronously. */
2612 if (target_can_async_p ())
2613 target_async (inferior_event_handler
, 0);
2614 /* Tell the world that the target is now executing. */
2615 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2616 this? Instead, should the client of target just assume (for
2617 async targets) that the target is going to start executing? Is
2618 this information already found in the continuation block? */
2619 if (target_is_async_p ())
2620 target_executing
= 1;
2624 /* Set up the signal handler for SIGINT, while the target is
2625 executing, ovewriting the 'regular' SIGINT signal handler. */
2627 initialize_sigint_signal_handler (void)
2629 sigint_remote_token
=
2630 create_async_signal_handler (async_remote_interrupt
, NULL
);
2631 signal (SIGINT
, handle_remote_sigint
);
2634 /* Signal handler for SIGINT, while the target is executing. */
2636 handle_remote_sigint (int sig
)
2638 signal (sig
, handle_remote_sigint_twice
);
2639 sigint_remote_twice_token
=
2640 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2641 mark_async_signal_handler_wrapper (sigint_remote_token
);
2644 /* Signal handler for SIGINT, installed after SIGINT has already been
2645 sent once. It will take effect the second time that the user sends
2648 handle_remote_sigint_twice (int sig
)
2650 signal (sig
, handle_sigint
);
2651 sigint_remote_twice_token
=
2652 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2653 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2656 /* Perform the real interruption of the target execution, in response
2659 async_remote_interrupt (gdb_client_data arg
)
2662 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2667 /* Perform interrupt, if the first attempt did not succeed. Just give
2668 up on the target alltogether. */
2670 async_remote_interrupt_twice (gdb_client_data arg
)
2673 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2674 /* Do something only if the target was not killed by the previous
2676 if (target_executing
)
2679 signal (SIGINT
, handle_remote_sigint
);
2683 /* Reinstall the usual SIGINT handlers, after the target has
2686 cleanup_sigint_signal_handler (void *dummy
)
2688 signal (SIGINT
, handle_sigint
);
2689 if (sigint_remote_twice_token
)
2690 delete_async_signal_handler ((struct async_signal_handler
**)
2691 &sigint_remote_twice_token
);
2692 if (sigint_remote_token
)
2693 delete_async_signal_handler ((struct async_signal_handler
**)
2694 &sigint_remote_token
);
2697 /* Send ^C to target to halt it. Target will respond, and send us a
2699 static void (*ofunc
) (int);
2701 /* The command line interface's stop routine. This function is installed
2702 as a signal handler for SIGINT. The first time a user requests a
2703 stop, we call remote_stop to send a break or ^C. If there is no
2704 response from the target (it didn't stop when the user requested it),
2705 we ask the user if he'd like to detach from the target. */
2707 remote_interrupt (int signo
)
2709 /* If this doesn't work, try more severe steps. */
2710 signal (signo
, remote_interrupt_twice
);
2713 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2718 /* The user typed ^C twice. */
2721 remote_interrupt_twice (int signo
)
2723 signal (signo
, ofunc
);
2725 signal (signo
, remote_interrupt
);
2728 /* This is the generic stop called via the target vector. When a target
2729 interrupt is requested, either by the command line or the GUI, we
2730 will eventually end up here. */
2734 /* Send a break or a ^C, depending on user preference. */
2736 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2739 serial_send_break (remote_desc
);
2741 serial_write (remote_desc
, "\003", 1);
2744 /* Ask the user what to do when an interrupt is received. */
2747 interrupt_query (void)
2749 target_terminal_ours ();
2751 if (query ("Interrupted while waiting for the program.\n\
2752 Give up (and stop debugging it)? "))
2754 target_mourn_inferior ();
2755 deprecated_throw_reason (RETURN_QUIT
);
2758 target_terminal_inferior ();
2761 /* Enable/disable target terminal ownership. Most targets can use
2762 terminal groups to control terminal ownership. Remote targets are
2763 different in that explicit transfer of ownership to/from GDB/target
2767 remote_async_terminal_inferior (void)
2769 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2770 sync_execution here. This function should only be called when
2771 GDB is resuming the inferior in the forground. A background
2772 resume (``run&'') should leave GDB in control of the terminal and
2773 consequently should not call this code. */
2774 if (!sync_execution
)
2776 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2777 calls target_terminal_*() idenpotent. The event-loop GDB talking
2778 to an asynchronous target with a synchronous command calls this
2779 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2780 stops trying to transfer the terminal to the target when it
2781 shouldn't this guard can go away. */
2782 if (!remote_async_terminal_ours_p
)
2784 delete_file_handler (input_fd
);
2785 remote_async_terminal_ours_p
= 0;
2786 initialize_sigint_signal_handler ();
2787 /* NOTE: At this point we could also register our selves as the
2788 recipient of all input. Any characters typed could then be
2789 passed on down to the target. */
2793 remote_async_terminal_ours (void)
2795 /* See FIXME in remote_async_terminal_inferior. */
2796 if (!sync_execution
)
2798 /* See FIXME in remote_async_terminal_inferior. */
2799 if (remote_async_terminal_ours_p
)
2801 cleanup_sigint_signal_handler (NULL
);
2802 add_file_handler (input_fd
, stdin_event_handler
, 0);
2803 remote_async_terminal_ours_p
= 1;
2806 /* If nonzero, ignore the next kill. */
2811 remote_console_output (char *msg
)
2815 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2818 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2821 fputs_unfiltered (tb
, gdb_stdtarg
);
2823 gdb_flush (gdb_stdtarg
);
2826 /* Wait until the remote machine stops, then return,
2827 storing status in STATUS just as `wait' would.
2828 Returns "pid", which in the case of a multi-threaded
2829 remote OS, is the thread-id. */
2832 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2834 struct remote_state
*rs
= get_remote_state ();
2835 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2836 ULONGEST thread_num
= -1;
2839 status
->kind
= TARGET_WAITKIND_EXITED
;
2840 status
->value
.integer
= 0;
2846 ofunc
= signal (SIGINT
, remote_interrupt
);
2847 getpkt (buf
, (rs
->remote_packet_size
), 1);
2848 signal (SIGINT
, ofunc
);
2850 /* This is a hook for when we need to do something (perhaps the
2851 collection of trace data) every time the target stops. */
2852 if (deprecated_target_wait_loop_hook
)
2853 (*deprecated_target_wait_loop_hook
) ();
2855 remote_stopped_by_watchpoint_p
= 0;
2859 case 'E': /* Error of some sort. */
2860 warning (_("Remote failure reply: %s"), buf
);
2862 case 'F': /* File-I/O request. */
2863 remote_fileio_request (buf
);
2865 case 'T': /* Status with PC, SP, FP, ... */
2867 char regs
[MAX_REGISTER_SIZE
];
2869 /* Expedited reply, containing Signal, {regno, reg} repeat. */
2870 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2872 n... = register number
2873 r... = register contents
2875 p
= &buf
[3]; /* after Txx */
2884 /* If the packet contains a register number save it in
2885 pnum and set p1 to point to the character following
2886 it. Otherwise p1 points to p. */
2888 /* If this packet is an awatch packet, don't parse the
2889 'a' as a register number. */
2891 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
2893 /* Read the ``P'' register number. */
2894 pnum
= strtol (p
, &p_temp
, 16);
2895 p1
= (unsigned char *) p_temp
;
2900 if (p1
== p
) /* No register number present here. */
2902 p1
= (unsigned char *) strchr (p
, ':');
2904 warning (_("Malformed packet(a) (missing colon): %s\n\
2907 if (strncmp (p
, "thread", p1
- p
) == 0)
2909 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2910 record_currthread (thread_num
);
2911 p
= (unsigned char *) p_temp
;
2913 else if ((strncmp (p
, "watch", p1
- p
) == 0)
2914 || (strncmp (p
, "rwatch", p1
- p
) == 0)
2915 || (strncmp (p
, "awatch", p1
- p
) == 0))
2917 remote_stopped_by_watchpoint_p
= 1;
2918 p
= unpack_varlen_hex (++p1
, &addr
);
2919 remote_watch_data_address
= (CORE_ADDR
)addr
;
2923 /* Silently skip unknown optional info. */
2924 p_temp
= strchr (p1
+ 1, ';');
2926 p
= (unsigned char *) p_temp
;
2931 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
2935 error (_("Malformed packet(b) (missing colon): %s\n\
2940 error (_("Remote sent bad register number %s: %s\n\
2942 phex_nz (pnum
, 0), p
, buf
);
2944 fieldsize
= hex2bin (p
, regs
,
2945 register_size (current_gdbarch
,
2948 if (fieldsize
< register_size (current_gdbarch
,
2950 warning (_("Remote reply is too short: %s"), buf
);
2951 regcache_raw_supply (current_regcache
,
2956 error (_("Remote register badly formatted: %s\nhere: %s"),
2961 case 'S': /* Old style status, just signal only. */
2962 status
->kind
= TARGET_WAITKIND_STOPPED
;
2963 status
->value
.sig
= (enum target_signal
)
2964 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2968 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2969 record_currthread (thread_num
);
2972 case 'W': /* Target exited. */
2974 /* The remote process exited. */
2975 status
->kind
= TARGET_WAITKIND_EXITED
;
2976 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2980 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2981 status
->value
.sig
= (enum target_signal
)
2982 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2986 case 'O': /* Console output. */
2987 remote_console_output (buf
+ 1);
2990 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2992 /* Zero length reply means that we tried 'S' or 'C' and
2993 the remote system doesn't support it. */
2994 target_terminal_ours_for_output ();
2996 ("Can't send signals to this remote system. %s not sent.\n",
2997 target_signal_to_name (last_sent_signal
));
2998 last_sent_signal
= TARGET_SIGNAL_0
;
2999 target_terminal_inferior ();
3001 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3002 putpkt ((char *) buf
);
3005 /* else fallthrough */
3007 warning (_("Invalid remote reply: %s"), buf
);
3012 if (thread_num
!= -1)
3014 return pid_to_ptid (thread_num
);
3016 return inferior_ptid
;
3019 /* Async version of remote_wait. */
3021 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3023 struct remote_state
*rs
= get_remote_state ();
3024 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3025 ULONGEST thread_num
= -1;
3028 status
->kind
= TARGET_WAITKIND_EXITED
;
3029 status
->value
.integer
= 0;
3031 remote_stopped_by_watchpoint_p
= 0;
3037 if (!target_is_async_p ())
3038 ofunc
= signal (SIGINT
, remote_interrupt
);
3039 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3040 _never_ wait for ever -> test on target_is_async_p().
3041 However, before we do that we need to ensure that the caller
3042 knows how to take the target into/out of async mode. */
3043 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3044 if (!target_is_async_p ())
3045 signal (SIGINT
, ofunc
);
3047 /* This is a hook for when we need to do something (perhaps the
3048 collection of trace data) every time the target stops. */
3049 if (deprecated_target_wait_loop_hook
)
3050 (*deprecated_target_wait_loop_hook
) ();
3054 case 'E': /* Error of some sort. */
3055 warning (_("Remote failure reply: %s"), buf
);
3057 case 'F': /* File-I/O request. */
3058 remote_fileio_request (buf
);
3060 case 'T': /* Status with PC, SP, FP, ... */
3062 char regs
[MAX_REGISTER_SIZE
];
3064 /* Expedited reply, containing Signal, {regno, reg} repeat. */
3065 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3067 n... = register number
3068 r... = register contents
3070 p
= &buf
[3]; /* after Txx */
3079 /* If the packet contains a register number, save it
3080 in pnum and set p1 to point to the character
3081 following it. Otherwise p1 points to p. */
3083 /* If this packet is an awatch packet, don't parse the 'a'
3084 as a register number. */
3086 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3088 /* Read the register number. */
3089 pnum
= strtol (p
, &p_temp
, 16);
3090 p1
= (unsigned char *) p_temp
;
3095 if (p1
== p
) /* No register number present here. */
3097 p1
= (unsigned char *) strchr (p
, ':');
3099 error (_("Malformed packet(a) (missing colon): %s\n\
3102 if (strncmp (p
, "thread", p1
- p
) == 0)
3104 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3105 record_currthread (thread_num
);
3106 p
= (unsigned char *) p_temp
;
3108 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3109 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3110 || (strncmp (p
, "awatch", p1
- p
) == 0))
3112 remote_stopped_by_watchpoint_p
= 1;
3113 p
= unpack_varlen_hex (++p1
, &addr
);
3114 remote_watch_data_address
= (CORE_ADDR
)addr
;
3118 /* Silently skip unknown optional info. */
3119 p_temp
= (unsigned char *) strchr (p1
+ 1, ';');
3127 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3130 error (_("Malformed packet(b) (missing colon): %s\n\
3135 error (_("Remote sent bad register number %ld: %s\n\
3139 fieldsize
= hex2bin (p
, regs
,
3140 register_size (current_gdbarch
,
3143 if (fieldsize
< register_size (current_gdbarch
,
3145 warning (_("Remote reply is too short: %s"), buf
);
3146 regcache_raw_supply (current_regcache
, reg
->regnum
, regs
);
3150 error (_("Remote register badly formatted: %s\nhere: %s"),
3155 case 'S': /* Old style status, just signal only. */
3156 status
->kind
= TARGET_WAITKIND_STOPPED
;
3157 status
->value
.sig
= (enum target_signal
)
3158 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3162 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3163 record_currthread (thread_num
);
3166 case 'W': /* Target exited. */
3168 /* The remote process exited. */
3169 status
->kind
= TARGET_WAITKIND_EXITED
;
3170 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3174 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3175 status
->value
.sig
= (enum target_signal
)
3176 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3180 case 'O': /* Console output. */
3181 remote_console_output (buf
+ 1);
3182 /* Return immediately to the event loop. The event loop will
3183 still be waiting on the inferior afterwards. */
3184 status
->kind
= TARGET_WAITKIND_IGNORE
;
3187 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3189 /* Zero length reply means that we tried 'S' or 'C' and
3190 the remote system doesn't support it. */
3191 target_terminal_ours_for_output ();
3193 ("Can't send signals to this remote system. %s not sent.\n",
3194 target_signal_to_name (last_sent_signal
));
3195 last_sent_signal
= TARGET_SIGNAL_0
;
3196 target_terminal_inferior ();
3198 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3199 putpkt ((char *) buf
);
3202 /* else fallthrough */
3204 warning (_("Invalid remote reply: %s"), buf
);
3209 if (thread_num
!= -1)
3211 return pid_to_ptid (thread_num
);
3213 return inferior_ptid
;
3216 /* Number of bytes of registers this stub implements. */
3218 static int register_bytes_found
;
3220 /* Read the remote registers into the block REGS. */
3221 /* Currently we just read all the registers, so we don't use regnum. */
3224 fetch_register_using_p (int regnum
)
3226 struct remote_state
*rs
= get_remote_state ();
3227 char *buf
= alloca (rs
->remote_packet_size
), *p
;
3228 char regp
[MAX_REGISTER_SIZE
];
3233 p
+= hexnumstr (p
, regnum
);
3235 remote_send (buf
, rs
->remote_packet_size
);
3237 /* If the stub didn't recognize the packet, or if we got an error,
3239 if (buf
[0] == '\0' || buf
[0] == 'E')
3242 /* If this register is unfetchable, tell the regcache. */
3245 regcache_raw_supply (current_regcache
, regnum
, NULL
);
3246 set_register_cached (regnum
, -1);
3250 /* Otherwise, parse and supply the value. */
3257 error (_("fetch_register_using_p: early buf termination"));
3261 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3264 regcache_raw_supply (current_regcache
, regnum
, regp
);
3269 remote_fetch_registers (int regnum
)
3271 struct remote_state
*rs
= get_remote_state ();
3272 char *buf
= alloca (rs
->remote_packet_size
);
3275 char *regs
= alloca (rs
->sizeof_g_packet
);
3277 set_thread (PIDGET (inferior_ptid
), 1);
3281 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3282 gdb_assert (reg
!= NULL
);
3283 if (!reg
->in_g_packet
)
3284 internal_error (__FILE__
, __LINE__
,
3285 _("Attempt to fetch a non G-packet register when this "
3286 "remote.c does not support the p-packet."));
3288 switch (remote_protocol_p
.support
)
3290 case PACKET_DISABLE
:
3293 if (fetch_register_using_p (regnum
))
3296 error (_("Protocol error: p packet not recognized by stub"));
3297 case PACKET_SUPPORT_UNKNOWN
:
3298 if (fetch_register_using_p (regnum
))
3300 /* The stub recognized the 'p' packet. Remember this. */
3301 remote_protocol_p
.support
= PACKET_ENABLE
;
3306 /* The stub does not support the 'P' packet. Use 'G'
3307 instead, and don't try using 'P' in the future (it
3308 will just waste our time). */
3309 remote_protocol_p
.support
= PACKET_DISABLE
;
3315 remote_send (buf
, (rs
->remote_packet_size
));
3317 /* Save the size of the packet sent to us by the target. Its used
3318 as a heuristic when determining the max size of packets that the
3319 target can safely receive. */
3320 if ((rs
->actual_register_packet_size
) == 0)
3321 (rs
->actual_register_packet_size
) = strlen (buf
);
3323 /* Unimplemented registers read as all bits zero. */
3324 memset (regs
, 0, rs
->sizeof_g_packet
);
3326 /* We can get out of synch in various cases. If the first character
3327 in the buffer is not a hex character, assume that has happened
3328 and try to fetch another packet to read. */
3329 while ((buf
[0] < '0' || buf
[0] > '9')
3330 && (buf
[0] < 'A' || buf
[0] > 'F')
3331 && (buf
[0] < 'a' || buf
[0] > 'f')
3332 && buf
[0] != 'x') /* New: unavailable register value. */
3335 fprintf_unfiltered (gdb_stdlog
,
3336 "Bad register packet; fetching a new packet\n");
3337 getpkt (buf
, (rs
->remote_packet_size
), 0);
3340 /* Reply describes registers byte by byte, each byte encoded as two
3341 hex characters. Suck them all up, then supply them to the
3342 register cacheing/storage mechanism. */
3345 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3351 warning (_("Remote reply is of odd length: %s"), buf
);
3352 /* Don't change register_bytes_found in this case, and don't
3353 print a second warning. */
3356 if (p
[0] == 'x' && p
[1] == 'x')
3357 regs
[i
] = 0; /* 'x' */
3359 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3363 if (i
!= register_bytes_found
)
3365 register_bytes_found
= i
;
3366 if (REGISTER_BYTES_OK_P ()
3367 && !REGISTER_BYTES_OK (i
))
3368 warning (_("Remote reply is too short: %s"), buf
);
3374 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3376 struct packet_reg
*r
= &rs
->regs
[i
];
3379 if (r
->offset
* 2 >= strlen (buf
))
3380 /* A short packet that didn't include the register's
3381 value, this implies that the register is zero (and
3382 not that the register is unavailable). Supply that
3384 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3385 else if (buf
[r
->offset
* 2] == 'x')
3387 gdb_assert (r
->offset
* 2 < strlen (buf
));
3388 /* The register isn't available, mark it as such (at
3389 the same time setting the value to zero). */
3390 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3391 set_register_cached (i
, -1);
3394 regcache_raw_supply (current_regcache
, r
->regnum
,
3401 /* Prepare to store registers. Since we may send them all (using a
3402 'G' request), we have to read out the ones we don't want to change
3406 remote_prepare_to_store (void)
3408 struct remote_state
*rs
= get_remote_state ();
3410 char buf
[MAX_REGISTER_SIZE
];
3412 /* Make sure the entire registers array is valid. */
3413 switch (remote_protocol_P
.support
)
3415 case PACKET_DISABLE
:
3416 case PACKET_SUPPORT_UNKNOWN
:
3417 /* Make sure all the necessary registers are cached. */
3418 for (i
= 0; i
< NUM_REGS
; i
++)
3419 if (rs
->regs
[i
].in_g_packet
)
3420 regcache_raw_read (current_regcache
, rs
->regs
[i
].regnum
, buf
);
3427 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3428 packet was not recognized. */
3431 store_register_using_P (int regnum
)
3433 struct remote_state
*rs
= get_remote_state ();
3434 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3435 /* Try storing a single register. */
3436 char *buf
= alloca (rs
->remote_packet_size
);
3437 char regp
[MAX_REGISTER_SIZE
];
3440 xsnprintf (buf
, rs
->remote_packet_size
, "P%s=", phex_nz (reg
->pnum
, 0));
3441 p
= buf
+ strlen (buf
);
3442 regcache_raw_collect (current_regcache
, reg
->regnum
, regp
);
3443 bin2hex (regp
, p
, register_size (current_gdbarch
, reg
->regnum
));
3444 remote_send (buf
, rs
->remote_packet_size
);
3446 return buf
[0] != '\0';
3450 /* Store register REGNUM, or all registers if REGNUM == -1, from the
3451 contents of the register cache buffer. FIXME: ignores errors. */
3454 remote_store_registers (int regnum
)
3456 struct remote_state
*rs
= get_remote_state ();
3461 set_thread (PIDGET (inferior_ptid
), 1);
3465 switch (remote_protocol_P
.support
)
3467 case PACKET_DISABLE
:
3470 if (store_register_using_P (regnum
))
3473 error (_("Protocol error: P packet not recognized by stub"));
3474 case PACKET_SUPPORT_UNKNOWN
:
3475 if (store_register_using_P (regnum
))
3477 /* The stub recognized the 'P' packet. Remember this. */
3478 remote_protocol_P
.support
= PACKET_ENABLE
;
3483 /* The stub does not support the 'P' packet. Use 'G'
3484 instead, and don't try using 'P' in the future (it
3485 will just waste our time). */
3486 remote_protocol_P
.support
= PACKET_DISABLE
;
3492 /* Extract all the registers in the regcache copying them into a
3496 regs
= alloca (rs
->sizeof_g_packet
);
3497 memset (regs
, 0, rs
->sizeof_g_packet
);
3498 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3500 struct packet_reg
*r
= &rs
->regs
[i
];
3502 regcache_raw_collect (current_regcache
, r
->regnum
, regs
+ r
->offset
);
3506 /* Command describes registers byte by byte,
3507 each byte encoded as two hex characters. */
3508 buf
= alloca (rs
->remote_packet_size
);
3511 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3512 bin2hex (regs
, p
, register_bytes_found
);
3513 remote_send (buf
, (rs
->remote_packet_size
));
3517 /* Return the number of hex digits in num. */
3520 hexnumlen (ULONGEST num
)
3524 for (i
= 0; num
!= 0; i
++)
3530 /* Set BUF to the minimum number of hex digits representing NUM. */
3533 hexnumstr (char *buf
, ULONGEST num
)
3535 int len
= hexnumlen (num
);
3536 return hexnumnstr (buf
, num
, len
);
3540 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3543 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3549 for (i
= width
- 1; i
>= 0; i
--)
3551 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3558 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3561 remote_address_masked (CORE_ADDR addr
)
3563 if (remote_address_size
> 0
3564 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3566 /* Only create a mask when that mask can safely be constructed
3567 in a ULONGEST variable. */
3569 mask
= (mask
<< remote_address_size
) - 1;
3575 /* Determine whether the remote target supports binary downloading.
3576 This is accomplished by sending a no-op memory write of zero length
3577 to the target at the specified address. It does not suffice to send
3578 the whole packet, since many stubs strip the eighth bit and
3579 subsequently compute a wrong checksum, which causes real havoc with
3582 NOTE: This can still lose if the serial line is not eight-bit
3583 clean. In cases like this, the user should clear "remote
3587 check_binary_download (CORE_ADDR addr
)
3589 struct remote_state
*rs
= get_remote_state ();
3590 switch (remote_protocol_binary_download
.support
)
3592 case PACKET_DISABLE
:
3596 case PACKET_SUPPORT_UNKNOWN
:
3598 char *buf
= alloca (rs
->remote_packet_size
);
3603 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3605 p
+= hexnumstr (p
, (ULONGEST
) 0);
3609 putpkt_binary (buf
, (int) (p
- buf
));
3610 getpkt (buf
, (rs
->remote_packet_size
), 0);
3615 fprintf_unfiltered (gdb_stdlog
,
3616 "binary downloading NOT suppported by target\n");
3617 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3622 fprintf_unfiltered (gdb_stdlog
,
3623 "binary downloading suppported by target\n");
3624 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3631 /* Write memory data directly to the remote machine.
3632 This does not inform the data cache; the data cache uses this.
3633 MEMADDR is the address in the remote memory space.
3634 MYADDR is the address of the buffer in our space.
3635 LEN is the number of bytes.
3637 Returns number of bytes transferred, or 0 (setting errno) for
3638 error. Only transfer a single packet. */
3641 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3645 unsigned char *plen
;
3651 unsigned char *payload_start
;
3653 /* Verify that the target can support a binary download. */
3654 check_binary_download (memaddr
);
3656 payload_size
= get_memory_write_packet_size ();
3658 /* Compute the size, and then allocate space for the largest
3659 possible packet. Include space for an extra trailing NUL. */
3660 sizeof_buf
= payload_size
+ 1;
3661 buf
= alloca (sizeof_buf
);
3663 /* Compute the size of the actual payload by subtracting out the
3664 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
3666 payload_size
-= strlen ("$M,:#NN");
3667 payload_size
-= hexnumlen (memaddr
);
3669 /* Construct the packet header: "[MX]<memaddr>,<len>:". */
3671 /* Append "[XM]". Compute a best guess of the number of bytes
3672 actually transfered. */
3674 switch (remote_protocol_binary_download
.support
)
3678 /* Best guess at number of bytes that will fit. */
3679 todo
= min (len
, payload_size
);
3680 payload_size
-= hexnumlen (todo
);
3681 todo
= min (todo
, payload_size
);
3683 case PACKET_DISABLE
:
3685 /* Num bytes that will fit. */
3686 todo
= min (len
, payload_size
/ 2);
3687 payload_size
-= hexnumlen (todo
);
3688 todo
= min (todo
, 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 internal_error (__FILE__
, __LINE__
,
3698 _("minumum packet size too small to write data"));
3700 /* Append "<memaddr>". */
3701 memaddr
= remote_address_masked (memaddr
);
3702 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3707 /* Append <len>. Retain the location/size of <len>. It may need to
3708 be adjusted once the packet body has been created. */
3710 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3717 /* Append the packet body. */
3719 switch (remote_protocol_binary_download
.support
)
3722 /* Binary mode. Send target system values byte by byte, in
3723 increasing byte addresses. Only escape certain critical
3726 (nr_bytes
< todo
) && (p
- payload_start
) < payload_size
;
3729 switch (myaddr
[nr_bytes
] & 0xff)
3734 /* These must be escaped. */
3736 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3739 *p
++ = myaddr
[nr_bytes
] & 0xff;
3743 if (nr_bytes
< todo
)
3745 /* Escape chars have filled up the buffer prematurely,
3746 and we have actually sent fewer bytes than planned.
3747 Fix-up the length field of the packet. Use the same
3748 number of characters as before. */
3749 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3750 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3753 case PACKET_DISABLE
:
3754 /* Normal mode: Send target system values byte by byte, in
3755 increasing byte addresses. Each byte is encoded as a two hex
3757 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3760 case PACKET_SUPPORT_UNKNOWN
:
3761 internal_error (__FILE__
, __LINE__
,
3762 _("remote_write_bytes: bad internal state"));
3764 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3767 putpkt_binary (buf
, (int) (p
- buf
));
3768 getpkt (buf
, sizeof_buf
, 0);
3772 /* There is no correspondance between what the remote protocol
3773 uses for errors and errno codes. We would like a cleaner way
3774 of representing errors (big enough to include errno codes,
3775 bfd_error codes, and others). But for now just return EIO. */
3780 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
3781 fewer bytes than we'd planned. */
3785 /* Read memory data directly from the remote machine.
3786 This does not use the data cache; the data cache uses this.
3787 MEMADDR is the address in the remote memory space.
3788 MYADDR is the address of the buffer in our space.
3789 LEN is the number of bytes.
3791 Returns number of bytes transferred, or 0 for error. */
3793 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3794 remote targets) shouldn't attempt to read the entire buffer.
3795 Instead it should read a single packet worth of data and then
3796 return the byte size of that packet to the caller. The caller (its
3797 caller and its callers caller ;-) already contains code for
3798 handling partial reads. */
3801 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3804 int max_buf_size
; /* Max size of packet output buffer. */
3808 /* Create a buffer big enough for this packet. */
3809 max_buf_size
= get_memory_read_packet_size ();
3810 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NULL. */
3811 buf
= alloca (sizeof_buf
);
3820 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3822 /* construct "m"<memaddr>","<len>" */
3823 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3824 memaddr
= remote_address_masked (memaddr
);
3827 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3829 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3833 getpkt (buf
, sizeof_buf
, 0);
3836 && isxdigit (buf
[1]) && isxdigit (buf
[2])
3839 /* There is no correspondance between what the remote
3840 protocol uses for errors and errno codes. We would like
3841 a cleaner way of representing errors (big enough to
3842 include errno codes, bfd_error codes, and others). But
3843 for now just return EIO. */
3848 /* Reply describes memory byte by byte,
3849 each byte encoded as two hex characters. */
3852 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3854 /* Reply is short. This means that we were able to read
3855 only part of what we wanted to. */
3856 return i
+ (origlen
- len
);
3865 /* Read or write LEN bytes from inferior memory at MEMADDR,
3866 transferring to or from debugger address BUFFER. Write to inferior
3867 if SHOULD_WRITE is nonzero. Returns length of data written or
3868 read; 0 for error. TARGET is unused. */
3871 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
3872 int should_write
, struct mem_attrib
*attrib
,
3873 struct target_ops
*target
)
3875 CORE_ADDR targ_addr
;
3879 /* Should this be the selected frame? */
3880 gdbarch_remote_translate_xfer_address (current_gdbarch
,
3883 &targ_addr
, &targ_len
);
3888 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3890 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3896 remote_files_info (struct target_ops
*ignore
)
3898 puts_filtered ("Debugging a target over a serial line.\n");
3901 /* Stuff for dealing with the packets which are part of this protocol.
3902 See comment at top of file for details. */
3904 /* Read a single character from the remote end, masking it down to 7
3908 readchar (int timeout
)
3912 ch
= serial_readchar (remote_desc
, timeout
);
3917 switch ((enum serial_rc
) ch
)
3920 target_mourn_inferior ();
3921 error (_("Remote connection closed"));
3924 perror_with_name (_("Remote communication error"));
3926 case SERIAL_TIMEOUT
:
3932 /* Send the command in BUF to the remote machine, and read the reply
3933 into BUF. Report an error if we get an error reply. */
3936 remote_send (char *buf
,
3940 getpkt (buf
, sizeof_buf
, 0);
3943 error (_("Remote failure reply: %s"), buf
);
3946 /* Display a null-terminated packet on stdout, for debugging, using C
3950 print_packet (char *buf
)
3952 puts_filtered ("\"");
3953 fputstr_filtered (buf
, '"', gdb_stdout
);
3954 puts_filtered ("\"");
3960 return putpkt_binary (buf
, strlen (buf
));
3963 /* Send a packet to the remote machine, with error checking. The data
3964 of the packet is in BUF. The string in BUF can be at most
3965 (rs->remote_packet_size) - 5 to account for the $, # and checksum,
3966 and for a possible /0 if we are debugging (remote_debug) and want
3967 to print the sent packet as a string. */
3970 putpkt_binary (char *buf
, int cnt
)
3972 struct remote_state
*rs
= get_remote_state ();
3974 unsigned char csum
= 0;
3975 char *buf2
= alloca (cnt
+ 6);
3976 long sizeof_junkbuf
= (rs
->remote_packet_size
);
3977 char *junkbuf
= alloca (sizeof_junkbuf
);
3983 /* Copy the packet into buffer BUF2, encapsulating it
3984 and giving it a checksum. */
3989 for (i
= 0; i
< cnt
; i
++)
3995 *p
++ = tohex ((csum
>> 4) & 0xf);
3996 *p
++ = tohex (csum
& 0xf);
3998 /* Send it over and over until we get a positive ack. */
4002 int started_error_output
= 0;
4007 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4008 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4009 fprintf_unfiltered (gdb_stdlog
, "...");
4010 gdb_flush (gdb_stdlog
);
4012 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4013 perror_with_name (_("putpkt: write failed"));
4015 /* Read until either a timeout occurs (-2) or '+' is read. */
4018 ch
= readchar (remote_timeout
);
4026 case SERIAL_TIMEOUT
:
4028 if (started_error_output
)
4030 putchar_unfiltered ('\n');
4031 started_error_output
= 0;
4040 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4044 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4045 case SERIAL_TIMEOUT
:
4049 break; /* Retransmit buffer. */
4053 fprintf_unfiltered (gdb_stdlog
,
4054 "Packet instead of Ack, ignoring it\n");
4055 /* It's probably an old response sent because an ACK
4056 was lost. Gobble up the packet and ack it so it
4057 doesn't get retransmitted when we resend this
4059 read_frame (junkbuf
, sizeof_junkbuf
);
4060 serial_write (remote_desc
, "+", 1);
4061 continue; /* Now, go look for +. */
4066 if (!started_error_output
)
4068 started_error_output
= 1;
4069 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4071 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4075 break; /* Here to retransmit. */
4079 /* This is wrong. If doing a long backtrace, the user should be
4080 able to get out next time we call QUIT, without anything as
4081 violent as interrupt_query. If we want to provide a way out of
4082 here without getting to the next QUIT, it should be based on
4083 hitting ^C twice as in remote_wait. */
4093 /* Come here after finding the start of the frame. Collect the rest
4094 into BUF, verifying the checksum, length, and handling run-length
4095 compression. No more than sizeof_buf-1 characters are read so that
4096 the buffer can be NUL terminated.
4098 Returns -1 on error, number of characters in buffer (ignoring the
4099 trailing NULL) on success. (could be extended to return one of the
4100 SERIAL status indications). */
4103 read_frame (char *buf
,
4115 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NULL. */
4116 c
= readchar (remote_timeout
);
4119 case SERIAL_TIMEOUT
:
4121 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4125 fputs_filtered ("Saw new packet start in middle of old one\n",
4127 return -1; /* Start a new packet, count retries. */
4130 unsigned char pktcsum
;
4136 check_0
= readchar (remote_timeout
);
4138 check_1
= readchar (remote_timeout
);
4140 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4143 fputs_filtered ("Timeout in checksum, retrying\n",
4147 else if (check_0
< 0 || check_1
< 0)
4150 fputs_filtered ("Communication error in checksum\n",
4155 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4156 if (csum
== pktcsum
)
4161 fprintf_filtered (gdb_stdlog
,
4162 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4164 fputs_filtered (buf
, gdb_stdlog
);
4165 fputs_filtered ("\n", gdb_stdlog
);
4167 /* Number of characters in buffer ignoring trailing
4171 case '*': /* Run length encoding. */
4176 c
= readchar (remote_timeout
);
4178 repeat
= c
- ' ' + 3; /* Compute repeat count. */
4180 /* The character before ``*'' is repeated. */
4182 if (repeat
> 0 && repeat
<= 255
4184 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4186 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4192 printf_filtered (_("Repeat count %d too large for buffer: "),
4194 puts_filtered (buf
);
4195 puts_filtered ("\n");
4199 if (bc
< sizeof_buf
- 1)
4207 puts_filtered ("Remote packet too long: ");
4208 puts_filtered (buf
);
4209 puts_filtered ("\n");
4216 /* Read a packet from the remote machine, with error checking, and
4217 store it in BUF. If FOREVER, wait forever rather than timing out;
4218 this is used (in synchronous mode) to wait for a target that is is
4219 executing user code to stop. */
4220 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4221 don't have to change all the calls to getpkt to deal with the
4222 return value, because at the moment I don't know what the right
4223 thing to do it for those. */
4231 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4235 /* Read a packet from the remote machine, with error checking, and
4236 store it in BUF. If FOREVER, wait forever rather than timing out;
4237 this is used (in synchronous mode) to wait for a target that is is
4238 executing user code to stop. If FOREVER == 0, this function is
4239 allowed to time out gracefully and return an indication of this to
4242 getpkt_sane (char *buf
,
4251 strcpy (buf
, "timeout");
4255 timeout
= watchdog
> 0 ? watchdog
: -1;
4259 timeout
= remote_timeout
;
4263 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4265 /* This can loop forever if the remote side sends us characters
4266 continuously, but if it pauses, we'll get a zero from
4267 readchar because of timeout. Then we'll count that as a
4270 /* Note that we will only wait forever prior to the start of a
4271 packet. After that, we expect characters to arrive at a
4272 brisk pace. They should show up within remote_timeout
4277 c
= readchar (timeout
);
4279 if (c
== SERIAL_TIMEOUT
)
4281 if (forever
) /* Watchdog went off? Kill the target. */
4284 target_mourn_inferior ();
4285 error (_("Watchdog has expired. Target detached."));
4288 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4294 /* We've found the start of a packet, now collect the data. */
4296 val
= read_frame (buf
, sizeof_buf
);
4302 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4303 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4304 fprintf_unfiltered (gdb_stdlog
, "\n");
4306 serial_write (remote_desc
, "+", 1);
4310 /* Try the whole thing again. */
4312 serial_write (remote_desc
, "-", 1);
4315 /* We have tried hard enough, and just can't receive the packet.
4318 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
4319 serial_write (remote_desc
, "+", 1);
4326 /* For some mysterious reason, wait_for_inferior calls kill instead of
4327 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4331 target_mourn_inferior ();
4335 /* Use catch_errors so the user can quit from gdb even when we aren't on
4336 speaking terms with the remote system. */
4337 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4339 /* Don't wait for it to die. I'm not really sure it matters whether
4340 we do or not. For the existing stubs, kill is a noop. */
4341 target_mourn_inferior ();
4344 /* Async version of remote_kill. */
4346 remote_async_kill (void)
4348 /* Unregister the file descriptor from the event loop. */
4349 if (target_is_async_p ())
4350 serial_async (remote_desc
, NULL
, 0);
4352 /* For some mysterious reason, wait_for_inferior calls kill instead of
4353 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4357 target_mourn_inferior ();
4361 /* Use catch_errors so the user can quit from gdb even when we
4362 aren't on speaking terms with the remote system. */
4363 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4365 /* Don't wait for it to die. I'm not really sure it matters whether
4366 we do or not. For the existing stubs, kill is a noop. */
4367 target_mourn_inferior ();
4373 remote_mourn_1 (&remote_ops
);
4377 remote_async_mourn (void)
4379 remote_mourn_1 (&remote_async_ops
);
4383 extended_remote_mourn (void)
4385 /* We do _not_ want to mourn the target like this; this will
4386 remove the extended remote target from the target stack,
4387 and the next time the user says "run" it'll fail.
4389 FIXME: What is the right thing to do here? */
4391 remote_mourn_1 (&extended_remote_ops
);
4395 /* Worker function for remote_mourn. */
4397 remote_mourn_1 (struct target_ops
*target
)
4399 unpush_target (target
);
4400 generic_mourn_inferior ();
4403 /* In the extended protocol we want to be able to do things like
4404 "run" and have them basically work as expected. So we need
4405 a special create_inferior function.
4407 FIXME: One day add support for changing the exec file
4408 we're debugging, arguments and an environment. */
4411 extended_remote_create_inferior (char *exec_file
, char *args
,
4412 char **env
, int from_tty
)
4414 /* Rip out the breakpoints; we'll reinsert them after restarting
4415 the remote server. */
4416 remove_breakpoints ();
4418 /* Now restart the remote server. */
4419 extended_remote_restart ();
4421 /* Now put the breakpoints back in. This way we're safe if the
4422 restart function works via a unix fork on the remote side. */
4423 insert_breakpoints ();
4425 /* Clean up from the last time we were running. */
4426 clear_proceed_status ();
4428 /* Let the remote process run. */
4429 proceed (-1, TARGET_SIGNAL_0
, 0);
4432 /* Async version of extended_remote_create_inferior. */
4434 extended_remote_async_create_inferior (char *exec_file
, char *args
,
4435 char **env
, int from_tty
)
4437 /* Rip out the breakpoints; we'll reinsert them after restarting
4438 the remote server. */
4439 remove_breakpoints ();
4441 /* If running asynchronously, register the target file descriptor
4442 with the event loop. */
4443 if (target_can_async_p ())
4444 target_async (inferior_event_handler
, 0);
4446 /* Now restart the remote server. */
4447 extended_remote_restart ();
4449 /* Now put the breakpoints back in. This way we're safe if the
4450 restart function works via a unix fork on the remote side. */
4451 insert_breakpoints ();
4453 /* Clean up from the last time we were running. */
4454 clear_proceed_status ();
4456 /* Let the remote process run. */
4457 proceed (-1, TARGET_SIGNAL_0
, 0);
4461 /* On some machines, e.g. 68k, we may use a different breakpoint
4462 instruction than other targets; in those use
4463 DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
4464 Also, bi-endian targets may define
4465 DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
4466 DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we
4467 just call the standard routines that are in mem-break.c. */
4469 /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator
4470 target should use an identical BREAKPOINT_FROM_PC. As for native,
4471 the ARCH-OS-tdep.c code can override the default. */
4473 #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
4474 #define DEPRECATED_REMOTE_BREAKPOINT
4477 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4479 /* If the target isn't bi-endian, just pretend it is. */
4480 #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
4481 #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4482 #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4485 static unsigned char big_break_insn
[] = DEPRECATED_BIG_REMOTE_BREAKPOINT
;
4486 static unsigned char little_break_insn
[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT
;
4488 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4490 /* Insert a breakpoint on targets that don't have any better
4491 breakpoint support. We read the contents of the target location
4492 and stash it, then overwrite it with a breakpoint instruction.
4493 ADDR is the target location in the target machine. CONTENTS_CACHE
4494 is a pointer to memory allocated for saving the target contents.
4495 It is guaranteed by the caller to be long enough to save the number
4496 of bytes returned by BREAKPOINT_FROM_PC. */
4499 remote_insert_breakpoint (CORE_ADDR addr
, bfd_byte
*contents_cache
)
4501 struct remote_state
*rs
= get_remote_state ();
4502 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4507 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4508 If it succeeds, then set the support to PACKET_ENABLE. If it
4509 fails, and the user has explicitly requested the Z support then
4510 report an error, otherwise, mark it disabled and go on. */
4512 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4514 char *buf
= alloca (rs
->remote_packet_size
);
4517 addr
= remote_address_masked (addr
);
4521 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4522 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4523 sprintf (p
, ",%d", bp_size
);
4526 getpkt (buf
, (rs
->remote_packet_size
), 0);
4528 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4534 case PACKET_UNKNOWN
:
4539 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4540 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4544 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4545 val
= target_write_memory (addr
, (char *) big_break_insn
,
4546 sizeof big_break_insn
);
4548 val
= target_write_memory (addr
, (char *) little_break_insn
,
4549 sizeof little_break_insn
);
4554 return memory_insert_breakpoint (addr
, contents_cache
);
4555 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4559 remote_remove_breakpoint (CORE_ADDR addr
, bfd_byte
*contents_cache
)
4561 struct remote_state
*rs
= get_remote_state ();
4564 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4566 char *buf
= alloca (rs
->remote_packet_size
);
4573 addr
= remote_address_masked (addr
);
4574 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4575 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4576 sprintf (p
, ",%d", bp_size
);
4579 getpkt (buf
, (rs
->remote_packet_size
), 0);
4581 return (buf
[0] == 'E');
4584 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4585 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4587 return memory_remove_breakpoint (addr
, contents_cache
);
4588 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4592 watchpoint_to_Z_packet (int type
)
4606 internal_error (__FILE__
, __LINE__
,
4607 _("hw_bp_to_z: bad watchpoint type %d"), type
);
4612 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4614 struct remote_state
*rs
= get_remote_state ();
4615 char *buf
= alloca (rs
->remote_packet_size
);
4617 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4619 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4620 error (_("Can't set hardware watchpoints without the '%s' (%s) packet."),
4621 remote_protocol_Z
[packet
].name
,
4622 remote_protocol_Z
[packet
].title
);
4624 sprintf (buf
, "Z%x,", packet
);
4625 p
= strchr (buf
, '\0');
4626 addr
= remote_address_masked (addr
);
4627 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4628 sprintf (p
, ",%x", len
);
4631 getpkt (buf
, (rs
->remote_packet_size
), 0);
4633 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4636 case PACKET_UNKNOWN
:
4641 internal_error (__FILE__
, __LINE__
,
4642 _("remote_insert_watchpoint: reached end of function"));
4647 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4649 struct remote_state
*rs
= get_remote_state ();
4650 char *buf
= alloca (rs
->remote_packet_size
);
4652 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4654 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4655 error (_("Can't clear hardware watchpoints without the '%s' (%s) packet."),
4656 remote_protocol_Z
[packet
].name
,
4657 remote_protocol_Z
[packet
].title
);
4659 sprintf (buf
, "z%x,", packet
);
4660 p
= strchr (buf
, '\0');
4661 addr
= remote_address_masked (addr
);
4662 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4663 sprintf (p
, ",%x", len
);
4665 getpkt (buf
, (rs
->remote_packet_size
), 0);
4667 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4670 case PACKET_UNKNOWN
:
4675 internal_error (__FILE__
, __LINE__
,
4676 _("remote_remove_watchpoint: reached end of function"));
4680 int remote_hw_watchpoint_limit
= -1;
4681 int remote_hw_breakpoint_limit
= -1;
4684 remote_check_watch_resources (int type
, int cnt
, int ot
)
4686 if (type
== bp_hardware_breakpoint
)
4688 if (remote_hw_breakpoint_limit
== 0)
4690 else if (remote_hw_breakpoint_limit
< 0)
4692 else if (cnt
<= remote_hw_breakpoint_limit
)
4697 if (remote_hw_watchpoint_limit
== 0)
4699 else if (remote_hw_watchpoint_limit
< 0)
4703 else if (cnt
<= remote_hw_watchpoint_limit
)
4710 remote_stopped_by_watchpoint (void)
4712 return remote_stopped_by_watchpoint_p
;
4715 extern int stepped_after_stopped_by_watchpoint
;
4718 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
4721 if (remote_stopped_by_watchpoint ()
4722 || stepped_after_stopped_by_watchpoint
)
4724 *addr_p
= remote_watch_data_address
;
4733 remote_insert_hw_breakpoint (CORE_ADDR addr
, gdb_byte
*shadow
)
4736 struct remote_state
*rs
= get_remote_state ();
4737 char *buf
= alloca (rs
->remote_packet_size
);
4740 /* The length field should be set to the size of a breakpoint
4743 BREAKPOINT_FROM_PC (&addr
, &len
);
4745 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4746 error (_("Can't set hardware breakpoint without the '%s' (%s) packet."),
4747 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4748 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4754 addr
= remote_address_masked (addr
);
4755 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4756 sprintf (p
, ",%x", len
);
4759 getpkt (buf
, (rs
->remote_packet_size
), 0);
4761 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4764 case PACKET_UNKNOWN
:
4769 internal_error (__FILE__
, __LINE__
,
4770 _("remote_insert_hw_breakpoint: reached end of function"));
4775 remote_remove_hw_breakpoint (CORE_ADDR addr
, gdb_byte
*shadow
)
4778 struct remote_state
*rs
= get_remote_state ();
4779 char *buf
= alloca (rs
->remote_packet_size
);
4782 /* The length field should be set to the size of a breakpoint
4785 BREAKPOINT_FROM_PC (&addr
, &len
);
4787 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4788 error (_("Can't clear hardware breakpoint without the '%s' (%s) packet."),
4789 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4790 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4796 addr
= remote_address_masked (addr
);
4797 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4798 sprintf (p
, ",%x", len
);
4801 getpkt (buf
, (rs
->remote_packet_size
), 0);
4803 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4806 case PACKET_UNKNOWN
:
4811 internal_error (__FILE__
, __LINE__
,
4812 _("remote_remove_hw_breakpoint: reached end of function"));
4815 /* Some targets are only capable of doing downloads, and afterwards
4816 they switch to the remote serial protocol. This function provides
4817 a clean way to get from the download target to the remote target.
4818 It's basically just a wrapper so that we don't have to expose any
4819 of the internal workings of remote.c.
4821 Prior to calling this routine, you should shutdown the current
4822 target code, else you will get the "A program is being debugged
4823 already..." message. Usually a call to pop_target() suffices. */
4826 push_remote_target (char *name
, int from_tty
)
4828 printf_filtered (_("Switching to remote protocol\n"));
4829 remote_open (name
, from_tty
);
4832 /* Table used by the crc32 function to calcuate the checksum. */
4834 static unsigned long crc32_table
[256] =
4837 static unsigned long
4838 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4840 if (!crc32_table
[1])
4842 /* Initialize the CRC table and the decoding table. */
4846 for (i
= 0; i
< 256; i
++)
4848 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4849 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4856 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4862 /* compare-sections command
4864 With no arguments, compares each loadable section in the exec bfd
4865 with the same memory range on the target, and reports mismatches.
4866 Useful for verifying the image on the target against the exec file.
4867 Depends on the target understanding the new "qCRC:" request. */
4869 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4870 target method (target verify memory) and generic version of the
4871 actual command. This will allow other high-level code (especially
4872 generic_load()) to make use of this target functionality. */
4875 compare_sections_command (char *args
, int from_tty
)
4877 struct remote_state
*rs
= get_remote_state ();
4879 unsigned long host_crc
, target_crc
;
4880 extern bfd
*exec_bfd
;
4881 struct cleanup
*old_chain
;
4884 const char *sectname
;
4885 char *buf
= alloca (rs
->remote_packet_size
);
4892 error (_("command cannot be used without an exec file"));
4893 if (!current_target
.to_shortname
||
4894 strcmp (current_target
.to_shortname
, "remote") != 0)
4895 error (_("command can only be used with remote target"));
4897 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4899 if (!(s
->flags
& SEC_LOAD
))
4900 continue; /* skip non-loadable section */
4902 size
= bfd_get_section_size (s
);
4904 continue; /* skip zero-length section */
4906 sectname
= bfd_get_section_name (exec_bfd
, s
);
4907 if (args
&& strcmp (args
, sectname
) != 0)
4908 continue; /* not the section selected by user */
4910 matched
= 1; /* do this section */
4912 /* FIXME: assumes lma can fit into long. */
4913 xsnprintf (buf
, rs
->remote_packet_size
, "qCRC:%lx,%lx",
4914 (long) lma
, (long) size
);
4917 /* Be clever; compute the host_crc before waiting for target
4919 sectdata
= xmalloc (size
);
4920 old_chain
= make_cleanup (xfree
, sectdata
);
4921 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4922 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4924 getpkt (buf
, (rs
->remote_packet_size
), 0);
4926 error (_("target memory fault, section %s, range 0x%s -- 0x%s"),
4927 sectname
, paddr (lma
), paddr (lma
+ size
));
4929 error (_("remote target does not support this operation"));
4931 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4932 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4934 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4935 sectname
, paddr (lma
), paddr (lma
+ size
));
4936 if (host_crc
== target_crc
)
4937 printf_filtered ("matched.\n");
4940 printf_filtered ("MIS-MATCHED!\n");
4944 do_cleanups (old_chain
);
4947 warning (_("One or more sections of the remote executable does not match\n\
4948 the loaded file\n"));
4949 if (args
&& !matched
)
4950 printf_filtered (_("No loaded section named '%s'.\n"), args
);
4954 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
4955 const char *annex
, gdb_byte
*readbuf
,
4956 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
4958 struct remote_state
*rs
= get_remote_state ();
4960 char *buf2
= alloca (rs
->remote_packet_size
);
4961 char *p2
= &buf2
[0];
4964 /* Handle memory using remote_xfer_memory. */
4965 if (object
== TARGET_OBJECT_MEMORY
)
4970 if (writebuf
!= NULL
)
4972 void *buffer
= xmalloc (len
);
4973 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
4974 memcpy (buffer
, writebuf
, len
);
4975 xfered
= remote_xfer_memory (offset
, buffer
, len
, 1, NULL
, ops
);
4976 do_cleanups (cleanup
);
4979 xfered
= remote_xfer_memory (offset
, readbuf
, len
, 0, NULL
, ops
);
4983 else if (xfered
== 0 && errno
== 0)
4989 /* Only handle reads. */
4990 if (writebuf
!= NULL
|| readbuf
== NULL
)
4993 /* Map pre-existing objects onto letters. DO NOT do this for new
4994 objects!!! Instead specify new query packets. */
4997 case TARGET_OBJECT_KOD
:
5000 case TARGET_OBJECT_AVR
:
5004 case TARGET_OBJECT_AUXV
:
5005 if (remote_protocol_qPart_auxv
.support
!= PACKET_DISABLE
)
5007 unsigned int total
= 0;
5010 LONGEST n
= min ((rs
->remote_packet_size
- 2) / 2, len
);
5011 snprintf (buf2
, rs
->remote_packet_size
,
5012 "qPart:auxv:read::%s,%s",
5013 phex_nz (offset
, sizeof offset
),
5014 phex_nz (n
, sizeof n
));
5017 return total
> 0 ? total
: i
;
5019 getpkt (buf2
, rs
->remote_packet_size
, 0);
5020 if (packet_ok (buf2
, &remote_protocol_qPart_auxv
) != PACKET_OK
)
5021 return total
> 0 ? total
: -1;
5022 if (buf2
[0] == 'O' && buf2
[1] == 'K' && buf2
[2] == '\0')
5023 break; /* Got EOF indicator. */
5024 /* Got some data. */
5025 i
= hex2bin (buf2
, readbuf
, len
);
5028 readbuf
= (void *) ((char *) readbuf
+ i
);
5042 /* Note: a zero OFFSET and LEN can be used to query the minimum
5044 if (offset
== 0 && len
== 0)
5045 return (rs
->remote_packet_size
);
5046 /* Minimum outbuf size is (rs->remote_packet_size) - if bufsiz is
5047 not large enough let the caller. */
5048 if (len
< (rs
->remote_packet_size
))
5050 len
= rs
->remote_packet_size
;
5052 /* Except for querying the minimum buffer size, target must be open. */
5054 error (_("remote query is only available after target open"));
5056 gdb_assert (annex
!= NULL
);
5057 gdb_assert (readbuf
!= NULL
);
5062 /* We used one buffer char for the remote protocol q command and
5063 another for the query type. As the remote protocol encapsulation
5064 uses 4 chars plus one extra in case we are debugging
5065 (remote_debug), we have PBUFZIZ - 7 left to pack the query
5068 while (annex
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5070 /* Bad caller may have sent forbidden characters. */
5071 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
5076 gdb_assert (annex
[i
] == '\0');
5082 getpkt (readbuf
, len
, 0);
5084 return strlen (readbuf
);
5088 remote_rcmd (char *command
,
5089 struct ui_file
*outbuf
)
5091 struct remote_state
*rs
= get_remote_state ();
5092 char *buf
= alloca (rs
->remote_packet_size
);
5096 error (_("remote rcmd is only available after target open"));
5098 /* Send a NULL command across as an empty command. */
5099 if (command
== NULL
)
5102 /* The query prefix. */
5103 strcpy (buf
, "qRcmd,");
5104 p
= strchr (buf
, '\0');
5106 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5107 error (_("\"monitor\" command ``%s'' is too long."), command
);
5109 /* Encode the actual command. */
5110 bin2hex (command
, p
, 0);
5112 if (putpkt (buf
) < 0)
5113 error (_("Communication problem with target."));
5115 /* get/display the response */
5118 /* XXX - see also tracepoint.c:remote_get_noisy_reply(). */
5120 getpkt (buf
, (rs
->remote_packet_size
), 0);
5122 error (_("Target does not support this command."));
5123 if (buf
[0] == 'O' && buf
[1] != 'K')
5125 remote_console_output (buf
+ 1); /* 'O' message from stub. */
5128 if (strcmp (buf
, "OK") == 0)
5130 if (strlen (buf
) == 3 && buf
[0] == 'E'
5131 && isdigit (buf
[1]) && isdigit (buf
[2]))
5133 error (_("Protocol error with Rcmd"));
5135 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5137 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5138 fputc_unfiltered (c
, outbuf
);
5145 packet_command (char *args
, int from_tty
)
5147 struct remote_state
*rs
= get_remote_state ();
5148 char *buf
= alloca (rs
->remote_packet_size
);
5151 error (_("command can only be used with remote target"));
5154 error (_("remote-packet command requires packet text as argument"));
5156 puts_filtered ("sending: ");
5157 print_packet (args
);
5158 puts_filtered ("\n");
5161 getpkt (buf
, (rs
->remote_packet_size
), 0);
5162 puts_filtered ("received: ");
5164 puts_filtered ("\n");
5168 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
5170 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5172 static void threadset_test_cmd (char *cmd
, int tty
);
5174 static void threadalive_test (char *cmd
, int tty
);
5176 static void threadlist_test_cmd (char *cmd
, int tty
);
5178 int get_and_display_threadinfo (threadref
*ref
);
5180 static void threadinfo_test_cmd (char *cmd
, int tty
);
5182 static int thread_display_step (threadref
*ref
, void *context
);
5184 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5186 static void init_remote_threadtests (void);
5188 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
5191 threadset_test_cmd (char *cmd
, int tty
)
5193 int sample_thread
= SAMPLE_THREAD
;
5195 printf_filtered (_("Remote threadset test\n"));
5196 set_thread (sample_thread
, 1);
5201 threadalive_test (char *cmd
, int tty
)
5203 int sample_thread
= SAMPLE_THREAD
;
5205 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5206 printf_filtered ("PASS: Thread alive test\n");
5208 printf_filtered ("FAIL: Thread alive test\n");
5211 void output_threadid (char *title
, threadref
*ref
);
5214 output_threadid (char *title
, threadref
*ref
)
5218 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
5220 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5224 threadlist_test_cmd (char *cmd
, int tty
)
5227 threadref nextthread
;
5228 int done
, result_count
;
5229 threadref threadlist
[3];
5231 printf_filtered ("Remote Threadlist test\n");
5232 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5233 &result_count
, &threadlist
[0]))
5234 printf_filtered ("FAIL: threadlist test\n");
5237 threadref
*scan
= threadlist
;
5238 threadref
*limit
= scan
+ result_count
;
5240 while (scan
< limit
)
5241 output_threadid (" thread ", scan
++);
5246 display_thread_info (struct gdb_ext_thread_info
*info
)
5248 output_threadid ("Threadid: ", &info
->threadid
);
5249 printf_filtered ("Name: %s\n ", info
->shortname
);
5250 printf_filtered ("State: %s\n", info
->display
);
5251 printf_filtered ("other: %s\n\n", info
->more_display
);
5255 get_and_display_threadinfo (threadref
*ref
)
5259 struct gdb_ext_thread_info threadinfo
;
5261 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5262 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5263 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5264 display_thread_info (&threadinfo
);
5269 threadinfo_test_cmd (char *cmd
, int tty
)
5271 int athread
= SAMPLE_THREAD
;
5275 int_to_threadref (&thread
, athread
);
5276 printf_filtered ("Remote Threadinfo test\n");
5277 if (!get_and_display_threadinfo (&thread
))
5278 printf_filtered ("FAIL cannot get thread info\n");
5282 thread_display_step (threadref
*ref
, void *context
)
5284 /* output_threadid(" threadstep ",ref); *//* simple test */
5285 return get_and_display_threadinfo (ref
);
5289 threadlist_update_test_cmd (char *cmd
, int tty
)
5291 printf_filtered ("Remote Threadlist update test\n");
5292 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5296 init_remote_threadtests (void)
5298 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
5299 Fetch and print the remote list of thread identifiers, one pkt only"));
5300 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5301 _("Fetch and display info about one thread"));
5302 add_com ("tset", class_obscure
, threadset_test_cmd
,
5303 _("Test setting to a different thread"));
5304 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5305 _("Iterate through updating all remote thread info"));
5306 add_com ("talive", class_obscure
, threadalive_test
,
5307 _(" Remote thread alive test "));
5312 /* Convert a thread ID to a string. Returns the string in a static
5316 remote_pid_to_str (ptid_t ptid
)
5318 static char buf
[32];
5321 size
= snprintf (buf
, sizeof buf
, "thread %d", ptid_get_pid (ptid
));
5322 gdb_assert (size
< sizeof buf
);
5326 /* Get the address of the thread local variable in OBJFILE which is
5327 stored at OFFSET within the thread local storage for thread PTID. */
5330 remote_get_thread_local_address (ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
5332 if (remote_protocol_qGetTLSAddr
.support
!= PACKET_DISABLE
)
5334 struct remote_state
*rs
= get_remote_state ();
5335 char *buf
= alloca (rs
->remote_packet_size
);
5337 enum packet_result result
;
5339 strcpy (p
, "qGetTLSAddr:");
5341 p
+= hexnumstr (p
, PIDGET (ptid
));
5343 p
+= hexnumstr (p
, offset
);
5345 p
+= hexnumstr (p
, lm
);
5349 getpkt (buf
, rs
->remote_packet_size
, 0);
5350 result
= packet_ok (buf
, &remote_protocol_qGetTLSAddr
);
5351 if (result
== PACKET_OK
)
5355 unpack_varlen_hex (buf
, &result
);
5358 else if (result
== PACKET_UNKNOWN
)
5359 throw_error (TLS_GENERIC_ERROR
,
5360 _("Remote target doesn't support qGetTLSAddr packet"));
5362 throw_error (TLS_GENERIC_ERROR
,
5363 _("Remote target failed to process qGetTLSAddr request"));
5366 throw_error (TLS_GENERIC_ERROR
,
5367 _("TLS not supported or disabled on this target"));
5373 init_remote_ops (void)
5375 remote_ops
.to_shortname
= "remote";
5376 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5378 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5379 Specify the serial device it is connected to\n\
5380 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5381 remote_ops
.to_open
= remote_open
;
5382 remote_ops
.to_close
= remote_close
;
5383 remote_ops
.to_detach
= remote_detach
;
5384 remote_ops
.to_disconnect
= remote_disconnect
;
5385 remote_ops
.to_resume
= remote_resume
;
5386 remote_ops
.to_wait
= remote_wait
;
5387 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5388 remote_ops
.to_store_registers
= remote_store_registers
;
5389 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5390 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5391 remote_ops
.to_files_info
= remote_files_info
;
5392 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5393 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5394 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5395 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5396 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5397 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5398 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5399 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5400 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5401 remote_ops
.to_kill
= remote_kill
;
5402 remote_ops
.to_load
= generic_load
;
5403 remote_ops
.to_mourn_inferior
= remote_mourn
;
5404 remote_ops
.to_thread_alive
= remote_thread_alive
;
5405 remote_ops
.to_find_new_threads
= remote_threads_info
;
5406 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5407 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5408 remote_ops
.to_stop
= remote_stop
;
5409 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
5410 remote_ops
.to_rcmd
= remote_rcmd
;
5411 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
5412 remote_ops
.to_stratum
= process_stratum
;
5413 remote_ops
.to_has_all_memory
= 1;
5414 remote_ops
.to_has_memory
= 1;
5415 remote_ops
.to_has_stack
= 1;
5416 remote_ops
.to_has_registers
= 1;
5417 remote_ops
.to_has_execution
= 1;
5418 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5419 remote_ops
.to_magic
= OPS_MAGIC
;
5422 /* Set up the extended remote vector by making a copy of the standard
5423 remote vector and adding to it. */
5426 init_extended_remote_ops (void)
5428 extended_remote_ops
= remote_ops
;
5430 extended_remote_ops
.to_shortname
= "extended-remote";
5431 extended_remote_ops
.to_longname
=
5432 "Extended remote serial target in gdb-specific protocol";
5433 extended_remote_ops
.to_doc
=
5434 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5435 Specify the serial device it is connected to (e.g. /dev/ttya).",
5436 extended_remote_ops
.to_open
= extended_remote_open
;
5437 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5438 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5442 remote_can_async_p (void)
5444 /* We're async whenever the serial device is. */
5445 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5449 remote_is_async_p (void)
5451 /* We're async whenever the serial device is. */
5452 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5455 /* Pass the SERIAL event on and up to the client. One day this code
5456 will be able to delay notifying the client of an event until the
5457 point where an entire packet has been received. */
5459 static void (*async_client_callback
) (enum inferior_event_type event_type
,
5461 static void *async_client_context
;
5462 static serial_event_ftype remote_async_serial_handler
;
5465 remote_async_serial_handler (struct serial
*scb
, void *context
)
5467 /* Don't propogate error information up to the client. Instead let
5468 the client find out about the error by querying the target. */
5469 async_client_callback (INF_REG_EVENT
, async_client_context
);
5473 remote_async (void (*callback
) (enum inferior_event_type event_type
,
5474 void *context
), void *context
)
5476 if (current_target
.to_async_mask_value
== 0)
5477 internal_error (__FILE__
, __LINE__
,
5478 _("Calling remote_async when async is masked"));
5480 if (callback
!= NULL
)
5482 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5483 async_client_callback
= callback
;
5484 async_client_context
= context
;
5487 serial_async (remote_desc
, NULL
, NULL
);
5490 /* Target async and target extended-async.
5492 This are temporary targets, until it is all tested. Eventually
5493 async support will be incorporated int the usual 'remote'
5497 init_remote_async_ops (void)
5499 remote_async_ops
.to_shortname
= "async";
5500 remote_async_ops
.to_longname
=
5501 "Remote serial target in async version of the gdb-specific protocol";
5502 remote_async_ops
.to_doc
=
5503 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5504 Specify the serial device it is connected to (e.g. /dev/ttya).";
5505 remote_async_ops
.to_open
= remote_async_open
;
5506 remote_async_ops
.to_close
= remote_close
;
5507 remote_async_ops
.to_detach
= remote_detach
;
5508 remote_async_ops
.to_disconnect
= remote_disconnect
;
5509 remote_async_ops
.to_resume
= remote_async_resume
;
5510 remote_async_ops
.to_wait
= remote_async_wait
;
5511 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5512 remote_async_ops
.to_store_registers
= remote_store_registers
;
5513 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5514 remote_async_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5515 remote_async_ops
.to_files_info
= remote_files_info
;
5516 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5517 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5518 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5519 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5520 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5521 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5522 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5523 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5524 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5525 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5526 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5527 remote_async_ops
.to_kill
= remote_async_kill
;
5528 remote_async_ops
.to_load
= generic_load
;
5529 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5530 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5531 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5532 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5533 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5534 remote_async_ops
.to_stop
= remote_stop
;
5535 remote_async_ops
.to_xfer_partial
= remote_xfer_partial
;
5536 remote_async_ops
.to_rcmd
= remote_rcmd
;
5537 remote_async_ops
.to_stratum
= process_stratum
;
5538 remote_async_ops
.to_has_all_memory
= 1;
5539 remote_async_ops
.to_has_memory
= 1;
5540 remote_async_ops
.to_has_stack
= 1;
5541 remote_async_ops
.to_has_registers
= 1;
5542 remote_async_ops
.to_has_execution
= 1;
5543 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5544 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5545 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5546 remote_async_ops
.to_async
= remote_async
;
5547 remote_async_ops
.to_async_mask_value
= 1;
5548 remote_async_ops
.to_magic
= OPS_MAGIC
;
5551 /* Set up the async extended remote vector by making a copy of the standard
5552 remote vector and adding to it. */
5555 init_extended_async_remote_ops (void)
5557 extended_async_remote_ops
= remote_async_ops
;
5559 extended_async_remote_ops
.to_shortname
= "extended-async";
5560 extended_async_remote_ops
.to_longname
=
5561 "Extended remote serial target in async gdb-specific protocol";
5562 extended_async_remote_ops
.to_doc
=
5563 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5564 Specify the serial device it is connected to (e.g. /dev/ttya).",
5565 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5566 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5567 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5571 set_remote_cmd (char *args
, int from_tty
)
5576 show_remote_cmd (char *args
, int from_tty
)
5578 /* FIXME: cagney/2002-06-15: This function should iterate over
5579 remote_show_cmdlist for a list of sub commands to show. */
5580 show_remote_protocol_Z_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5581 show_remote_protocol_P_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5582 show_remote_protocol_p_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5583 show_remote_protocol_qSymbol_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5584 show_remote_protocol_vcont_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5585 show_remote_protocol_binary_download_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5586 show_remote_protocol_qPart_auxv_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5587 show_remote_protocol_qGetTLSAddr_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5591 build_remote_gdbarch_data (void)
5593 remote_address_size
= TARGET_ADDR_BIT
;
5596 /* Saved pointer to previous owner of the new_objfile event. */
5597 static void (*remote_new_objfile_chain
) (struct objfile
*);
5599 /* Function to be called whenever a new objfile (shlib) is detected. */
5601 remote_new_objfile (struct objfile
*objfile
)
5603 if (remote_desc
!= 0) /* Have a remote connection. */
5605 remote_check_symbols (objfile
);
5607 /* Call predecessor on chain, if any. */
5608 if (remote_new_objfile_chain
!= 0 &&
5610 remote_new_objfile_chain (objfile
);
5614 _initialize_remote (void)
5616 static struct cmd_list_element
*remote_set_cmdlist
;
5617 static struct cmd_list_element
*remote_show_cmdlist
;
5619 /* architecture specific data */
5620 remote_gdbarch_data_handle
=
5621 gdbarch_data_register_post_init (init_remote_state
);
5623 /* Old tacky stuff. NOTE: This comes after the remote protocol so
5624 that the remote protocol has been initialized. */
5625 DEPRECATED_REGISTER_GDBARCH_SWAP (remote_address_size
);
5626 deprecated_register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5629 add_target (&remote_ops
);
5631 init_extended_remote_ops ();
5632 add_target (&extended_remote_ops
);
5634 init_remote_async_ops ();
5635 add_target (&remote_async_ops
);
5637 init_extended_async_remote_ops ();
5638 add_target (&extended_async_remote_ops
);
5640 /* Hook into new objfile notification. */
5641 remote_new_objfile_chain
= deprecated_target_new_objfile_hook
;
5642 deprecated_target_new_objfile_hook
= remote_new_objfile
;
5645 init_remote_threadtests ();
5648 /* set/show remote ... */
5650 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
5651 Remote protocol specific variables\n\
5652 Configure various remote-protocol specific variables such as\n\
5653 the packets being used"),
5654 &remote_set_cmdlist
, "set remote ",
5655 0 /* allow-unknown */, &setlist
);
5656 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
5657 Remote protocol specific variables\n\
5658 Configure various remote-protocol specific variables such as\n\
5659 the packets being used"),
5660 &remote_show_cmdlist
, "show remote ",
5661 0 /* allow-unknown */, &showlist
);
5663 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
5664 Compare section data on target to the exec file.\n\
5665 Argument is a single section name (default: all loaded sections)."),
5668 add_cmd ("packet", class_maintenance
, packet_command
, _("\
5669 Send an arbitrary packet to a remote target.\n\
5670 maintenance packet TEXT\n\
5671 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5672 this command sends the string TEXT to the inferior, and displays the\n\
5673 response packet. GDB supplies the initial `$' character, and the\n\
5674 terminating `#' character and checksum."),
5677 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
5678 Set whether to send break if interrupted."), _("\
5679 Show whether to send break if interrupted."), _("\
5680 If set, a break, instead of a cntrl-c, is sent to the remote target."),
5681 NULL
, NULL
, /* FIXME: i18n: Whether to send break if interrupted is %s. */
5682 &setlist
, &showlist
);
5684 /* Install commands for configuring memory read/write packets. */
5686 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
5687 Set the maximum number of bytes per memory write packet (deprecated)."),
5689 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
5690 Show the maximum number of bytes per memory write packet (deprecated)."),
5692 add_cmd ("memory-write-packet-size", no_class
,
5693 set_memory_write_packet_size
, _("\
5694 Set the maximum number of bytes per memory-write packet.\n\
5695 Specify the number of bytes in a packet or 0 (zero) for the\n\
5696 default packet size. The actual limit is further reduced\n\
5697 dependent on the target. Specify ``fixed'' to disable the\n\
5698 further restriction and ``limit'' to enable that restriction."),
5699 &remote_set_cmdlist
);
5700 add_cmd ("memory-read-packet-size", no_class
,
5701 set_memory_read_packet_size
, _("\
5702 Set the maximum number of bytes per memory-read packet.\n\
5703 Specify the number of bytes in a packet or 0 (zero) for the\n\
5704 default packet size. The actual limit is further reduced\n\
5705 dependent on the target. Specify ``fixed'' to disable the\n\
5706 further restriction and ``limit'' to enable that restriction."),
5707 &remote_set_cmdlist
);
5708 add_cmd ("memory-write-packet-size", no_class
,
5709 show_memory_write_packet_size
,
5710 _("Show the maximum number of bytes per memory-write packet."),
5711 &remote_show_cmdlist
);
5712 add_cmd ("memory-read-packet-size", no_class
,
5713 show_memory_read_packet_size
,
5714 _("Show the maximum number of bytes per memory-read packet."),
5715 &remote_show_cmdlist
);
5717 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
5718 &remote_hw_watchpoint_limit
, _("\
5719 Set the maximum number of target hardware watchpoints."), _("\
5720 Show the maximum number of target hardware watchpoints."), _("\
5721 Specify a negative limit for unlimited."),
5722 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
5723 &remote_set_cmdlist
, &remote_show_cmdlist
);
5724 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
5725 &remote_hw_breakpoint_limit
, _("\
5726 Set the maximum number of target hardware breakpoints."), _("\
5727 Show the maximum number of target hardware breakpoints."), _("\
5728 Specify a negative limit for unlimited."),
5729 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
5730 &remote_set_cmdlist
, &remote_show_cmdlist
);
5732 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
5733 &remote_address_size
, _("\
5734 Set the maximum size of the address (in bits) in a memory packet."), _("\
5735 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
5737 NULL
, /* FIXME: i18n: */
5738 &setlist
, &showlist
);
5740 add_packet_config_cmd (&remote_protocol_binary_download
,
5741 "X", "binary-download",
5742 set_remote_protocol_binary_download_cmd
,
5743 show_remote_protocol_binary_download_cmd
,
5744 &remote_set_cmdlist
, &remote_show_cmdlist
,
5747 add_packet_config_cmd (&remote_protocol_vcont
,
5748 "vCont", "verbose-resume",
5749 set_remote_protocol_vcont_packet_cmd
,
5750 show_remote_protocol_vcont_packet_cmd
,
5751 &remote_set_cmdlist
, &remote_show_cmdlist
,
5754 add_packet_config_cmd (&remote_protocol_qSymbol
,
5755 "qSymbol", "symbol-lookup",
5756 set_remote_protocol_qSymbol_packet_cmd
,
5757 show_remote_protocol_qSymbol_packet_cmd
,
5758 &remote_set_cmdlist
, &remote_show_cmdlist
,
5761 add_packet_config_cmd (&remote_protocol_P
,
5762 "P", "set-register",
5763 set_remote_protocol_P_packet_cmd
,
5764 show_remote_protocol_P_packet_cmd
,
5765 &remote_set_cmdlist
, &remote_show_cmdlist
,
5768 add_packet_config_cmd (&remote_protocol_p
,
5769 "p", "fetch-register",
5770 set_remote_protocol_p_packet_cmd
,
5771 show_remote_protocol_p_packet_cmd
,
5772 &remote_set_cmdlist
, &remote_show_cmdlist
,
5775 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
5776 "Z0", "software-breakpoint",
5777 set_remote_protocol_Z_software_bp_packet_cmd
,
5778 show_remote_protocol_Z_software_bp_packet_cmd
,
5779 &remote_set_cmdlist
, &remote_show_cmdlist
,
5782 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
5783 "Z1", "hardware-breakpoint",
5784 set_remote_protocol_Z_hardware_bp_packet_cmd
,
5785 show_remote_protocol_Z_hardware_bp_packet_cmd
,
5786 &remote_set_cmdlist
, &remote_show_cmdlist
,
5789 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
5790 "Z2", "write-watchpoint",
5791 set_remote_protocol_Z_write_wp_packet_cmd
,
5792 show_remote_protocol_Z_write_wp_packet_cmd
,
5793 &remote_set_cmdlist
, &remote_show_cmdlist
,
5796 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
5797 "Z3", "read-watchpoint",
5798 set_remote_protocol_Z_read_wp_packet_cmd
,
5799 show_remote_protocol_Z_read_wp_packet_cmd
,
5800 &remote_set_cmdlist
, &remote_show_cmdlist
,
5803 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
5804 "Z4", "access-watchpoint",
5805 set_remote_protocol_Z_access_wp_packet_cmd
,
5806 show_remote_protocol_Z_access_wp_packet_cmd
,
5807 &remote_set_cmdlist
, &remote_show_cmdlist
,
5810 add_packet_config_cmd (&remote_protocol_qPart_auxv
,
5811 "qPart_auxv", "read-aux-vector",
5812 set_remote_protocol_qPart_auxv_packet_cmd
,
5813 show_remote_protocol_qPart_auxv_packet_cmd
,
5814 &remote_set_cmdlist
, &remote_show_cmdlist
,
5817 add_packet_config_cmd (&remote_protocol_qGetTLSAddr
,
5818 "qGetTLSAddr", "get-thread-local-storage-address",
5819 set_remote_protocol_qGetTLSAddr_packet_cmd
,
5820 show_remote_protocol_qGetTLSAddr_packet_cmd
,
5821 &remote_set_cmdlist
, &remote_show_cmdlist
,
5824 /* Keep the old ``set remote Z-packet ...'' working. */
5825 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
5826 &remote_Z_packet_detect
, _("\
5827 Set use of remote protocol `Z' packets"), _("\
5828 Show use of remote protocol `Z' packets "), _("\
5829 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
5831 set_remote_protocol_Z_packet_cmd
,
5832 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
5833 &remote_set_cmdlist
, &remote_show_cmdlist
);
5835 /* Eventually initialize fileio. See fileio.c */
5836 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);