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"
48 #include "event-loop.h"
49 #include "event-top.h"
55 #include "gdbcore.h" /* for exec_bfd */
57 #include "remote-fileio.h"
59 /* Prototypes for local functions. */
60 static void cleanup_sigint_signal_handler (void *dummy
);
61 static void initialize_sigint_signal_handler (void);
62 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
64 static void handle_remote_sigint (int);
65 static void handle_remote_sigint_twice (int);
66 static void async_remote_interrupt (gdb_client_data
);
67 void async_remote_interrupt_twice (gdb_client_data
);
69 static void build_remote_gdbarch_data (void);
71 static void remote_files_info (struct target_ops
*ignore
);
73 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
74 int len
, int should_write
,
75 struct mem_attrib
*attrib
,
76 struct target_ops
*target
);
78 static void remote_prepare_to_store (void);
80 static void remote_fetch_registers (int regno
);
82 static void remote_resume (ptid_t ptid
, int step
,
83 enum target_signal siggnal
);
84 static void remote_async_resume (ptid_t ptid
, int step
,
85 enum target_signal siggnal
);
86 static void remote_open (char *name
, int from_tty
);
87 static void remote_async_open (char *name
, int from_tty
);
89 static void extended_remote_open (char *name
, int from_tty
);
90 static void extended_remote_async_open (char *name
, int from_tty
);
92 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
95 static void remote_close (int quitting
);
97 static void remote_store_registers (int regno
);
99 static void remote_mourn (void);
100 static void remote_async_mourn (void);
102 static void extended_remote_restart (void);
104 static void extended_remote_mourn (void);
106 static void remote_mourn_1 (struct target_ops
*);
108 static void remote_send (char *buf
, long sizeof_buf
);
110 static int readchar (int timeout
);
112 static ptid_t
remote_wait (ptid_t ptid
,
113 struct target_waitstatus
*status
);
114 static ptid_t
remote_async_wait (ptid_t ptid
,
115 struct target_waitstatus
*status
);
117 static void remote_kill (void);
118 static void remote_async_kill (void);
120 static int tohex (int nib
);
122 static void remote_detach (char *args
, int from_tty
);
124 static void remote_interrupt (int signo
);
126 static void remote_interrupt_twice (int signo
);
128 static void interrupt_query (void);
130 static void set_thread (int, int);
132 static int remote_thread_alive (ptid_t
);
134 static void get_offsets (void);
136 static long read_frame (char *buf
, long sizeof_buf
);
138 static int remote_insert_breakpoint (CORE_ADDR
, char *);
140 static int remote_remove_breakpoint (CORE_ADDR
, char *);
142 static int hexnumlen (ULONGEST num
);
144 static void init_remote_ops (void);
146 static void init_extended_remote_ops (void);
148 static void remote_stop (void);
150 static int ishex (int ch
, int *val
);
152 static int stubhex (int ch
);
154 static int hexnumstr (char *, ULONGEST
);
156 static int hexnumnstr (char *, ULONGEST
, int);
158 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
160 static void print_packet (char *);
162 static unsigned long crc32 (unsigned char *, int, unsigned int);
164 static void compare_sections_command (char *, int);
166 static void packet_command (char *, int);
168 static int stub_unpack_int (char *buff
, int fieldlength
);
170 static ptid_t
remote_current_thread (ptid_t oldptid
);
172 static void remote_find_new_threads (void);
174 static void record_currthread (int currthread
);
176 static int fromhex (int a
);
178 static int hex2bin (const char *hex
, char *bin
, int count
);
180 static int bin2hex (const char *bin
, char *hex
, int count
);
182 static int putpkt_binary (char *buf
, int cnt
);
184 static void check_binary_download (CORE_ADDR addr
);
186 struct packet_config
;
188 static void show_packet_config_cmd (struct packet_config
*config
);
190 static void update_packet_config (struct packet_config
*config
);
192 void _initialize_remote (void);
194 /* Description of the remote protocol. Strictly speaking, when the
195 target is open()ed, remote.c should create a per-target description
196 of the remote protocol using that target's architecture.
197 Unfortunately, the target stack doesn't include local state. For
198 the moment keep the information in the target's architecture
203 long offset
; /* Offset into G packet. */
204 long regnum
; /* GDB's internal register number. */
205 LONGEST pnum
; /* Remote protocol register number. */
206 int in_g_packet
; /* Always part of G packet. */
207 /* long size in bytes; == register_size (current_gdbarch, regnum);
209 /* char *name; == REGISTER_NAME (regnum); at present. */
214 /* Description of the remote protocol registers. */
215 long sizeof_g_packet
;
217 /* Description of the remote protocol registers indexed by REGNUM
218 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
219 struct packet_reg
*regs
;
221 /* This is the size (in chars) of the first response to the ``g''
222 packet. It is used as a heuristic when determining the maximum
223 size of memory-read and memory-write packets. A target will
224 typically only reserve a buffer large enough to hold the ``g''
225 packet. The size does not include packet overhead (headers and
227 long actual_register_packet_size
;
229 /* This is the maximum size (in chars) of a non read/write packet.
230 It is also used as a cap on the size of read/write packets. */
231 long remote_packet_size
;
235 /* Handle for retreving the remote protocol data from gdbarch. */
236 static struct gdbarch_data
*remote_gdbarch_data_handle
;
238 static struct remote_state
*
239 get_remote_state (void)
241 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
245 init_remote_state (struct gdbarch
*gdbarch
)
248 struct remote_state
*rs
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_state
);
250 if (deprecated_register_bytes () != 0)
251 rs
->sizeof_g_packet
= deprecated_register_bytes ();
253 rs
->sizeof_g_packet
= 0;
255 /* Assume a 1:1 regnum<->pnum table. */
256 rs
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
, NUM_REGS
+ NUM_PSEUDO_REGS
,
258 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
260 struct packet_reg
*r
= &rs
->regs
[regnum
];
263 r
->offset
= DEPRECATED_REGISTER_BYTE (regnum
);
264 r
->in_g_packet
= (regnum
< NUM_REGS
);
265 /* ...name = REGISTER_NAME (regnum); */
267 /* Compute packet size by accumulating the size of all registers. */
268 if (deprecated_register_bytes () == 0)
269 rs
->sizeof_g_packet
+= register_size (current_gdbarch
, regnum
);
272 /* Default maximum number of characters in a packet body. Many
273 remote stubs have a hardwired buffer size of 400 bytes
274 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
275 as the maximum packet-size to ensure that the packet and an extra
276 NUL character can always fit in the buffer. This stops GDB
277 trashing stubs that try to squeeze an extra NUL into what is
278 already a full buffer (As of 1999-12-04 that was most stubs. */
279 rs
->remote_packet_size
= 400 - 1;
281 /* Should rs->sizeof_g_packet needs more space than the
282 default, adjust the size accordingly. Remember that each byte is
283 encoded as two characters. 32 is the overhead for the packet
284 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
285 (``$NN:G...#NN'') is a better guess, the below has been padded a
287 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
288 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
290 /* This one is filled in when a ``g'' packet is received. */
291 rs
->actual_register_packet_size
= 0;
296 static struct packet_reg
*
297 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
299 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
303 struct packet_reg
*r
= &rs
->regs
[regnum
];
304 gdb_assert (r
->regnum
== regnum
);
309 static struct packet_reg
*
310 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
313 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
315 struct packet_reg
*r
= &rs
->regs
[i
];
322 /* FIXME: graces/2002-08-08: These variables should eventually be
323 bound to an instance of the target object (as in gdbarch-tdep()),
324 when such a thing exists. */
326 /* This is set to the data address of the access causing the target
327 to stop for a watchpoint. */
328 static CORE_ADDR remote_watch_data_address
;
330 /* This is non-zero if taregt stopped for a watchpoint. */
331 static int remote_stopped_by_watchpoint_p
;
334 static struct target_ops remote_ops
;
336 static struct target_ops extended_remote_ops
;
338 /* Temporary target ops. Just like the remote_ops and
339 extended_remote_ops, but with asynchronous support. */
340 static struct target_ops remote_async_ops
;
342 static struct target_ops extended_async_remote_ops
;
344 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
345 ``forever'' still use the normal timeout mechanism. This is
346 currently used by the ASYNC code to guarentee that target reads
347 during the initial connect always time-out. Once getpkt has been
348 modified to return a timeout indication and, in turn
349 remote_wait()/wait_for_inferior() have gained a timeout parameter
351 static int wait_forever_enabled_p
= 1;
354 /* This variable chooses whether to send a ^C or a break when the user
355 requests program interruption. Although ^C is usually what remote
356 systems expect, and that is the default here, sometimes a break is
357 preferable instead. */
359 static int remote_break
;
361 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
362 remote_open knows that we don't have a file open when the program
364 static struct serial
*remote_desc
= NULL
;
366 /* This variable sets the number of bits in an address that are to be
367 sent in a memory ("M" or "m") packet. Normally, after stripping
368 leading zeros, the entire address would be sent. This variable
369 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
370 initial implementation of remote.c restricted the address sent in
371 memory packets to ``host::sizeof long'' bytes - (typically 32
372 bits). Consequently, for 64 bit targets, the upper 32 bits of an
373 address was never sent. Since fixing this bug may cause a break in
374 some remote targets this variable is principly provided to
375 facilitate backward compatibility. */
377 static int remote_address_size
;
379 /* Tempoary to track who currently owns the terminal. See
380 target_async_terminal_* for more details. */
382 static int remote_async_terminal_ours_p
;
385 /* User configurable variables for the number of characters in a
386 memory read/write packet. MIN ((rs->remote_packet_size),
387 rs->sizeof_g_packet) is the default. Some targets need smaller
388 values (fifo overruns, et.al.) and some users need larger values
389 (speed up transfers). The variables ``preferred_*'' (the user
390 request), ``current_*'' (what was actually set) and ``forced_*''
391 (Positive - a soft limit, negative - a hard limit). */
393 struct memory_packet_config
400 /* Compute the current size of a read/write packet. Since this makes
401 use of ``actual_register_packet_size'' the computation is dynamic. */
404 get_memory_packet_size (struct memory_packet_config
*config
)
406 struct remote_state
*rs
= get_remote_state ();
407 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
408 law?) that some hosts don't cope very well with large alloca()
409 calls. Eventually the alloca() code will be replaced by calls to
410 xmalloc() and make_cleanups() allowing this restriction to either
411 be lifted or removed. */
412 #ifndef MAX_REMOTE_PACKET_SIZE
413 #define MAX_REMOTE_PACKET_SIZE 16384
415 /* NOTE: 16 is just chosen at random. */
416 #ifndef MIN_REMOTE_PACKET_SIZE
417 #define MIN_REMOTE_PACKET_SIZE 16
422 if (config
->size
<= 0)
423 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
425 what_they_get
= config
->size
;
429 what_they_get
= (rs
->remote_packet_size
);
430 /* Limit the packet to the size specified by the user. */
432 && what_they_get
> config
->size
)
433 what_they_get
= config
->size
;
434 /* Limit it to the size of the targets ``g'' response. */
435 if ((rs
->actual_register_packet_size
) > 0
436 && what_they_get
> (rs
->actual_register_packet_size
))
437 what_they_get
= (rs
->actual_register_packet_size
);
439 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
440 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
441 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
442 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
443 return what_they_get
;
446 /* Update the size of a read/write packet. If they user wants
447 something really big then do a sanity check. */
450 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
452 int fixed_p
= config
->fixed_p
;
453 long size
= config
->size
;
455 error (_("Argument required (integer, `fixed' or `limited')."));
456 else if (strcmp (args
, "hard") == 0
457 || strcmp (args
, "fixed") == 0)
459 else if (strcmp (args
, "soft") == 0
460 || strcmp (args
, "limit") == 0)
465 size
= strtoul (args
, &end
, 0);
467 error (_("Invalid %s (bad syntax)."), config
->name
);
469 /* Instead of explicitly capping the size of a packet to
470 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
471 instead allowed to set the size to something arbitrarily
473 if (size
> MAX_REMOTE_PACKET_SIZE
)
474 error (_("Invalid %s (too large)."), config
->name
);
478 if (fixed_p
&& !config
->fixed_p
)
480 if (! query (_("The target may not be able to correctly handle a %s\n"
481 "of %ld bytes. Change the packet size? "),
483 error (_("Packet size not changed."));
485 /* Update the config. */
486 config
->fixed_p
= fixed_p
;
491 show_memory_packet_size (struct memory_packet_config
*config
)
493 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
495 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
496 get_memory_packet_size (config
));
498 printf_filtered (_("Packets are limited to %ld bytes.\n"),
499 get_memory_packet_size (config
));
502 static struct memory_packet_config memory_write_packet_config
=
504 "memory-write-packet-size",
508 set_memory_write_packet_size (char *args
, int from_tty
)
510 set_memory_packet_size (args
, &memory_write_packet_config
);
514 show_memory_write_packet_size (char *args
, int from_tty
)
516 show_memory_packet_size (&memory_write_packet_config
);
520 get_memory_write_packet_size (void)
522 return get_memory_packet_size (&memory_write_packet_config
);
525 static struct memory_packet_config memory_read_packet_config
=
527 "memory-read-packet-size",
531 set_memory_read_packet_size (char *args
, int from_tty
)
533 set_memory_packet_size (args
, &memory_read_packet_config
);
537 show_memory_read_packet_size (char *args
, int from_tty
)
539 show_memory_packet_size (&memory_read_packet_config
);
543 get_memory_read_packet_size (void)
545 struct remote_state
*rs
= get_remote_state ();
546 long size
= get_memory_packet_size (&memory_read_packet_config
);
547 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
548 extra buffer size argument before the memory read size can be
549 increased beyond (rs->remote_packet_size). */
550 if (size
> (rs
->remote_packet_size
))
551 size
= (rs
->remote_packet_size
);
556 /* Generic configuration support for packets the stub optionally
557 supports. Allows the user to specify the use of the packet as well
558 as allowing GDB to auto-detect support in the remote stub. */
562 PACKET_SUPPORT_UNKNOWN
= 0,
571 enum auto_boolean detect
;
572 enum packet_support support
;
575 /* Analyze a packet's return value and update the packet config
586 update_packet_config (struct packet_config
*config
)
588 switch (config
->detect
)
590 case AUTO_BOOLEAN_TRUE
:
591 config
->support
= PACKET_ENABLE
;
593 case AUTO_BOOLEAN_FALSE
:
594 config
->support
= PACKET_DISABLE
;
596 case AUTO_BOOLEAN_AUTO
:
597 config
->support
= PACKET_SUPPORT_UNKNOWN
;
603 show_packet_config_cmd (struct packet_config
*config
)
605 char *support
= "internal-error";
606 switch (config
->support
)
612 support
= "disabled";
614 case PACKET_SUPPORT_UNKNOWN
:
618 switch (config
->detect
)
620 case AUTO_BOOLEAN_AUTO
:
621 printf_filtered (_("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n"),
622 config
->name
, config
->title
, support
);
624 case AUTO_BOOLEAN_TRUE
:
625 case AUTO_BOOLEAN_FALSE
:
626 printf_filtered (_("Support for remote protocol `%s' (%s) packet is currently %s.\n"),
627 config
->name
, config
->title
, support
);
633 add_packet_config_cmd (struct packet_config
*config
,
636 cmd_sfunc_ftype
*set_func
,
637 show_value_ftype
*show_func
,
638 struct cmd_list_element
**set_remote_list
,
639 struct cmd_list_element
**show_remote_list
,
642 struct cmd_list_element
*set_cmd
;
643 struct cmd_list_element
*show_cmd
;
650 config
->title
= title
;
651 config
->detect
= AUTO_BOOLEAN_AUTO
;
652 config
->support
= PACKET_SUPPORT_UNKNOWN
;
653 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
655 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
657 print
= xstrprintf ("Current use of remote protocol `%s' (%s) is %%s",
659 /* set/show TITLE-packet {auto,on,off} */
660 cmd_name
= xstrprintf ("%s-packet", title
);
661 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
662 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
664 set_remote_list
, show_remote_list
);
665 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
669 legacy_name
= xstrprintf ("%s-packet", name
);
670 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
672 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
677 static enum packet_result
678 packet_ok (const char *buf
, struct packet_config
*config
)
682 /* The stub recognized the packet request. Check that the
683 operation succeeded. */
684 switch (config
->support
)
686 case PACKET_SUPPORT_UNKNOWN
:
688 fprintf_unfiltered (gdb_stdlog
,
689 "Packet %s (%s) is supported\n",
690 config
->name
, config
->title
);
691 config
->support
= PACKET_ENABLE
;
694 internal_error (__FILE__
, __LINE__
,
695 _("packet_ok: attempt to use a disabled packet"));
700 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
701 /* "OK" - definitly OK. */
704 && isxdigit (buf
[1]) && isxdigit (buf
[2])
706 /* "Enn" - definitly an error. */
708 /* The packet may or may not be OK. Just assume it is. */
713 /* The stub does not support the packet. */
714 switch (config
->support
)
717 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
718 /* If the stub previously indicated that the packet was
719 supported then there is a protocol error.. */
720 error (_("Protocol error: %s (%s) conflicting enabled responses."),
721 config
->name
, config
->title
);
723 /* The user set it wrong. */
724 error (_("Enabled packet %s (%s) not recognized by stub"),
725 config
->name
, config
->title
);
727 case PACKET_SUPPORT_UNKNOWN
:
729 fprintf_unfiltered (gdb_stdlog
,
730 "Packet %s (%s) is NOT supported\n",
731 config
->name
, config
->title
);
732 config
->support
= PACKET_DISABLE
;
737 return PACKET_UNKNOWN
;
741 /* Should we try the 'vCont' (descriptive resume) request? */
742 static struct packet_config remote_protocol_vcont
;
745 set_remote_protocol_vcont_packet_cmd (char *args
, int from_tty
,
746 struct cmd_list_element
*c
)
748 update_packet_config (&remote_protocol_vcont
);
752 show_remote_protocol_vcont_packet_cmd (struct ui_file
*file
, int from_tty
,
753 struct cmd_list_element
*c
,
756 deprecated_show_value_hack (file
, from_tty
, c
, value
);
757 show_packet_config_cmd (&remote_protocol_vcont
);
760 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
761 static struct packet_config remote_protocol_qSymbol
;
764 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
765 struct cmd_list_element
*c
)
767 update_packet_config (&remote_protocol_qSymbol
);
771 show_remote_protocol_qSymbol_packet_cmd (struct ui_file
*file
, int from_tty
,
772 struct cmd_list_element
*c
,
775 deprecated_show_value_hack (file
, from_tty
, c
, value
);
776 show_packet_config_cmd (&remote_protocol_qSymbol
);
779 /* Should we try the 'P' (set register) request? */
781 static struct packet_config remote_protocol_P
;
784 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
785 struct cmd_list_element
*c
)
787 update_packet_config (&remote_protocol_P
);
791 show_remote_protocol_P_packet_cmd (struct ui_file
*file
, int from_tty
,
792 struct cmd_list_element
*c
,
795 deprecated_show_value_hack (file
, from_tty
, c
, value
);
796 show_packet_config_cmd (&remote_protocol_P
);
799 /* Should we try one of the 'Z' requests? */
803 Z_PACKET_SOFTWARE_BP
,
804 Z_PACKET_HARDWARE_BP
,
811 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
813 /* FIXME: Instead of having all these boiler plate functions, the
814 command callback should include a context argument. */
817 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
818 struct cmd_list_element
*c
)
820 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
824 show_remote_protocol_Z_software_bp_packet_cmd (struct ui_file
*file
, int from_tty
,
825 struct cmd_list_element
*c
,
828 deprecated_show_value_hack (file
, from_tty
, c
, value
);
829 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
833 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
834 struct cmd_list_element
*c
)
836 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
840 show_remote_protocol_Z_hardware_bp_packet_cmd (struct ui_file
*file
, int from_tty
,
841 struct cmd_list_element
*c
,
844 deprecated_show_value_hack (file
, from_tty
, c
, value
);
845 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
849 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
850 struct cmd_list_element
*c
)
852 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
856 show_remote_protocol_Z_write_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
857 struct cmd_list_element
*c
,
860 deprecated_show_value_hack (file
, from_tty
, c
, value
);
861 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
865 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
866 struct cmd_list_element
*c
)
868 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
872 show_remote_protocol_Z_read_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
873 struct cmd_list_element
*c
,
876 deprecated_show_value_hack (file
, from_tty
, c
, value
);
877 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
881 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
882 struct cmd_list_element
*c
)
884 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
888 show_remote_protocol_Z_access_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
889 struct cmd_list_element
*c
,
892 deprecated_show_value_hack (file
, from_tty
, c
, value
);
893 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
896 /* For compatibility with older distributions. Provide a ``set remote
897 Z-packet ...'' command that updates all the Z packet types. */
899 static enum auto_boolean remote_Z_packet_detect
;
902 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
903 struct cmd_list_element
*c
)
906 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
908 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
909 update_packet_config (&remote_protocol_Z
[i
]);
914 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
915 struct cmd_list_element
*c
,
919 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
921 show_packet_config_cmd (&remote_protocol_Z
[i
]);
925 /* Should we try the 'X' (remote binary download) packet?
927 This variable (available to the user via "set remote X-packet")
928 dictates whether downloads are sent in binary (via the 'X' packet).
929 We assume that the stub can, and attempt to do it. This will be
930 cleared if the stub does not understand it. This switch is still
931 needed, though in cases when the packet is supported in the stub,
932 but the connection does not allow it (i.e., 7-bit serial connection
935 static struct packet_config remote_protocol_binary_download
;
937 /* Should we try the 'ThreadInfo' query packet?
939 This variable (NOT available to the user: auto-detect only!)
940 determines whether GDB will use the new, simpler "ThreadInfo"
941 query or the older, more complex syntax for thread queries.
942 This is an auto-detect variable (set to true at each connect,
943 and set to false when the target fails to recognize it). */
945 static int use_threadinfo_query
;
946 static int use_threadextra_query
;
949 set_remote_protocol_binary_download_cmd (char *args
,
951 struct cmd_list_element
*c
)
953 update_packet_config (&remote_protocol_binary_download
);
957 show_remote_protocol_binary_download_cmd (struct ui_file
*file
, int from_tty
,
958 struct cmd_list_element
*c
,
961 deprecated_show_value_hack (file
, from_tty
, c
, value
);
962 show_packet_config_cmd (&remote_protocol_binary_download
);
965 /* Should we try the 'qPart:auxv' (target auxiliary vector read) request? */
966 static struct packet_config remote_protocol_qPart_auxv
;
969 set_remote_protocol_qPart_auxv_packet_cmd (char *args
, int from_tty
,
970 struct cmd_list_element
*c
)
972 update_packet_config (&remote_protocol_qPart_auxv
);
976 show_remote_protocol_qPart_auxv_packet_cmd (struct ui_file
*file
, int from_tty
,
977 struct cmd_list_element
*c
,
980 deprecated_show_value_hack (file
, from_tty
, c
, value
);
981 show_packet_config_cmd (&remote_protocol_qPart_auxv
);
984 static struct packet_config remote_protocol_p
;
987 set_remote_protocol_p_packet_cmd (char *args
, int from_tty
,
988 struct cmd_list_element
*c
)
990 update_packet_config (&remote_protocol_p
);
994 show_remote_protocol_p_packet_cmd (struct ui_file
*file
, int from_tty
,
995 struct cmd_list_element
*c
,
998 deprecated_show_value_hack (file
, from_tty
, c
, value
);
999 show_packet_config_cmd (&remote_protocol_p
);
1004 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1005 static void *sigint_remote_twice_token
;
1006 static void *sigint_remote_token
;
1008 /* These are pointers to hook functions that may be set in order to
1009 modify resume/wait behavior for a particular architecture. */
1011 void (*deprecated_target_resume_hook
) (void);
1012 void (*deprecated_target_wait_loop_hook
) (void);
1016 /* These are the threads which we last sent to the remote system.
1017 -1 for all or -2 for not sent yet. */
1018 static int general_thread
;
1019 static int continue_thread
;
1021 /* Call this function as a result of
1022 1) A halt indication (T packet) containing a thread id
1023 2) A direct query of currthread
1024 3) Successful execution of set thread
1028 record_currthread (int currthread
)
1030 general_thread
= currthread
;
1032 /* If this is a new thread, add it to GDB's thread list.
1033 If we leave it up to WFI to do this, bad things will happen. */
1034 if (!in_thread_list (pid_to_ptid (currthread
)))
1036 add_thread (pid_to_ptid (currthread
));
1037 ui_out_text (uiout
, "[New ");
1038 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1039 ui_out_text (uiout
, "]\n");
1043 #define MAGIC_NULL_PID 42000
1046 set_thread (int th
, int gen
)
1048 struct remote_state
*rs
= get_remote_state ();
1049 char *buf
= alloca (rs
->remote_packet_size
);
1050 int state
= gen
? general_thread
: continue_thread
;
1056 buf
[1] = gen
? 'g' : 'c';
1057 if (th
== MAGIC_NULL_PID
)
1063 sprintf (&buf
[2], "-%x", -th
);
1065 sprintf (&buf
[2], "%x", th
);
1067 getpkt (buf
, (rs
->remote_packet_size
), 0);
1069 general_thread
= th
;
1071 continue_thread
= th
;
1074 /* Return nonzero if the thread TH is still alive on the remote system. */
1077 remote_thread_alive (ptid_t ptid
)
1079 int tid
= PIDGET (ptid
);
1083 sprintf (buf
, "T-%08x", -tid
);
1085 sprintf (buf
, "T%08x", tid
);
1087 getpkt (buf
, sizeof (buf
), 0);
1088 return (buf
[0] == 'O' && buf
[1] == 'K');
1091 /* About these extended threadlist and threadinfo packets. They are
1092 variable length packets but, the fields within them are often fixed
1093 length. They are redundent enough to send over UDP as is the
1094 remote protocol in general. There is a matching unit test module
1097 #define OPAQUETHREADBYTES 8
1099 /* a 64 bit opaque identifier */
1100 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1102 /* WARNING: This threadref data structure comes from the remote O.S.,
1103 libstub protocol encoding, and remote.c. it is not particularly
1106 /* Right now, the internal structure is int. We want it to be bigger.
1110 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1112 /* gdb_ext_thread_info is an internal GDB data structure which is
1113 equivalint to the reply of the remote threadinfo packet. */
1115 struct gdb_ext_thread_info
1117 threadref threadid
; /* External form of thread reference. */
1118 int active
; /* Has state interesting to GDB?
1120 char display
[256]; /* Brief state display, name,
1121 blocked/syspended. */
1122 char shortname
[32]; /* To be used to name threads. */
1123 char more_display
[256]; /* Long info, statistics, queue depth,
1127 /* The volume of remote transfers can be limited by submitting
1128 a mask containing bits specifying the desired information.
1129 Use a union of these values as the 'selection' parameter to
1130 get_thread_info. FIXME: Make these TAG names more thread specific.
1133 #define TAG_THREADID 1
1134 #define TAG_EXISTS 2
1135 #define TAG_DISPLAY 4
1136 #define TAG_THREADNAME 8
1137 #define TAG_MOREDISPLAY 16
1139 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1141 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1143 static char *unpack_nibble (char *buf
, int *val
);
1145 static char *pack_nibble (char *buf
, int nibble
);
1147 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1149 static char *unpack_byte (char *buf
, int *value
);
1151 static char *pack_int (char *buf
, int value
);
1153 static char *unpack_int (char *buf
, int *value
);
1155 static char *unpack_string (char *src
, char *dest
, int length
);
1157 static char *pack_threadid (char *pkt
, threadref
*id
);
1159 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1161 void int_to_threadref (threadref
*id
, int value
);
1163 static int threadref_to_int (threadref
*ref
);
1165 static void copy_threadref (threadref
*dest
, threadref
*src
);
1167 static int threadmatch (threadref
*dest
, threadref
*src
);
1169 static char *pack_threadinfo_request (char *pkt
, int mode
,
1172 static int remote_unpack_thread_info_response (char *pkt
,
1173 threadref
*expectedref
,
1174 struct gdb_ext_thread_info
1178 static int remote_get_threadinfo (threadref
*threadid
,
1179 int fieldset
, /*TAG mask */
1180 struct gdb_ext_thread_info
*info
);
1182 static char *pack_threadlist_request (char *pkt
, int startflag
,
1184 threadref
*nextthread
);
1186 static int parse_threadlist_response (char *pkt
,
1188 threadref
*original_echo
,
1189 threadref
*resultlist
,
1192 static int remote_get_threadlist (int startflag
,
1193 threadref
*nextthread
,
1197 threadref
*threadlist
);
1199 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1201 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1202 void *context
, int looplimit
);
1204 static int remote_newthread_step (threadref
*ref
, void *context
);
1206 /* Encode 64 bits in 16 chars of hex. */
1208 static const char hexchars
[] = "0123456789abcdef";
1211 ishex (int ch
, int *val
)
1213 if ((ch
>= 'a') && (ch
<= 'f'))
1215 *val
= ch
- 'a' + 10;
1218 if ((ch
>= 'A') && (ch
<= 'F'))
1220 *val
= ch
- 'A' + 10;
1223 if ((ch
>= '0') && (ch
<= '9'))
1234 if (ch
>= 'a' && ch
<= 'f')
1235 return ch
- 'a' + 10;
1236 if (ch
>= '0' && ch
<= '9')
1238 if (ch
>= 'A' && ch
<= 'F')
1239 return ch
- 'A' + 10;
1244 stub_unpack_int (char *buff
, int fieldlength
)
1251 nibble
= stubhex (*buff
++);
1255 retval
= retval
<< 4;
1261 unpack_varlen_hex (char *buff
, /* packet to parse */
1267 while (ishex (*buff
, &nibble
))
1270 retval
= retval
<< 4;
1271 retval
|= nibble
& 0x0f;
1278 unpack_nibble (char *buf
, int *val
)
1280 ishex (*buf
++, val
);
1285 pack_nibble (char *buf
, int nibble
)
1287 *buf
++ = hexchars
[(nibble
& 0x0f)];
1292 pack_hex_byte (char *pkt
, int byte
)
1294 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1295 *pkt
++ = hexchars
[(byte
& 0xf)];
1300 unpack_byte (char *buf
, int *value
)
1302 *value
= stub_unpack_int (buf
, 2);
1307 pack_int (char *buf
, int value
)
1309 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1310 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1311 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1312 buf
= pack_hex_byte (buf
, (value
& 0xff));
1317 unpack_int (char *buf
, int *value
)
1319 *value
= stub_unpack_int (buf
, 8);
1323 #if 0 /* Currently unused, uncomment when needed. */
1324 static char *pack_string (char *pkt
, char *string
);
1327 pack_string (char *pkt
, char *string
)
1332 len
= strlen (string
);
1334 len
= 200; /* Bigger than most GDB packets, junk??? */
1335 pkt
= pack_hex_byte (pkt
, len
);
1339 if ((ch
== '\0') || (ch
== '#'))
1340 ch
= '*'; /* Protect encapsulation. */
1345 #endif /* 0 (unused) */
1348 unpack_string (char *src
, char *dest
, int length
)
1357 pack_threadid (char *pkt
, threadref
*id
)
1360 unsigned char *altid
;
1362 altid
= (unsigned char *) id
;
1363 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1365 pkt
= pack_hex_byte (pkt
, *altid
++);
1371 unpack_threadid (char *inbuf
, threadref
*id
)
1374 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1377 altref
= (char *) id
;
1379 while (inbuf
< limit
)
1381 x
= stubhex (*inbuf
++);
1382 y
= stubhex (*inbuf
++);
1383 *altref
++ = (x
<< 4) | y
;
1388 /* Externally, threadrefs are 64 bits but internally, they are still
1389 ints. This is due to a mismatch of specifications. We would like
1390 to use 64bit thread references internally. This is an adapter
1394 int_to_threadref (threadref
*id
, int value
)
1396 unsigned char *scan
;
1398 scan
= (unsigned char *) id
;
1404 *scan
++ = (value
>> 24) & 0xff;
1405 *scan
++ = (value
>> 16) & 0xff;
1406 *scan
++ = (value
>> 8) & 0xff;
1407 *scan
++ = (value
& 0xff);
1411 threadref_to_int (threadref
*ref
)
1414 unsigned char *scan
;
1416 scan
= (char *) ref
;
1420 value
= (value
<< 8) | ((*scan
++) & 0xff);
1425 copy_threadref (threadref
*dest
, threadref
*src
)
1428 unsigned char *csrc
, *cdest
;
1430 csrc
= (unsigned char *) src
;
1431 cdest
= (unsigned char *) dest
;
1438 threadmatch (threadref
*dest
, threadref
*src
)
1440 /* Things are broken right now, so just assume we got a match. */
1442 unsigned char *srcp
, *destp
;
1444 srcp
= (char *) src
;
1445 destp
= (char *) dest
;
1449 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1456 threadid:1, # always request threadid
1463 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1466 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1468 *pkt
++ = 'q'; /* Info Query */
1469 *pkt
++ = 'P'; /* process or thread info */
1470 pkt
= pack_int (pkt
, mode
); /* mode */
1471 pkt
= pack_threadid (pkt
, id
); /* threadid */
1472 *pkt
= '\0'; /* terminate */
1476 /* These values tag the fields in a thread info response packet. */
1477 /* Tagging the fields allows us to request specific fields and to
1478 add more fields as time goes by. */
1480 #define TAG_THREADID 1 /* Echo the thread identifier. */
1481 #define TAG_EXISTS 2 /* Is this process defined enough to
1482 fetch registers and its stack? */
1483 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1484 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
1485 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1489 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1490 struct gdb_ext_thread_info
*info
)
1492 struct remote_state
*rs
= get_remote_state ();
1496 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1499 /* info->threadid = 0; FIXME: implement zero_threadref. */
1501 info
->display
[0] = '\0';
1502 info
->shortname
[0] = '\0';
1503 info
->more_display
[0] = '\0';
1505 /* Assume the characters indicating the packet type have been
1507 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1508 pkt
= unpack_threadid (pkt
, &ref
);
1511 warning (_("Incomplete response to threadinfo request."));
1512 if (!threadmatch (&ref
, expectedref
))
1513 { /* This is an answer to a different request. */
1514 warning (_("ERROR RMT Thread info mismatch."));
1517 copy_threadref (&info
->threadid
, &ref
);
1519 /* Loop on tagged fields , try to bail if somthing goes wrong. */
1521 /* Packets are terminated with nulls. */
1522 while ((pkt
< limit
) && mask
&& *pkt
)
1524 pkt
= unpack_int (pkt
, &tag
); /* tag */
1525 pkt
= unpack_byte (pkt
, &length
); /* length */
1526 if (!(tag
& mask
)) /* Tags out of synch with mask. */
1528 warning (_("ERROR RMT: threadinfo tag mismatch."));
1532 if (tag
== TAG_THREADID
)
1536 warning (_("ERROR RMT: length of threadid is not 16."));
1540 pkt
= unpack_threadid (pkt
, &ref
);
1541 mask
= mask
& ~TAG_THREADID
;
1544 if (tag
== TAG_EXISTS
)
1546 info
->active
= stub_unpack_int (pkt
, length
);
1548 mask
= mask
& ~(TAG_EXISTS
);
1551 warning (_("ERROR RMT: 'exists' length too long."));
1557 if (tag
== TAG_THREADNAME
)
1559 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1560 mask
= mask
& ~TAG_THREADNAME
;
1563 if (tag
== TAG_DISPLAY
)
1565 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1566 mask
= mask
& ~TAG_DISPLAY
;
1569 if (tag
== TAG_MOREDISPLAY
)
1571 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1572 mask
= mask
& ~TAG_MOREDISPLAY
;
1575 warning (_("ERROR RMT: unknown thread info tag."));
1576 break; /* Not a tag we know about. */
1582 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1583 struct gdb_ext_thread_info
*info
)
1585 struct remote_state
*rs
= get_remote_state ();
1587 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1589 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1590 putpkt (threadinfo_pkt
);
1591 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1592 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2,
1597 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1600 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1601 threadref
*nextthread
)
1603 *pkt
++ = 'q'; /* info query packet */
1604 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1605 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1606 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1607 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1612 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1615 parse_threadlist_response (char *pkt
, int result_limit
,
1616 threadref
*original_echo
, threadref
*resultlist
,
1619 struct remote_state
*rs
= get_remote_state ();
1621 int count
, resultcount
, done
;
1624 /* Assume the 'q' and 'M chars have been stripped. */
1625 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
);
1626 /* done parse past here */
1627 pkt
= unpack_byte (pkt
, &count
); /* count field */
1628 pkt
= unpack_nibble (pkt
, &done
);
1629 /* The first threadid is the argument threadid. */
1630 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1631 while ((count
-- > 0) && (pkt
< limit
))
1633 pkt
= unpack_threadid (pkt
, resultlist
++);
1634 if (resultcount
++ >= result_limit
)
1643 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1644 int *done
, int *result_count
, threadref
*threadlist
)
1646 struct remote_state
*rs
= get_remote_state ();
1647 static threadref echo_nextthread
;
1648 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1649 char *t_response
= alloca (rs
->remote_packet_size
);
1652 /* Trancate result limit to be smaller than the packet size. */
1653 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1654 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1656 pack_threadlist_request (threadlist_packet
,
1657 startflag
, result_limit
, nextthread
);
1658 putpkt (threadlist_packet
);
1659 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1662 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1665 if (!threadmatch (&echo_nextthread
, nextthread
))
1667 /* FIXME: This is a good reason to drop the packet. */
1668 /* Possably, there is a duplicate response. */
1670 retransmit immediatly - race conditions
1671 retransmit after timeout - yes
1673 wait for packet, then exit
1675 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
1676 return 0; /* I choose simply exiting. */
1678 if (*result_count
<= 0)
1682 warning (_("RMT ERROR : failed to get remote thread list."));
1685 return result
; /* break; */
1687 if (*result_count
> result_limit
)
1690 warning (_("RMT ERROR: threadlist response longer than requested."));
1696 /* This is the interface between remote and threads, remotes upper
1699 /* remote_find_new_threads retrieves the thread list and for each
1700 thread in the list, looks up the thread in GDB's internal list,
1701 ading the thread if it does not already exist. This involves
1702 getting partial thread lists from the remote target so, polling the
1703 quit_flag is required. */
1706 /* About this many threadisds fit in a packet. */
1708 #define MAXTHREADLISTRESULTS 32
1711 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1714 int done
, i
, result_count
;
1718 static threadref nextthread
;
1719 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1724 if (loopcount
++ > looplimit
)
1727 warning (_("Remote fetch threadlist -infinite loop-."));
1730 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1731 &done
, &result_count
, resultthreadlist
))
1736 /* Clear for later iterations. */
1738 /* Setup to resume next batch of thread references, set nextthread. */
1739 if (result_count
>= 1)
1740 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1742 while (result_count
--)
1743 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1750 remote_newthread_step (threadref
*ref
, void *context
)
1754 ptid
= pid_to_ptid (threadref_to_int (ref
));
1756 if (!in_thread_list (ptid
))
1758 return 1; /* continue iterator */
1761 #define CRAZY_MAX_THREADS 1000
1764 remote_current_thread (ptid_t oldpid
)
1766 struct remote_state
*rs
= get_remote_state ();
1767 char *buf
= alloca (rs
->remote_packet_size
);
1770 getpkt (buf
, (rs
->remote_packet_size
), 0);
1771 if (buf
[0] == 'Q' && buf
[1] == 'C')
1772 /* Use strtoul here, so we'll correctly parse values whose highest
1773 bit is set. The protocol carries them as a simple series of
1774 hex digits; in the absence of a sign, strtol will see such
1775 values as positive numbers out of range for signed 'long', and
1776 return LONG_MAX to indicate an overflow. */
1777 return pid_to_ptid (strtoul (&buf
[2], NULL
, 16));
1782 /* Find new threads for info threads command.
1783 * Original version, using John Metzler's thread protocol.
1787 remote_find_new_threads (void)
1789 remote_threadlist_iterator (remote_newthread_step
, 0,
1791 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1792 inferior_ptid
= remote_current_thread (inferior_ptid
);
1796 * Find all threads for info threads command.
1797 * Uses new thread protocol contributed by Cisco.
1798 * Falls back and attempts to use the older method (above)
1799 * if the target doesn't respond to the new method.
1803 remote_threads_info (void)
1805 struct remote_state
*rs
= get_remote_state ();
1806 char *buf
= alloca (rs
->remote_packet_size
);
1810 if (remote_desc
== 0) /* paranoia */
1811 error (_("Command can only be used when connected to the remote target."));
1813 if (use_threadinfo_query
)
1815 putpkt ("qfThreadInfo");
1817 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1818 if (bufp
[0] != '\0') /* q packet recognized */
1820 while (*bufp
++ == 'm') /* reply contains one or more TID */
1824 /* Use strtoul here, so we'll correctly parse values
1825 whose highest bit is set. The protocol carries
1826 them as a simple series of hex digits; in the
1827 absence of a sign, strtol will see such values as
1828 positive numbers out of range for signed 'long',
1829 and return LONG_MAX to indicate an overflow. */
1830 tid
= strtoul (bufp
, &bufp
, 16);
1831 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1832 add_thread (pid_to_ptid (tid
));
1834 while (*bufp
++ == ','); /* comma-separated list */
1835 putpkt ("qsThreadInfo");
1837 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1843 /* Else fall back to old method based on jmetzler protocol. */
1844 use_threadinfo_query
= 0;
1845 remote_find_new_threads ();
1850 * Collect a descriptive string about the given thread.
1851 * The target may say anything it wants to about the thread
1852 * (typically info about its blocked / runnable state, name, etc.).
1853 * This string will appear in the info threads display.
1855 * Optional: targets are not required to implement this function.
1859 remote_threads_extra_info (struct thread_info
*tp
)
1861 struct remote_state
*rs
= get_remote_state ();
1865 struct gdb_ext_thread_info threadinfo
;
1866 static char display_buf
[100]; /* arbitrary... */
1867 char *bufp
= alloca (rs
->remote_packet_size
);
1868 int n
= 0; /* position in display_buf */
1870 if (remote_desc
== 0) /* paranoia */
1871 internal_error (__FILE__
, __LINE__
,
1872 _("remote_threads_extra_info"));
1874 if (use_threadextra_query
)
1876 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1878 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1881 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1882 result
= hex2bin (bufp
, display_buf
, n
);
1883 display_buf
[result
] = '\0';
1888 /* If the above query fails, fall back to the old method. */
1889 use_threadextra_query
= 0;
1890 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1891 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1892 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1893 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1894 if (threadinfo
.active
)
1896 if (*threadinfo
.shortname
)
1897 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1898 if (*threadinfo
.display
)
1899 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1900 if (*threadinfo
.more_display
)
1901 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1902 threadinfo
.more_display
);
1906 /* For purely cosmetic reasons, clear up trailing commas. */
1907 if (',' == display_buf
[n
-1])
1908 display_buf
[n
-1] = ' ';
1917 /* Restart the remote side; this is an extended protocol operation. */
1920 extended_remote_restart (void)
1922 struct remote_state
*rs
= get_remote_state ();
1923 char *buf
= alloca (rs
->remote_packet_size
);
1925 /* Send the restart command; for reasons I don't understand the
1926 remote side really expects a number after the "R". */
1928 sprintf (&buf
[1], "%x", 0);
1931 /* Now query for status so this looks just like we restarted
1932 gdbserver from scratch. */
1934 getpkt (buf
, (rs
->remote_packet_size
), 0);
1937 /* Clean up connection to a remote debugger. */
1940 remote_close (int quitting
)
1943 serial_close (remote_desc
);
1947 /* Query the remote side for the text, data and bss offsets. */
1952 struct remote_state
*rs
= get_remote_state ();
1953 char *buf
= alloca (rs
->remote_packet_size
);
1956 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1957 struct section_offsets
*offs
;
1959 putpkt ("qOffsets");
1961 getpkt (buf
, (rs
->remote_packet_size
), 0);
1963 if (buf
[0] == '\000')
1964 return; /* Return silently. Stub doesn't support
1968 warning (_("Remote failure reply: %s"), buf
);
1972 /* Pick up each field in turn. This used to be done with scanf, but
1973 scanf will make trouble if CORE_ADDR size doesn't match
1974 conversion directives correctly. The following code will work
1975 with any size of CORE_ADDR. */
1976 text_addr
= data_addr
= bss_addr
= 0;
1980 if (strncmp (ptr
, "Text=", 5) == 0)
1983 /* Don't use strtol, could lose on big values. */
1984 while (*ptr
&& *ptr
!= ';')
1985 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1990 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1993 while (*ptr
&& *ptr
!= ';')
1994 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1999 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2002 while (*ptr
&& *ptr
!= ';')
2003 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2009 error (_("Malformed response to offset query, %s"), buf
);
2011 if (symfile_objfile
== NULL
)
2014 offs
= ((struct section_offsets
*)
2015 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2016 memcpy (offs
, symfile_objfile
->section_offsets
,
2017 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2019 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2021 /* This is a temporary kludge to force data and bss to use the same offsets
2022 because that's what nlmconv does now. The real solution requires changes
2023 to the stub and remote.c that I don't have time to do right now. */
2025 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2026 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2028 objfile_relocate (symfile_objfile
, offs
);
2031 /* Stub for catch_errors. */
2034 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2036 start_remote (); /* Initialize gdb process mechanisms. */
2037 /* NOTE: Return something >=0. A -ve value is reserved for
2038 catch_exceptions. */
2043 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2045 immediate_quit
++; /* Allow user to interrupt it. */
2047 /* Ack any packet which the remote side has already sent. */
2048 serial_write (remote_desc
, "+", 1);
2050 /* Let the stub know that we want it to return the thread. */
2053 inferior_ptid
= remote_current_thread (inferior_ptid
);
2055 get_offsets (); /* Get text, data & bss offsets. */
2057 putpkt ("?"); /* Initiate a query from remote machine. */
2060 remote_start_remote_dummy (uiout
, dummy
);
2063 /* Open a connection to a remote debugger.
2064 NAME is the filename used for communication. */
2067 remote_open (char *name
, int from_tty
)
2069 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2072 /* Just like remote_open, but with asynchronous support. */
2074 remote_async_open (char *name
, int from_tty
)
2076 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2079 /* Open a connection to a remote debugger using the extended
2080 remote gdb protocol. NAME is the filename used for communication. */
2083 extended_remote_open (char *name
, int from_tty
)
2085 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2089 /* Just like extended_remote_open, but with asynchronous support. */
2091 extended_remote_async_open (char *name
, int from_tty
)
2093 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2094 1 /*extended_p */, 1 /* async_p */);
2097 /* Generic code for opening a connection to a remote target. */
2100 init_all_packet_configs (void)
2103 update_packet_config (&remote_protocol_P
);
2104 update_packet_config (&remote_protocol_p
);
2105 update_packet_config (&remote_protocol_qSymbol
);
2106 update_packet_config (&remote_protocol_vcont
);
2107 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2108 update_packet_config (&remote_protocol_Z
[i
]);
2109 /* Force remote_write_bytes to check whether target supports binary
2111 update_packet_config (&remote_protocol_binary_download
);
2112 update_packet_config (&remote_protocol_qPart_auxv
);
2115 /* Symbol look-up. */
2118 remote_check_symbols (struct objfile
*objfile
)
2120 struct remote_state
*rs
= get_remote_state ();
2121 char *msg
, *reply
, *tmp
;
2122 struct minimal_symbol
*sym
;
2125 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2128 msg
= alloca (rs
->remote_packet_size
);
2129 reply
= alloca (rs
->remote_packet_size
);
2131 /* Invite target to request symbol lookups. */
2133 putpkt ("qSymbol::");
2134 getpkt (reply
, (rs
->remote_packet_size
), 0);
2135 packet_ok (reply
, &remote_protocol_qSymbol
);
2137 while (strncmp (reply
, "qSymbol:", 8) == 0)
2140 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2142 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2144 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2146 sprintf (msg
, "qSymbol:%s:%s",
2147 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2150 getpkt (reply
, (rs
->remote_packet_size
), 0);
2154 static struct serial
*
2155 remote_serial_open (char *name
)
2157 static int udp_warning
= 0;
2159 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2160 of in ser-tcp.c, because it is the remote protocol assuming that the
2161 serial connection is reliable and not the serial connection promising
2163 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2166 The remote protocol may be unreliable over UDP.\n\
2167 Some events may be lost, rendering further debugging impossible."));
2171 return serial_open (name
);
2175 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2176 int extended_p
, int async_p
)
2178 struct exception ex
;
2179 struct remote_state
*rs
= get_remote_state ();
2181 error (_("To open a remote debug connection, you need to specify what\n"
2182 "serial device is attached to the remote system\n"
2183 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
2185 /* See FIXME above. */
2187 wait_forever_enabled_p
= 1;
2189 reopen_exec_file ();
2192 target_preopen (from_tty
);
2194 unpush_target (target
);
2196 remote_desc
= remote_serial_open (name
);
2198 perror_with_name (name
);
2200 if (baud_rate
!= -1)
2202 if (serial_setbaudrate (remote_desc
, baud_rate
))
2204 /* The requested speed could not be set. Error out to
2205 top level after closing remote_desc. Take care to
2206 set remote_desc to NULL to avoid closing remote_desc
2208 serial_close (remote_desc
);
2210 perror_with_name (name
);
2214 serial_raw (remote_desc
);
2216 /* If there is something sitting in the buffer we might take it as a
2217 response to a command, which would be bad. */
2218 serial_flush_input (remote_desc
);
2222 puts_filtered ("Remote debugging using ");
2223 puts_filtered (name
);
2224 puts_filtered ("\n");
2226 push_target (target
); /* Switch to using remote target now. */
2228 init_all_packet_configs ();
2230 general_thread
= -2;
2231 continue_thread
= -2;
2233 /* Probe for ability to use "ThreadInfo" query, as required. */
2234 use_threadinfo_query
= 1;
2235 use_threadextra_query
= 1;
2237 /* Without this, some commands which require an active target (such
2238 as kill) won't work. This variable serves (at least) double duty
2239 as both the pid of the target process (if it has such), and as a
2240 flag indicating that a target is active. These functions should
2241 be split out into seperate variables, especially since GDB will
2242 someday have a notion of debugging several processes. */
2244 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2248 /* With this target we start out by owning the terminal. */
2249 remote_async_terminal_ours_p
= 1;
2251 /* FIXME: cagney/1999-09-23: During the initial connection it is
2252 assumed that the target is already ready and able to respond to
2253 requests. Unfortunately remote_start_remote() eventually calls
2254 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2255 around this. Eventually a mechanism that allows
2256 wait_for_inferior() to expect/get timeouts will be
2258 wait_forever_enabled_p
= 0;
2261 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2262 /* First delete any symbols previously loaded from shared libraries. */
2263 no_shared_libraries (NULL
, 0);
2266 /* Start the remote connection. If error() or QUIT, discard this
2267 target (we'd otherwise be in an inconsistent state) and then
2268 propogate the error on up the exception chain. This ensures that
2269 the caller doesn't stumble along blindly assuming that the
2270 function succeeded. The CLI doesn't have this problem but other
2271 UI's, such as MI do.
2273 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2274 this function should return an error indication letting the
2275 caller restore the previous state. Unfortunately the command
2276 ``target remote'' is directly wired to this function making that
2277 impossible. On a positive note, the CLI side of this problem has
2278 been fixed - the function set_cmd_context() makes it possible for
2279 all the ``target ....'' commands to share a common callback
2280 function. See cli-dump.c. */
2281 ex
= catch_exception (uiout
, remote_start_remote
, NULL
, RETURN_MASK_ALL
);
2286 wait_forever_enabled_p
= 1;
2287 throw_exception (ex
);
2291 wait_forever_enabled_p
= 1;
2295 /* Tell the remote that we are using the extended protocol. */
2296 char *buf
= alloca (rs
->remote_packet_size
);
2298 getpkt (buf
, (rs
->remote_packet_size
), 0);
2300 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2301 /* FIXME: need a master target_open vector from which all
2302 remote_opens can be called, so that stuff like this can
2303 go there. Failing that, the following code must be copied
2304 to the open function for any remote target that wants to
2305 support svr4 shared libraries. */
2307 /* Set up to detect and load shared libraries. */
2308 if (exec_bfd
) /* No use without an exec file. */
2310 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2311 remote_check_symbols (symfile_objfile
);
2315 observer_notify_inferior_created (¤t_target
, from_tty
);
2318 /* This takes a program previously attached to and detaches it. After
2319 this is done, GDB can be used to debug some other program. We
2320 better not have left any breakpoints in the target program or it'll
2321 die when it hits one. */
2324 remote_detach (char *args
, int from_tty
)
2326 struct remote_state
*rs
= get_remote_state ();
2327 char *buf
= alloca (rs
->remote_packet_size
);
2330 error (_("Argument given to \"detach\" when remotely debugging."));
2332 /* Tell the remote target to detach. */
2334 remote_send (buf
, (rs
->remote_packet_size
));
2336 /* Unregister the file descriptor from the event loop. */
2337 if (target_is_async_p ())
2338 serial_async (remote_desc
, NULL
, 0);
2340 target_mourn_inferior ();
2342 puts_filtered ("Ending remote debugging.\n");
2345 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2348 remote_disconnect (char *args
, int from_tty
)
2350 struct remote_state
*rs
= get_remote_state ();
2351 char *buf
= alloca (rs
->remote_packet_size
);
2354 error (_("Argument given to \"detach\" when remotely debugging."));
2356 /* Unregister the file descriptor from the event loop. */
2357 if (target_is_async_p ())
2358 serial_async (remote_desc
, NULL
, 0);
2360 target_mourn_inferior ();
2362 puts_filtered ("Ending remote debugging.\n");
2365 /* Convert hex digit A to a number. */
2370 if (a
>= '0' && a
<= '9')
2372 else if (a
>= 'a' && a
<= 'f')
2373 return a
- 'a' + 10;
2374 else if (a
>= 'A' && a
<= 'F')
2375 return a
- 'A' + 10;
2377 error (_("Reply contains invalid hex digit %d"), a
);
2381 hex2bin (const char *hex
, char *bin
, int count
)
2385 for (i
= 0; i
< count
; i
++)
2387 if (hex
[0] == 0 || hex
[1] == 0)
2389 /* Hex string is short, or of uneven length.
2390 Return the count that has been converted so far. */
2393 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2399 /* Convert number NIB to a hex digit. */
2407 return 'a' + nib
- 10;
2411 bin2hex (const char *bin
, char *hex
, int count
)
2414 /* May use a length, or a nul-terminated string as input. */
2416 count
= strlen (bin
);
2418 for (i
= 0; i
< count
; i
++)
2420 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2421 *hex
++ = tohex (*bin
++ & 0xf);
2427 /* Check for the availability of vCont. This function should also check
2431 remote_vcont_probe (struct remote_state
*rs
, char *buf
)
2433 strcpy (buf
, "vCont?");
2435 getpkt (buf
, rs
->remote_packet_size
, 0);
2437 /* Make sure that the features we assume are supported. */
2438 if (strncmp (buf
, "vCont", 5) == 0)
2441 int support_s
, support_S
, support_c
, support_C
;
2447 while (p
&& *p
== ';')
2450 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2452 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2454 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2456 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2459 p
= strchr (p
, ';');
2462 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
2463 BUF will make packet_ok disable the packet. */
2464 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
2468 packet_ok (buf
, &remote_protocol_vcont
);
2471 /* Resume the remote inferior by using a "vCont" packet. The thread
2472 to be resumed is PTID; STEP and SIGGNAL indicate whether the
2473 resumed thread should be single-stepped and/or signalled. If PTID's
2474 PID is -1, then all threads are resumed; the thread to be stepped and/or
2475 signalled is given in the global INFERIOR_PTID. This function returns
2476 non-zero iff it resumes the inferior.
2478 This function issues a strict subset of all possible vCont commands at the
2482 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2484 struct remote_state
*rs
= get_remote_state ();
2485 int pid
= PIDGET (ptid
);
2486 char *buf
= NULL
, *outbuf
;
2487 struct cleanup
*old_cleanup
;
2489 buf
= xmalloc (rs
->remote_packet_size
);
2490 old_cleanup
= make_cleanup (xfree
, buf
);
2492 if (remote_protocol_vcont
.support
== PACKET_SUPPORT_UNKNOWN
)
2493 remote_vcont_probe (rs
, buf
);
2495 if (remote_protocol_vcont
.support
== PACKET_DISABLE
)
2497 do_cleanups (old_cleanup
);
2501 /* If we could generate a wider range of packets, we'd have to worry
2502 about overflowing BUF. Should there be a generic
2503 "multi-part-packet" packet? */
2505 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
)
2507 /* MAGIC_NULL_PTID means that we don't have any active threads, so we
2508 don't have any PID numbers the inferior will understand. Make sure
2509 to only send forms that do not specify a PID. */
2510 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2511 outbuf
= xstrprintf ("vCont;S%02x", siggnal
);
2513 outbuf
= xstrprintf ("vCont;s");
2514 else if (siggnal
!= TARGET_SIGNAL_0
)
2515 outbuf
= xstrprintf ("vCont;C%02x", siggnal
);
2517 outbuf
= xstrprintf ("vCont;c");
2521 /* Resume all threads, with preference for INFERIOR_PTID. */
2522 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2523 outbuf
= xstrprintf ("vCont;S%02x:%x;c", siggnal
,
2524 PIDGET (inferior_ptid
));
2526 outbuf
= xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid
));
2527 else if (siggnal
!= TARGET_SIGNAL_0
)
2528 outbuf
= xstrprintf ("vCont;C%02x:%x;c", siggnal
,
2529 PIDGET (inferior_ptid
));
2531 outbuf
= xstrprintf ("vCont;c");
2535 /* Scheduler locking; resume only PTID. */
2536 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2537 outbuf
= xstrprintf ("vCont;S%02x:%x", siggnal
, pid
);
2539 outbuf
= xstrprintf ("vCont;s:%x", pid
);
2540 else if (siggnal
!= TARGET_SIGNAL_0
)
2541 outbuf
= xstrprintf ("vCont;C%02x:%x", siggnal
, pid
);
2543 outbuf
= xstrprintf ("vCont;c:%x", pid
);
2546 gdb_assert (outbuf
&& strlen (outbuf
) < rs
->remote_packet_size
);
2547 make_cleanup (xfree
, outbuf
);
2551 do_cleanups (old_cleanup
);
2556 /* Tell the remote machine to resume. */
2558 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2560 static int last_sent_step
;
2563 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2565 struct remote_state
*rs
= get_remote_state ();
2566 char *buf
= alloca (rs
->remote_packet_size
);
2567 int pid
= PIDGET (ptid
);
2570 last_sent_signal
= siggnal
;
2571 last_sent_step
= step
;
2573 /* A hook for when we need to do something at the last moment before
2575 if (deprecated_target_resume_hook
)
2576 (*deprecated_target_resume_hook
) ();
2578 /* The vCont packet doesn't need to specify threads via Hc. */
2579 if (remote_vcont_resume (ptid
, step
, siggnal
))
2582 /* All other supported resume packets do use Hc, so call set_thread. */
2584 set_thread (0, 0); /* Run any thread. */
2586 set_thread (pid
, 0); /* Run this thread. */
2588 if (siggnal
!= TARGET_SIGNAL_0
)
2590 buf
[0] = step
? 'S' : 'C';
2591 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2592 buf
[2] = tohex (((int) siggnal
) & 0xf);
2596 strcpy (buf
, step
? "s" : "c");
2601 /* Same as remote_resume, but with async support. */
2603 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2605 remote_resume (ptid
, step
, siggnal
);
2607 /* We are about to start executing the inferior, let's register it
2608 with the event loop. NOTE: this is the one place where all the
2609 execution commands end up. We could alternatively do this in each
2610 of the execution commands in infcmd.c. */
2611 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2612 into infcmd.c in order to allow inferior function calls to work
2613 NOT asynchronously. */
2614 if (target_can_async_p ())
2615 target_async (inferior_event_handler
, 0);
2616 /* Tell the world that the target is now executing. */
2617 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2618 this? Instead, should the client of target just assume (for
2619 async targets) that the target is going to start executing? Is
2620 this information already found in the continuation block? */
2621 if (target_is_async_p ())
2622 target_executing
= 1;
2626 /* Set up the signal handler for SIGINT, while the target is
2627 executing, ovewriting the 'regular' SIGINT signal handler. */
2629 initialize_sigint_signal_handler (void)
2631 sigint_remote_token
=
2632 create_async_signal_handler (async_remote_interrupt
, NULL
);
2633 signal (SIGINT
, handle_remote_sigint
);
2636 /* Signal handler for SIGINT, while the target is executing. */
2638 handle_remote_sigint (int sig
)
2640 signal (sig
, handle_remote_sigint_twice
);
2641 sigint_remote_twice_token
=
2642 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2643 mark_async_signal_handler_wrapper (sigint_remote_token
);
2646 /* Signal handler for SIGINT, installed after SIGINT has already been
2647 sent once. It will take effect the second time that the user sends
2650 handle_remote_sigint_twice (int sig
)
2652 signal (sig
, handle_sigint
);
2653 sigint_remote_twice_token
=
2654 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2655 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2658 /* Perform the real interruption of the target execution, in response
2661 async_remote_interrupt (gdb_client_data arg
)
2664 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2669 /* Perform interrupt, if the first attempt did not succeed. Just give
2670 up on the target alltogether. */
2672 async_remote_interrupt_twice (gdb_client_data arg
)
2675 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2676 /* Do something only if the target was not killed by the previous
2678 if (target_executing
)
2681 signal (SIGINT
, handle_remote_sigint
);
2685 /* Reinstall the usual SIGINT handlers, after the target has
2688 cleanup_sigint_signal_handler (void *dummy
)
2690 signal (SIGINT
, handle_sigint
);
2691 if (sigint_remote_twice_token
)
2692 delete_async_signal_handler ((struct async_signal_handler
**)
2693 &sigint_remote_twice_token
);
2694 if (sigint_remote_token
)
2695 delete_async_signal_handler ((struct async_signal_handler
**)
2696 &sigint_remote_token
);
2699 /* Send ^C to target to halt it. Target will respond, and send us a
2701 static void (*ofunc
) (int);
2703 /* The command line interface's stop routine. This function is installed
2704 as a signal handler for SIGINT. The first time a user requests a
2705 stop, we call remote_stop to send a break or ^C. If there is no
2706 response from the target (it didn't stop when the user requested it),
2707 we ask the user if he'd like to detach from the target. */
2709 remote_interrupt (int signo
)
2711 /* If this doesn't work, try more severe steps. */
2712 signal (signo
, remote_interrupt_twice
);
2715 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2720 /* The user typed ^C twice. */
2723 remote_interrupt_twice (int signo
)
2725 signal (signo
, ofunc
);
2727 signal (signo
, remote_interrupt
);
2730 /* This is the generic stop called via the target vector. When a target
2731 interrupt is requested, either by the command line or the GUI, we
2732 will eventually end up here. */
2736 /* Send a break or a ^C, depending on user preference. */
2738 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2741 serial_send_break (remote_desc
);
2743 serial_write (remote_desc
, "\003", 1);
2746 /* Ask the user what to do when an interrupt is received. */
2749 interrupt_query (void)
2751 target_terminal_ours ();
2753 if (query ("Interrupted while waiting for the program.\n\
2754 Give up (and stop debugging it)? "))
2756 target_mourn_inferior ();
2757 deprecated_throw_reason (RETURN_QUIT
);
2760 target_terminal_inferior ();
2763 /* Enable/disable target terminal ownership. Most targets can use
2764 terminal groups to control terminal ownership. Remote targets are
2765 different in that explicit transfer of ownership to/from GDB/target
2769 remote_async_terminal_inferior (void)
2771 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2772 sync_execution here. This function should only be called when
2773 GDB is resuming the inferior in the forground. A background
2774 resume (``run&'') should leave GDB in control of the terminal and
2775 consequently should not call this code. */
2776 if (!sync_execution
)
2778 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2779 calls target_terminal_*() idenpotent. The event-loop GDB talking
2780 to an asynchronous target with a synchronous command calls this
2781 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2782 stops trying to transfer the terminal to the target when it
2783 shouldn't this guard can go away. */
2784 if (!remote_async_terminal_ours_p
)
2786 delete_file_handler (input_fd
);
2787 remote_async_terminal_ours_p
= 0;
2788 initialize_sigint_signal_handler ();
2789 /* NOTE: At this point we could also register our selves as the
2790 recipient of all input. Any characters typed could then be
2791 passed on down to the target. */
2795 remote_async_terminal_ours (void)
2797 /* See FIXME in remote_async_terminal_inferior. */
2798 if (!sync_execution
)
2800 /* See FIXME in remote_async_terminal_inferior. */
2801 if (remote_async_terminal_ours_p
)
2803 cleanup_sigint_signal_handler (NULL
);
2804 add_file_handler (input_fd
, stdin_event_handler
, 0);
2805 remote_async_terminal_ours_p
= 1;
2808 /* If nonzero, ignore the next kill. */
2813 remote_console_output (char *msg
)
2817 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2820 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2823 fputs_unfiltered (tb
, gdb_stdtarg
);
2825 gdb_flush (gdb_stdtarg
);
2828 /* Wait until the remote machine stops, then return,
2829 storing status in STATUS just as `wait' would.
2830 Returns "pid", which in the case of a multi-threaded
2831 remote OS, is the thread-id. */
2834 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2836 struct remote_state
*rs
= get_remote_state ();
2837 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2838 ULONGEST thread_num
= -1;
2841 status
->kind
= TARGET_WAITKIND_EXITED
;
2842 status
->value
.integer
= 0;
2848 ofunc
= signal (SIGINT
, remote_interrupt
);
2849 getpkt (buf
, (rs
->remote_packet_size
), 1);
2850 signal (SIGINT
, ofunc
);
2852 /* This is a hook for when we need to do something (perhaps the
2853 collection of trace data) every time the target stops. */
2854 if (deprecated_target_wait_loop_hook
)
2855 (*deprecated_target_wait_loop_hook
) ();
2857 remote_stopped_by_watchpoint_p
= 0;
2861 case 'E': /* Error of some sort. */
2862 warning (_("Remote failure reply: %s"), buf
);
2864 case 'F': /* File-I/O request. */
2865 remote_fileio_request (buf
);
2867 case 'T': /* Status with PC, SP, FP, ... */
2870 char regs
[MAX_REGISTER_SIZE
];
2872 /* Expedited reply, containing Signal, {regno, reg} repeat. */
2873 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2875 n... = register number
2876 r... = register contents
2878 p
= &buf
[3]; /* after Txx */
2887 /* If the packet contains a register number save it in
2888 pnum and set p1 to point to the character following
2889 it. Otherwise p1 points to p. */
2891 /* If this packet is an awatch packet, don't parse the
2892 'a' as a register number. */
2894 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
2896 /* Read the ``P'' register number. */
2897 pnum
= strtol (p
, &p_temp
, 16);
2898 p1
= (unsigned char *) p_temp
;
2903 if (p1
== p
) /* No register number present here. */
2905 p1
= (unsigned char *) strchr (p
, ':');
2907 warning (_("Malformed packet(a) (missing colon): %s\n\
2910 if (strncmp (p
, "thread", p1
- p
) == 0)
2912 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2913 record_currthread (thread_num
);
2914 p
= (unsigned char *) p_temp
;
2916 else if ((strncmp (p
, "watch", p1
- p
) == 0)
2917 || (strncmp (p
, "rwatch", p1
- p
) == 0)
2918 || (strncmp (p
, "awatch", p1
- p
) == 0))
2920 remote_stopped_by_watchpoint_p
= 1;
2921 p
= unpack_varlen_hex (++p1
, &addr
);
2922 remote_watch_data_address
= (CORE_ADDR
)addr
;
2926 /* Silently skip unknown optional info. */
2927 p_temp
= strchr (p1
+ 1, ';');
2929 p
= (unsigned char *) p_temp
;
2934 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
2938 error (_("Malformed packet(b) (missing colon): %s\n\
2943 error (_("Remote sent bad register number %s: %s\n\
2945 phex_nz (pnum
, 0), p
, buf
);
2947 fieldsize
= hex2bin (p
, regs
,
2948 register_size (current_gdbarch
,
2951 if (fieldsize
< register_size (current_gdbarch
,
2953 warning (_("Remote reply is too short: %s"), buf
);
2954 regcache_raw_supply (current_regcache
,
2959 error (_("Remote register badly formatted: %s\nhere: %s"),
2964 case 'S': /* Old style status, just signal only. */
2965 status
->kind
= TARGET_WAITKIND_STOPPED
;
2966 status
->value
.sig
= (enum target_signal
)
2967 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2971 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2972 record_currthread (thread_num
);
2975 case 'W': /* Target exited. */
2977 /* The remote process exited. */
2978 status
->kind
= TARGET_WAITKIND_EXITED
;
2979 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2983 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2984 status
->value
.sig
= (enum target_signal
)
2985 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2989 case 'O': /* Console output. */
2990 remote_console_output (buf
+ 1);
2993 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2995 /* Zero length reply means that we tried 'S' or 'C' and
2996 the remote system doesn't support it. */
2997 target_terminal_ours_for_output ();
2999 ("Can't send signals to this remote system. %s not sent.\n",
3000 target_signal_to_name (last_sent_signal
));
3001 last_sent_signal
= TARGET_SIGNAL_0
;
3002 target_terminal_inferior ();
3004 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3005 putpkt ((char *) buf
);
3008 /* else fallthrough */
3010 warning (_("Invalid remote reply: %s"), buf
);
3015 if (thread_num
!= -1)
3017 return pid_to_ptid (thread_num
);
3019 return inferior_ptid
;
3022 /* Async version of remote_wait. */
3024 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3026 struct remote_state
*rs
= get_remote_state ();
3027 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3028 ULONGEST thread_num
= -1;
3031 status
->kind
= TARGET_WAITKIND_EXITED
;
3032 status
->value
.integer
= 0;
3034 remote_stopped_by_watchpoint_p
= 0;
3040 if (!target_is_async_p ())
3041 ofunc
= signal (SIGINT
, remote_interrupt
);
3042 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3043 _never_ wait for ever -> test on target_is_async_p().
3044 However, before we do that we need to ensure that the caller
3045 knows how to take the target into/out of async mode. */
3046 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3047 if (!target_is_async_p ())
3048 signal (SIGINT
, ofunc
);
3050 /* This is a hook for when we need to do something (perhaps the
3051 collection of trace data) every time the target stops. */
3052 if (deprecated_target_wait_loop_hook
)
3053 (*deprecated_target_wait_loop_hook
) ();
3057 case 'E': /* Error of some sort. */
3058 warning (_("Remote failure reply: %s"), buf
);
3060 case 'F': /* File-I/O request. */
3061 remote_fileio_request (buf
);
3063 case 'T': /* Status with PC, SP, FP, ... */
3066 char regs
[MAX_REGISTER_SIZE
];
3068 /* Expedited reply, containing Signal, {regno, reg} repeat. */
3069 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3071 n... = register number
3072 r... = register contents
3074 p
= &buf
[3]; /* after Txx */
3083 /* If the packet contains a register number, save it
3084 in pnum and set p1 to point to the character
3085 following it. Otherwise p1 points to p. */
3087 /* If this packet is an awatch packet, don't parse the 'a'
3088 as a register number. */
3090 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3092 /* Read the register number. */
3093 pnum
= strtol (p
, &p_temp
, 16);
3094 p1
= (unsigned char *) p_temp
;
3099 if (p1
== p
) /* No register number present here. */
3101 p1
= (unsigned char *) strchr (p
, ':');
3103 error (_("Malformed packet(a) (missing colon): %s\n\
3106 if (strncmp (p
, "thread", p1
- p
) == 0)
3108 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3109 record_currthread (thread_num
);
3110 p
= (unsigned char *) p_temp
;
3112 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3113 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3114 || (strncmp (p
, "awatch", p1
- p
) == 0))
3116 remote_stopped_by_watchpoint_p
= 1;
3117 p
= unpack_varlen_hex (++p1
, &addr
);
3118 remote_watch_data_address
= (CORE_ADDR
)addr
;
3122 /* Silently skip unknown optional info. */
3123 p_temp
= (unsigned char *) strchr (p1
+ 1, ';');
3131 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3134 error (_("Malformed packet(b) (missing colon): %s\n\
3139 error (_("Remote sent bad register number %ld: %s\n\
3143 fieldsize
= hex2bin (p
, regs
,
3144 register_size (current_gdbarch
,
3147 if (fieldsize
< register_size (current_gdbarch
,
3149 warning (_("Remote reply is too short: %s"), buf
);
3150 regcache_raw_supply (current_regcache
, reg
->regnum
, regs
);
3154 error (_("Remote register badly formatted: %s\nhere: %s"),
3159 case 'S': /* Old style status, just signal only. */
3160 status
->kind
= TARGET_WAITKIND_STOPPED
;
3161 status
->value
.sig
= (enum target_signal
)
3162 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3166 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3167 record_currthread (thread_num
);
3170 case 'W': /* Target exited. */
3172 /* The remote process exited. */
3173 status
->kind
= TARGET_WAITKIND_EXITED
;
3174 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3178 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3179 status
->value
.sig
= (enum target_signal
)
3180 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3184 case 'O': /* Console output. */
3185 remote_console_output (buf
+ 1);
3186 /* Return immediately to the event loop. The event loop will
3187 still be waiting on the inferior afterwards. */
3188 status
->kind
= TARGET_WAITKIND_IGNORE
;
3191 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3193 /* Zero length reply means that we tried 'S' or 'C' and
3194 the remote system doesn't support it. */
3195 target_terminal_ours_for_output ();
3197 ("Can't send signals to this remote system. %s not sent.\n",
3198 target_signal_to_name (last_sent_signal
));
3199 last_sent_signal
= TARGET_SIGNAL_0
;
3200 target_terminal_inferior ();
3202 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3203 putpkt ((char *) buf
);
3206 /* else fallthrough */
3208 warning (_("Invalid remote reply: %s"), buf
);
3213 if (thread_num
!= -1)
3215 return pid_to_ptid (thread_num
);
3217 return inferior_ptid
;
3220 /* Number of bytes of registers this stub implements. */
3222 static int register_bytes_found
;
3224 /* Read the remote registers into the block REGS. */
3225 /* Currently we just read all the registers, so we don't use regnum. */
3228 fetch_register_using_p (int regnum
)
3230 struct remote_state
*rs
= get_remote_state ();
3231 char *buf
= alloca (rs
->remote_packet_size
), *p
;
3232 char regp
[MAX_REGISTER_SIZE
];
3237 p
+= hexnumstr (p
, regnum
);
3239 remote_send (buf
, rs
->remote_packet_size
);
3241 /* If the stub didn't recognize the packet, or if we got an error,
3243 if (buf
[0] == '\0' || buf
[0] == 'E')
3246 /* If this register is unfetchable, tell the regcache. */
3249 regcache_raw_supply (current_regcache
, regnum
, NULL
);
3250 set_register_cached (regnum
, -1);
3254 /* Otherwise, parse and supply the value. */
3261 error (_("fetch_register_using_p: early buf termination"));
3265 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3268 regcache_raw_supply (current_regcache
, regnum
, regp
);
3273 remote_fetch_registers (int regnum
)
3275 struct remote_state
*rs
= get_remote_state ();
3276 char *buf
= alloca (rs
->remote_packet_size
);
3279 char *regs
= alloca (rs
->sizeof_g_packet
);
3281 set_thread (PIDGET (inferior_ptid
), 1);
3285 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3286 gdb_assert (reg
!= NULL
);
3287 if (!reg
->in_g_packet
)
3288 internal_error (__FILE__
, __LINE__
,
3289 _("Attempt to fetch a non G-packet register when this "
3290 "remote.c does not support the p-packet."));
3292 switch (remote_protocol_p
.support
)
3294 case PACKET_DISABLE
:
3297 if (fetch_register_using_p (regnum
))
3300 error (_("Protocol error: p packet not recognized by stub"));
3301 case PACKET_SUPPORT_UNKNOWN
:
3302 if (fetch_register_using_p (regnum
))
3304 /* The stub recognized the 'p' packet. Remember this. */
3305 remote_protocol_p
.support
= PACKET_ENABLE
;
3310 /* The stub does not support the 'P' packet. Use 'G'
3311 instead, and don't try using 'P' in the future (it
3312 will just waste our time). */
3313 remote_protocol_p
.support
= PACKET_DISABLE
;
3319 remote_send (buf
, (rs
->remote_packet_size
));
3321 /* Save the size of the packet sent to us by the target. Its used
3322 as a heuristic when determining the max size of packets that the
3323 target can safely receive. */
3324 if ((rs
->actual_register_packet_size
) == 0)
3325 (rs
->actual_register_packet_size
) = strlen (buf
);
3327 /* Unimplemented registers read as all bits zero. */
3328 memset (regs
, 0, rs
->sizeof_g_packet
);
3330 /* We can get out of synch in various cases. If the first character
3331 in the buffer is not a hex character, assume that has happened
3332 and try to fetch another packet to read. */
3333 while ((buf
[0] < '0' || buf
[0] > '9')
3334 && (buf
[0] < 'a' || buf
[0] > 'f')
3335 && buf
[0] != 'x') /* New: unavailable register value. */
3338 fprintf_unfiltered (gdb_stdlog
,
3339 "Bad register packet; fetching a new packet\n");
3340 getpkt (buf
, (rs
->remote_packet_size
), 0);
3343 /* Reply describes registers byte by byte, each byte encoded as two
3344 hex characters. Suck them all up, then supply them to the
3345 register cacheing/storage mechanism. */
3348 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3354 warning (_("Remote reply is of odd length: %s"), buf
);
3355 /* Don't change register_bytes_found in this case, and don't
3356 print a second warning. */
3359 if (p
[0] == 'x' && p
[1] == 'x')
3360 regs
[i
] = 0; /* 'x' */
3362 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3366 if (i
!= register_bytes_found
)
3368 register_bytes_found
= i
;
3369 if (REGISTER_BYTES_OK_P ()
3370 && !REGISTER_BYTES_OK (i
))
3371 warning (_("Remote reply is too short: %s"), buf
);
3377 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3379 struct packet_reg
*r
= &rs
->regs
[i
];
3382 if (r
->offset
* 2 >= strlen (buf
))
3383 /* A short packet that didn't include the register's
3384 value, this implies that the register is zero (and
3385 not that the register is unavailable). Supply that
3387 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3388 else if (buf
[r
->offset
* 2] == 'x')
3390 gdb_assert (r
->offset
* 2 < strlen (buf
));
3391 /* The register isn't available, mark it as such (at
3392 the same time setting the value to zero). */
3393 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3394 set_register_cached (i
, -1);
3397 regcache_raw_supply (current_regcache
, r
->regnum
,
3404 /* Prepare to store registers. Since we may send them all (using a
3405 'G' request), we have to read out the ones we don't want to change
3409 remote_prepare_to_store (void)
3411 struct remote_state
*rs
= get_remote_state ();
3413 char buf
[MAX_REGISTER_SIZE
];
3415 /* Make sure the entire registers array is valid. */
3416 switch (remote_protocol_P
.support
)
3418 case PACKET_DISABLE
:
3419 case PACKET_SUPPORT_UNKNOWN
:
3420 /* Make sure all the necessary registers are cached. */
3421 for (i
= 0; i
< NUM_REGS
; i
++)
3422 if (rs
->regs
[i
].in_g_packet
)
3423 regcache_raw_read (current_regcache
, rs
->regs
[i
].regnum
, buf
);
3430 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3431 packet was not recognized. */
3434 store_register_using_P (int regnum
)
3436 struct remote_state
*rs
= get_remote_state ();
3437 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3438 /* Try storing a single register. */
3439 char *buf
= alloca (rs
->remote_packet_size
);
3440 char regp
[MAX_REGISTER_SIZE
];
3444 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3445 p
= buf
+ strlen (buf
);
3446 regcache_raw_collect (current_regcache
, reg
->regnum
, regp
);
3447 bin2hex (regp
, p
, register_size (current_gdbarch
, reg
->regnum
));
3448 remote_send (buf
, rs
->remote_packet_size
);
3450 return buf
[0] != '\0';
3454 /* Store register REGNUM, or all registers if REGNUM == -1, from the
3455 contents of the register cache buffer. FIXME: ignores errors. */
3458 remote_store_registers (int regnum
)
3460 struct remote_state
*rs
= get_remote_state ();
3466 set_thread (PIDGET (inferior_ptid
), 1);
3470 switch (remote_protocol_P
.support
)
3472 case PACKET_DISABLE
:
3475 if (store_register_using_P (regnum
))
3478 error (_("Protocol error: P packet not recognized by stub"));
3479 case PACKET_SUPPORT_UNKNOWN
:
3480 if (store_register_using_P (regnum
))
3482 /* The stub recognized the 'P' packet. Remember this. */
3483 remote_protocol_P
.support
= PACKET_ENABLE
;
3488 /* The stub does not support the 'P' packet. Use 'G'
3489 instead, and don't try using 'P' in the future (it
3490 will just waste our time). */
3491 remote_protocol_P
.support
= PACKET_DISABLE
;
3497 /* Extract all the registers in the regcache copying them into a
3501 regs
= alloca (rs
->sizeof_g_packet
);
3502 memset (regs
, rs
->sizeof_g_packet
, 0);
3503 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3505 struct packet_reg
*r
= &rs
->regs
[i
];
3507 regcache_raw_collect (current_regcache
, r
->regnum
, regs
+ r
->offset
);
3511 /* Command describes registers byte by byte,
3512 each byte encoded as two hex characters. */
3513 buf
= alloca (rs
->remote_packet_size
);
3516 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3517 bin2hex (regs
, p
, register_bytes_found
);
3518 remote_send (buf
, (rs
->remote_packet_size
));
3522 /* Return the number of hex digits in num. */
3525 hexnumlen (ULONGEST num
)
3529 for (i
= 0; num
!= 0; i
++)
3535 /* Set BUF to the minimum number of hex digits representing NUM. */
3538 hexnumstr (char *buf
, ULONGEST num
)
3540 int len
= hexnumlen (num
);
3541 return hexnumnstr (buf
, num
, len
);
3545 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3548 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3554 for (i
= width
- 1; i
>= 0; i
--)
3556 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3563 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3566 remote_address_masked (CORE_ADDR addr
)
3568 if (remote_address_size
> 0
3569 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3571 /* Only create a mask when that mask can safely be constructed
3572 in a ULONGEST variable. */
3574 mask
= (mask
<< remote_address_size
) - 1;
3580 /* Determine whether the remote target supports binary downloading.
3581 This is accomplished by sending a no-op memory write of zero length
3582 to the target at the specified address. It does not suffice to send
3583 the whole packet, since many stubs strip the eighth bit and
3584 subsequently compute a wrong checksum, which causes real havoc with
3587 NOTE: This can still lose if the serial line is not eight-bit
3588 clean. In cases like this, the user should clear "remote
3592 check_binary_download (CORE_ADDR addr
)
3594 struct remote_state
*rs
= get_remote_state ();
3595 switch (remote_protocol_binary_download
.support
)
3597 case PACKET_DISABLE
:
3601 case PACKET_SUPPORT_UNKNOWN
:
3603 char *buf
= alloca (rs
->remote_packet_size
);
3608 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3610 p
+= hexnumstr (p
, (ULONGEST
) 0);
3614 putpkt_binary (buf
, (int) (p
- buf
));
3615 getpkt (buf
, (rs
->remote_packet_size
), 0);
3620 fprintf_unfiltered (gdb_stdlog
,
3621 "binary downloading NOT suppported by target\n");
3622 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3627 fprintf_unfiltered (gdb_stdlog
,
3628 "binary downloading suppported by target\n");
3629 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3636 /* Write memory data directly to the remote machine.
3637 This does not inform the data cache; the data cache uses this.
3638 MEMADDR is the address in the remote memory space.
3639 MYADDR is the address of the buffer in our space.
3640 LEN is the number of bytes.
3642 Returns number of bytes transferred, or 0 (setting errno) for
3643 error. Only transfer a single packet. */
3646 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3650 unsigned char *plen
;
3656 unsigned char *payload_start
;
3658 /* Verify that the target can support a binary download. */
3659 check_binary_download (memaddr
);
3661 /* Compute the size, and then allocate space for the largest
3662 possible packet. Include space for an extra trailing NULL. */
3663 sizeof_buf
= get_memory_write_packet_size () + 1;
3664 buf
= alloca (sizeof_buf
);
3666 /* Compute the size of the actual payload by subtracting out the
3667 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
3668 payload_size
= (get_memory_write_packet_size () - (strlen ("$M,:#NN")
3669 + hexnumlen (memaddr
)
3670 + hexnumlen (len
)));
3672 /* Construct the packet header: "[MX]<memaddr>,<len>:". */
3674 /* Append "[XM]". Compute a best guess of the number of bytes
3675 actually transfered. */
3677 switch (remote_protocol_binary_download
.support
)
3681 /* Best guess at number of bytes that will fit. */
3682 todo
= min (len
, payload_size
);
3684 case PACKET_DISABLE
:
3686 /* Num bytes that will fit. */
3687 todo
= min (len
, payload_size
/ 2);
3689 case PACKET_SUPPORT_UNKNOWN
:
3690 internal_error (__FILE__
, __LINE__
,
3691 _("remote_write_bytes: bad internal state"));
3693 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3696 /* Append "<memaddr>". */
3697 memaddr
= remote_address_masked (memaddr
);
3698 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3703 /* Append <len>. Retain the location/size of <len>. It may need to
3704 be adjusted once the packet body has been created. */
3706 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3713 /* Append the packet body. */
3715 switch (remote_protocol_binary_download
.support
)
3718 /* Binary mode. Send target system values byte by byte, in
3719 increasing byte addresses. Only escape certain critical
3722 (nr_bytes
< todo
) && (p
- payload_start
) < payload_size
;
3725 switch (myaddr
[nr_bytes
] & 0xff)
3730 /* These must be escaped. */
3732 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3735 *p
++ = myaddr
[nr_bytes
] & 0xff;
3739 if (nr_bytes
< todo
)
3741 /* Escape chars have filled up the buffer prematurely,
3742 and we have actually sent fewer bytes than planned.
3743 Fix-up the length field of the packet. Use the same
3744 number of characters as before. */
3745 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3746 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3749 case PACKET_DISABLE
:
3750 /* Normal mode: Send target system values byte by byte, in
3751 increasing byte addresses. Each byte is encoded as a two hex
3753 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3756 case PACKET_SUPPORT_UNKNOWN
:
3757 internal_error (__FILE__
, __LINE__
,
3758 _("remote_write_bytes: bad internal state"));
3760 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3763 putpkt_binary (buf
, (int) (p
- buf
));
3764 getpkt (buf
, sizeof_buf
, 0);
3768 /* There is no correspondance between what the remote protocol
3769 uses for errors and errno codes. We would like a cleaner way
3770 of representing errors (big enough to include errno codes,
3771 bfd_error codes, and others). But for now just return EIO. */
3776 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
3777 fewer bytes than we'd planned. */
3781 /* Read memory data directly from the remote machine.
3782 This does not use the data cache; the data cache uses this.
3783 MEMADDR is the address in the remote memory space.
3784 MYADDR is the address of the buffer in our space.
3785 LEN is the number of bytes.
3787 Returns number of bytes transferred, or 0 for error. */
3789 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3790 remote targets) shouldn't attempt to read the entire buffer.
3791 Instead it should read a single packet worth of data and then
3792 return the byte size of that packet to the caller. The caller (its
3793 caller and its callers caller ;-) already contains code for
3794 handling partial reads. */
3797 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3800 int max_buf_size
; /* Max size of packet output buffer. */
3804 /* Create a buffer big enough for this packet. */
3805 max_buf_size
= get_memory_read_packet_size ();
3806 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NULL. */
3807 buf
= alloca (sizeof_buf
);
3816 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3818 /* construct "m"<memaddr>","<len>" */
3819 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3820 memaddr
= remote_address_masked (memaddr
);
3823 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3825 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3829 getpkt (buf
, sizeof_buf
, 0);
3832 && isxdigit (buf
[1]) && isxdigit (buf
[2])
3835 /* There is no correspondance between what the remote
3836 protocol uses for errors and errno codes. We would like
3837 a cleaner way of representing errors (big enough to
3838 include errno codes, bfd_error codes, and others). But
3839 for now just return EIO. */
3844 /* Reply describes memory byte by byte,
3845 each byte encoded as two hex characters. */
3848 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3850 /* Reply is short. This means that we were able to read
3851 only part of what we wanted to. */
3852 return i
+ (origlen
- len
);
3861 /* Read or write LEN bytes from inferior memory at MEMADDR,
3862 transferring to or from debugger address BUFFER. Write to inferior
3863 if SHOULD_WRITE is nonzero. Returns length of data written or
3864 read; 0 for error. TARGET is unused. */
3867 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3868 int should_write
, struct mem_attrib
*attrib
,
3869 struct target_ops
*target
)
3871 CORE_ADDR targ_addr
;
3875 /* Should this be the selected frame? */
3876 gdbarch_remote_translate_xfer_address (current_gdbarch
,
3879 &targ_addr
, &targ_len
);
3884 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3886 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3892 remote_files_info (struct target_ops
*ignore
)
3894 puts_filtered ("Debugging a target over a serial line.\n");
3897 /* Stuff for dealing with the packets which are part of this protocol.
3898 See comment at top of file for details. */
3900 /* Read a single character from the remote end, masking it down to 7
3904 readchar (int timeout
)
3908 ch
= serial_readchar (remote_desc
, timeout
);
3913 switch ((enum serial_rc
) ch
)
3916 target_mourn_inferior ();
3917 error (_("Remote connection closed"));
3920 perror_with_name (_("Remote communication error"));
3922 case SERIAL_TIMEOUT
:
3928 /* Send the command in BUF to the remote machine, and read the reply
3929 into BUF. Report an error if we get an error reply. */
3932 remote_send (char *buf
,
3936 getpkt (buf
, sizeof_buf
, 0);
3939 error (_("Remote failure reply: %s"), buf
);
3942 /* Display a null-terminated packet on stdout, for debugging, using C
3946 print_packet (char *buf
)
3948 puts_filtered ("\"");
3949 fputstr_filtered (buf
, '"', gdb_stdout
);
3950 puts_filtered ("\"");
3956 return putpkt_binary (buf
, strlen (buf
));
3959 /* Send a packet to the remote machine, with error checking. The data
3960 of the packet is in BUF. The string in BUF can be at most
3961 (rs->remote_packet_size) - 5 to account for the $, # and checksum,
3962 and for a possible /0 if we are debugging (remote_debug) and want
3963 to print the sent packet as a string. */
3966 putpkt_binary (char *buf
, int cnt
)
3968 struct remote_state
*rs
= get_remote_state ();
3970 unsigned char csum
= 0;
3971 char *buf2
= alloca (cnt
+ 6);
3972 long sizeof_junkbuf
= (rs
->remote_packet_size
);
3973 char *junkbuf
= alloca (sizeof_junkbuf
);
3979 /* Copy the packet into buffer BUF2, encapsulating it
3980 and giving it a checksum. */
3985 for (i
= 0; i
< cnt
; i
++)
3991 *p
++ = tohex ((csum
>> 4) & 0xf);
3992 *p
++ = tohex (csum
& 0xf);
3994 /* Send it over and over until we get a positive ack. */
3998 int started_error_output
= 0;
4003 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4004 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4005 fprintf_unfiltered (gdb_stdlog
, "...");
4006 gdb_flush (gdb_stdlog
);
4008 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4009 perror_with_name (_("putpkt: write failed"));
4011 /* Read until either a timeout occurs (-2) or '+' is read. */
4014 ch
= readchar (remote_timeout
);
4022 case SERIAL_TIMEOUT
:
4024 if (started_error_output
)
4026 putchar_unfiltered ('\n');
4027 started_error_output
= 0;
4036 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4040 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4041 case SERIAL_TIMEOUT
:
4045 break; /* Retransmit buffer. */
4049 fprintf_unfiltered (gdb_stdlog
,
4050 "Packet instead of Ack, ignoring it\n");
4051 /* It's probably an old response sent because an ACK
4052 was lost. Gobble up the packet and ack it so it
4053 doesn't get retransmitted when we resend this
4055 read_frame (junkbuf
, sizeof_junkbuf
);
4056 serial_write (remote_desc
, "+", 1);
4057 continue; /* Now, go look for +. */
4062 if (!started_error_output
)
4064 started_error_output
= 1;
4065 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4067 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4071 break; /* Here to retransmit. */
4075 /* This is wrong. If doing a long backtrace, the user should be
4076 able to get out next time we call QUIT, without anything as
4077 violent as interrupt_query. If we want to provide a way out of
4078 here without getting to the next QUIT, it should be based on
4079 hitting ^C twice as in remote_wait. */
4089 /* Come here after finding the start of the frame. Collect the rest
4090 into BUF, verifying the checksum, length, and handling run-length
4091 compression. No more than sizeof_buf-1 characters are read so that
4092 the buffer can be NUL terminated.
4094 Returns -1 on error, number of characters in buffer (ignoring the
4095 trailing NULL) on success. (could be extended to return one of the
4096 SERIAL status indications). */
4099 read_frame (char *buf
,
4111 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NULL. */
4112 c
= readchar (remote_timeout
);
4115 case SERIAL_TIMEOUT
:
4117 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4121 fputs_filtered ("Saw new packet start in middle of old one\n",
4123 return -1; /* Start a new packet, count retries. */
4126 unsigned char pktcsum
;
4132 check_0
= readchar (remote_timeout
);
4134 check_1
= readchar (remote_timeout
);
4136 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4139 fputs_filtered ("Timeout in checksum, retrying\n",
4143 else if (check_0
< 0 || check_1
< 0)
4146 fputs_filtered ("Communication error in checksum\n",
4151 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4152 if (csum
== pktcsum
)
4157 fprintf_filtered (gdb_stdlog
,
4158 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4160 fputs_filtered (buf
, gdb_stdlog
);
4161 fputs_filtered ("\n", gdb_stdlog
);
4163 /* Number of characters in buffer ignoring trailing
4167 case '*': /* Run length encoding. */
4172 c
= readchar (remote_timeout
);
4174 repeat
= c
- ' ' + 3; /* Compute repeat count. */
4176 /* The character before ``*'' is repeated. */
4178 if (repeat
> 0 && repeat
<= 255
4180 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4182 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4188 printf_filtered (_("Repeat count %d too large for buffer: "),
4190 puts_filtered (buf
);
4191 puts_filtered ("\n");
4195 if (bc
< sizeof_buf
- 1)
4203 puts_filtered ("Remote packet too long: ");
4204 puts_filtered (buf
);
4205 puts_filtered ("\n");
4212 /* Read a packet from the remote machine, with error checking, and
4213 store it in BUF. If FOREVER, wait forever rather than timing out;
4214 this is used (in synchronous mode) to wait for a target that is is
4215 executing user code to stop. */
4216 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4217 don't have to change all the calls to getpkt to deal with the
4218 return value, because at the moment I don't know what the right
4219 thing to do it for those. */
4227 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4231 /* Read a packet from the remote machine, with error checking, and
4232 store it in BUF. If FOREVER, wait forever rather than timing out;
4233 this is used (in synchronous mode) to wait for a target that is is
4234 executing user code to stop. If FOREVER == 0, this function is
4235 allowed to time out gracefully and return an indication of this to
4238 getpkt_sane (char *buf
,
4247 strcpy (buf
, "timeout");
4251 timeout
= watchdog
> 0 ? watchdog
: -1;
4255 timeout
= remote_timeout
;
4259 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4261 /* This can loop forever if the remote side sends us characters
4262 continuously, but if it pauses, we'll get a zero from
4263 readchar because of timeout. Then we'll count that as a
4266 /* Note that we will only wait forever prior to the start of a
4267 packet. After that, we expect characters to arrive at a
4268 brisk pace. They should show up within remote_timeout
4273 c
= readchar (timeout
);
4275 if (c
== SERIAL_TIMEOUT
)
4277 if (forever
) /* Watchdog went off? Kill the target. */
4280 target_mourn_inferior ();
4281 error (_("Watchdog has expired. Target detached."));
4284 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4290 /* We've found the start of a packet, now collect the data. */
4292 val
= read_frame (buf
, sizeof_buf
);
4298 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4299 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4300 fprintf_unfiltered (gdb_stdlog
, "\n");
4302 serial_write (remote_desc
, "+", 1);
4306 /* Try the whole thing again. */
4308 serial_write (remote_desc
, "-", 1);
4311 /* We have tried hard enough, and just can't receive the packet.
4314 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
4315 serial_write (remote_desc
, "+", 1);
4322 /* For some mysterious reason, wait_for_inferior calls kill instead of
4323 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4327 target_mourn_inferior ();
4331 /* Use catch_errors so the user can quit from gdb even when we aren't on
4332 speaking terms with the remote system. */
4333 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4335 /* Don't wait for it to die. I'm not really sure it matters whether
4336 we do or not. For the existing stubs, kill is a noop. */
4337 target_mourn_inferior ();
4340 /* Async version of remote_kill. */
4342 remote_async_kill (void)
4344 /* Unregister the file descriptor from the event loop. */
4345 if (target_is_async_p ())
4346 serial_async (remote_desc
, NULL
, 0);
4348 /* For some mysterious reason, wait_for_inferior calls kill instead of
4349 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4353 target_mourn_inferior ();
4357 /* Use catch_errors so the user can quit from gdb even when we
4358 aren't on speaking terms with the remote system. */
4359 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4361 /* Don't wait for it to die. I'm not really sure it matters whether
4362 we do or not. For the existing stubs, kill is a noop. */
4363 target_mourn_inferior ();
4369 remote_mourn_1 (&remote_ops
);
4373 remote_async_mourn (void)
4375 remote_mourn_1 (&remote_async_ops
);
4379 extended_remote_mourn (void)
4381 /* We do _not_ want to mourn the target like this; this will
4382 remove the extended remote target from the target stack,
4383 and the next time the user says "run" it'll fail.
4385 FIXME: What is the right thing to do here? */
4387 remote_mourn_1 (&extended_remote_ops
);
4391 /* Worker function for remote_mourn. */
4393 remote_mourn_1 (struct target_ops
*target
)
4395 unpush_target (target
);
4396 generic_mourn_inferior ();
4399 /* In the extended protocol we want to be able to do things like
4400 "run" and have them basically work as expected. So we need
4401 a special create_inferior function.
4403 FIXME: One day add support for changing the exec file
4404 we're debugging, arguments and an environment. */
4407 extended_remote_create_inferior (char *exec_file
, char *args
,
4408 char **env
, int from_tty
)
4410 /* Rip out the breakpoints; we'll reinsert them after restarting
4411 the remote server. */
4412 remove_breakpoints ();
4414 /* Now restart the remote server. */
4415 extended_remote_restart ();
4417 /* Now put the breakpoints back in. This way we're safe if the
4418 restart function works via a unix fork on the remote side. */
4419 insert_breakpoints ();
4421 /* Clean up from the last time we were running. */
4422 clear_proceed_status ();
4424 /* Let the remote process run. */
4425 proceed (-1, TARGET_SIGNAL_0
, 0);
4428 /* Async version of extended_remote_create_inferior. */
4430 extended_remote_async_create_inferior (char *exec_file
, char *args
,
4431 char **env
, int from_tty
)
4433 /* Rip out the breakpoints; we'll reinsert them after restarting
4434 the remote server. */
4435 remove_breakpoints ();
4437 /* If running asynchronously, register the target file descriptor
4438 with the event loop. */
4439 if (target_can_async_p ())
4440 target_async (inferior_event_handler
, 0);
4442 /* Now restart the remote server. */
4443 extended_remote_restart ();
4445 /* Now put the breakpoints back in. This way we're safe if the
4446 restart function works via a unix fork on the remote side. */
4447 insert_breakpoints ();
4449 /* Clean up from the last time we were running. */
4450 clear_proceed_status ();
4452 /* Let the remote process run. */
4453 proceed (-1, TARGET_SIGNAL_0
, 0);
4457 /* On some machines, e.g. 68k, we may use a different breakpoint
4458 instruction than other targets; in those use
4459 DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
4460 Also, bi-endian targets may define
4461 DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
4462 DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we
4463 just call the standard routines that are in mem-break.c. */
4465 /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator
4466 target should use an identical BREAKPOINT_FROM_PC. As for native,
4467 the ARCH-OS-tdep.c code can override the default. */
4469 #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
4470 #define DEPRECATED_REMOTE_BREAKPOINT
4473 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4475 /* If the target isn't bi-endian, just pretend it is. */
4476 #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
4477 #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4478 #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4481 static unsigned char big_break_insn
[] = DEPRECATED_BIG_REMOTE_BREAKPOINT
;
4482 static unsigned char little_break_insn
[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT
;
4484 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4486 /* Insert a breakpoint on targets that don't have any better
4487 breakpoint support. We read the contents of the target location
4488 and stash it, then overwrite it with a breakpoint instruction.
4489 ADDR is the target location in the target machine. CONTENTS_CACHE
4490 is a pointer to memory allocated for saving the target contents.
4491 It is guaranteed by the caller to be long enough to save the number
4492 of bytes returned by BREAKPOINT_FROM_PC. */
4495 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4497 struct remote_state
*rs
= get_remote_state ();
4498 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4503 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4504 If it succeeds, then set the support to PACKET_ENABLE. If it
4505 fails, and the user has explicitly requested the Z support then
4506 report an error, otherwise, mark it disabled and go on. */
4508 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4510 char *buf
= alloca (rs
->remote_packet_size
);
4513 addr
= remote_address_masked (addr
);
4517 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4518 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4519 sprintf (p
, ",%d", bp_size
);
4522 getpkt (buf
, (rs
->remote_packet_size
), 0);
4524 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4530 case PACKET_UNKNOWN
:
4535 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4536 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4540 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4541 val
= target_write_memory (addr
, (char *) big_break_insn
,
4542 sizeof big_break_insn
);
4544 val
= target_write_memory (addr
, (char *) little_break_insn
,
4545 sizeof little_break_insn
);
4550 return memory_insert_breakpoint (addr
, contents_cache
);
4551 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4555 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4557 struct remote_state
*rs
= get_remote_state ();
4560 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4562 char *buf
= alloca (rs
->remote_packet_size
);
4569 addr
= remote_address_masked (addr
);
4570 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4571 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4572 sprintf (p
, ",%d", bp_size
);
4575 getpkt (buf
, (rs
->remote_packet_size
), 0);
4577 return (buf
[0] == 'E');
4580 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4581 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4583 return memory_remove_breakpoint (addr
, contents_cache
);
4584 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4588 watchpoint_to_Z_packet (int type
)
4602 internal_error (__FILE__
, __LINE__
,
4603 _("hw_bp_to_z: bad watchpoint type %d"), type
);
4608 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4610 struct remote_state
*rs
= get_remote_state ();
4611 char *buf
= alloca (rs
->remote_packet_size
);
4613 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4615 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4616 error (_("Can't set hardware watchpoints without the '%s' (%s) packet."),
4617 remote_protocol_Z
[packet
].name
,
4618 remote_protocol_Z
[packet
].title
);
4620 sprintf (buf
, "Z%x,", packet
);
4621 p
= strchr (buf
, '\0');
4622 addr
= remote_address_masked (addr
);
4623 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4624 sprintf (p
, ",%x", len
);
4627 getpkt (buf
, (rs
->remote_packet_size
), 0);
4629 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4632 case PACKET_UNKNOWN
:
4637 internal_error (__FILE__
, __LINE__
,
4638 _("remote_insert_watchpoint: reached end of function"));
4643 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4645 struct remote_state
*rs
= get_remote_state ();
4646 char *buf
= alloca (rs
->remote_packet_size
);
4648 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4650 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4651 error (_("Can't clear hardware watchpoints without the '%s' (%s) packet."),
4652 remote_protocol_Z
[packet
].name
,
4653 remote_protocol_Z
[packet
].title
);
4655 sprintf (buf
, "z%x,", packet
);
4656 p
= strchr (buf
, '\0');
4657 addr
= remote_address_masked (addr
);
4658 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4659 sprintf (p
, ",%x", len
);
4661 getpkt (buf
, (rs
->remote_packet_size
), 0);
4663 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4666 case PACKET_UNKNOWN
:
4671 internal_error (__FILE__
, __LINE__
,
4672 _("remote_remove_watchpoint: reached end of function"));
4676 int remote_hw_watchpoint_limit
= -1;
4677 int remote_hw_breakpoint_limit
= -1;
4680 remote_check_watch_resources (int type
, int cnt
, int ot
)
4682 if (type
== bp_hardware_breakpoint
)
4684 if (remote_hw_breakpoint_limit
== 0)
4686 else if (remote_hw_breakpoint_limit
< 0)
4688 else if (cnt
<= remote_hw_breakpoint_limit
)
4693 if (remote_hw_watchpoint_limit
== 0)
4695 else if (remote_hw_watchpoint_limit
< 0)
4699 else if (cnt
<= remote_hw_watchpoint_limit
)
4706 remote_stopped_by_watchpoint (void)
4708 return remote_stopped_by_watchpoint_p
;
4711 extern int stepped_after_stopped_by_watchpoint
;
4714 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
4717 if (remote_stopped_by_watchpoint ()
4718 || stepped_after_stopped_by_watchpoint
)
4720 *addr_p
= remote_watch_data_address
;
4729 remote_insert_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4732 struct remote_state
*rs
= get_remote_state ();
4733 char *buf
= alloca (rs
->remote_packet_size
);
4736 /* The length field should be set to the size of a breakpoint
4739 BREAKPOINT_FROM_PC (&addr
, &len
);
4741 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4742 error (_("Can't set hardware breakpoint without the '%s' (%s) packet."),
4743 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4744 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4750 addr
= remote_address_masked (addr
);
4751 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4752 sprintf (p
, ",%x", len
);
4755 getpkt (buf
, (rs
->remote_packet_size
), 0);
4757 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4760 case PACKET_UNKNOWN
:
4765 internal_error (__FILE__
, __LINE__
,
4766 _("remote_insert_hw_breakpoint: reached end of function"));
4771 remote_remove_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4774 struct remote_state
*rs
= get_remote_state ();
4775 char *buf
= alloca (rs
->remote_packet_size
);
4778 /* The length field should be set to the size of a breakpoint
4781 BREAKPOINT_FROM_PC (&addr
, &len
);
4783 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4784 error (_("Can't clear hardware breakpoint without the '%s' (%s) packet."),
4785 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4786 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4792 addr
= remote_address_masked (addr
);
4793 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4794 sprintf (p
, ",%x", len
);
4797 getpkt (buf
, (rs
->remote_packet_size
), 0);
4799 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4802 case PACKET_UNKNOWN
:
4807 internal_error (__FILE__
, __LINE__
,
4808 _("remote_remove_hw_breakpoint: reached end of function"));
4811 /* Some targets are only capable of doing downloads, and afterwards
4812 they switch to the remote serial protocol. This function provides
4813 a clean way to get from the download target to the remote target.
4814 It's basically just a wrapper so that we don't have to expose any
4815 of the internal workings of remote.c.
4817 Prior to calling this routine, you should shutdown the current
4818 target code, else you will get the "A program is being debugged
4819 already..." message. Usually a call to pop_target() suffices. */
4822 push_remote_target (char *name
, int from_tty
)
4824 printf_filtered (_("Switching to remote protocol\n"));
4825 remote_open (name
, from_tty
);
4828 /* Table used by the crc32 function to calcuate the checksum. */
4830 static unsigned long crc32_table
[256] =
4833 static unsigned long
4834 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4836 if (!crc32_table
[1])
4838 /* Initialize the CRC table and the decoding table. */
4842 for (i
= 0; i
< 256; i
++)
4844 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4845 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4852 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4858 /* compare-sections command
4860 With no arguments, compares each loadable section in the exec bfd
4861 with the same memory range on the target, and reports mismatches.
4862 Useful for verifying the image on the target against the exec file.
4863 Depends on the target understanding the new "qCRC:" request. */
4865 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4866 target method (target verify memory) and generic version of the
4867 actual command. This will allow other high-level code (especially
4868 generic_load()) to make use of this target functionality. */
4871 compare_sections_command (char *args
, int from_tty
)
4873 struct remote_state
*rs
= get_remote_state ();
4875 unsigned long host_crc
, target_crc
;
4876 extern bfd
*exec_bfd
;
4877 struct cleanup
*old_chain
;
4880 const char *sectname
;
4881 char *buf
= alloca (rs
->remote_packet_size
);
4888 error (_("command cannot be used without an exec file"));
4889 if (!current_target
.to_shortname
||
4890 strcmp (current_target
.to_shortname
, "remote") != 0)
4891 error (_("command can only be used with remote target"));
4893 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4895 if (!(s
->flags
& SEC_LOAD
))
4896 continue; /* skip non-loadable section */
4898 size
= bfd_get_section_size (s
);
4900 continue; /* skip zero-length section */
4902 sectname
= bfd_get_section_name (exec_bfd
, s
);
4903 if (args
&& strcmp (args
, sectname
) != 0)
4904 continue; /* not the section selected by user */
4906 matched
= 1; /* do this section */
4908 /* FIXME: assumes lma can fit into long. */
4909 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
4912 /* Be clever; compute the host_crc before waiting for target
4914 sectdata
= xmalloc (size
);
4915 old_chain
= make_cleanup (xfree
, sectdata
);
4916 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4917 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4919 getpkt (buf
, (rs
->remote_packet_size
), 0);
4921 error (_("target memory fault, section %s, range 0x%s -- 0x%s"),
4922 sectname
, paddr (lma
), paddr (lma
+ size
));
4924 error (_("remote target does not support this operation"));
4926 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4927 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4929 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4930 sectname
, paddr (lma
), paddr (lma
+ size
));
4931 if (host_crc
== target_crc
)
4932 printf_filtered ("matched.\n");
4935 printf_filtered ("MIS-MATCHED!\n");
4939 do_cleanups (old_chain
);
4942 warning (_("One or more sections of the remote executable does not match\n\
4943 the loaded file\n"));
4944 if (args
&& !matched
)
4945 printf_filtered (_("No loaded section named '%s'.\n"), args
);
4949 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
4950 const char *annex
, void *readbuf
, const void *writebuf
,
4951 ULONGEST offset
, LONGEST len
)
4953 struct remote_state
*rs
= get_remote_state ();
4955 char *buf2
= alloca (rs
->remote_packet_size
);
4956 char *p2
= &buf2
[0];
4959 /* Handle memory using remote_xfer_memory. */
4960 if (object
== TARGET_OBJECT_MEMORY
)
4965 if (writebuf
!= NULL
)
4967 void *buffer
= xmalloc (len
);
4968 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
4969 memcpy (buffer
, writebuf
, len
);
4970 xfered
= remote_xfer_memory (offset
, buffer
, len
, 1, NULL
, ops
);
4971 do_cleanups (cleanup
);
4974 xfered
= remote_xfer_memory (offset
, readbuf
, len
, 0, NULL
, ops
);
4978 else if (xfered
== 0 && errno
== 0)
4984 /* Only handle reads. */
4985 if (writebuf
!= NULL
|| readbuf
== NULL
)
4988 /* Map pre-existing objects onto letters. DO NOT do this for new
4989 objects!!! Instead specify new query packets. */
4992 case TARGET_OBJECT_KOD
:
4995 case TARGET_OBJECT_AVR
:
4999 case TARGET_OBJECT_AUXV
:
5000 if (remote_protocol_qPart_auxv
.support
!= PACKET_DISABLE
)
5002 unsigned int total
= 0;
5005 LONGEST n
= min ((rs
->remote_packet_size
- 2) / 2, len
);
5006 snprintf (buf2
, rs
->remote_packet_size
,
5007 "qPart:auxv:read::%s,%s",
5008 phex_nz (offset
, sizeof offset
),
5009 phex_nz (n
, sizeof n
));
5012 return total
> 0 ? total
: i
;
5014 getpkt (buf2
, rs
->remote_packet_size
, 0);
5015 if (packet_ok (buf2
, &remote_protocol_qPart_auxv
) != PACKET_OK
)
5016 return total
> 0 ? total
: -1;
5017 if (buf2
[0] == 'O' && buf2
[1] == 'K' && buf2
[2] == '\0')
5018 break; /* Got EOF indicator. */
5019 /* Got some data. */
5020 i
= hex2bin (buf2
, readbuf
, len
);
5023 readbuf
= (void *) ((char *) readbuf
+ i
);
5037 /* Note: a zero OFFSET and LEN can be used to query the minimum
5039 if (offset
== 0 && len
== 0)
5040 return (rs
->remote_packet_size
);
5041 /* Minimum outbuf size is (rs->remote_packet_size) - if bufsiz is
5042 not large enough let the caller. */
5043 if (len
< (rs
->remote_packet_size
))
5045 len
= rs
->remote_packet_size
;
5047 /* Except for querying the minimum buffer size, target must be open. */
5049 error (_("remote query is only available after target open"));
5051 gdb_assert (annex
!= NULL
);
5052 gdb_assert (readbuf
!= NULL
);
5057 /* We used one buffer char for the remote protocol q command and
5058 another for the query type. As the remote protocol encapsulation
5059 uses 4 chars plus one extra in case we are debugging
5060 (remote_debug), we have PBUFZIZ - 7 left to pack the query
5063 while (annex
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5065 /* Bad caller may have sent forbidden characters. */
5066 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
5071 gdb_assert (annex
[i
] == '\0');
5077 getpkt (readbuf
, len
, 0);
5079 return strlen (readbuf
);
5083 remote_rcmd (char *command
,
5084 struct ui_file
*outbuf
)
5086 struct remote_state
*rs
= get_remote_state ();
5088 char *buf
= alloca (rs
->remote_packet_size
);
5092 error (_("remote rcmd is only available after target open"));
5094 /* Send a NULL command across as an empty command. */
5095 if (command
== NULL
)
5098 /* The query prefix. */
5099 strcpy (buf
, "qRcmd,");
5100 p
= strchr (buf
, '\0');
5102 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5103 error (_("\"monitor\" command ``%s'' is too long."), command
);
5105 /* Encode the actual command. */
5106 bin2hex (command
, p
, 0);
5108 if (putpkt (buf
) < 0)
5109 error (_("Communication problem with target."));
5111 /* get/display the response */
5114 /* XXX - see also tracepoint.c:remote_get_noisy_reply(). */
5116 getpkt (buf
, (rs
->remote_packet_size
), 0);
5118 error (_("Target does not support this command."));
5119 if (buf
[0] == 'O' && buf
[1] != 'K')
5121 remote_console_output (buf
+ 1); /* 'O' message from stub. */
5124 if (strcmp (buf
, "OK") == 0)
5126 if (strlen (buf
) == 3 && buf
[0] == 'E'
5127 && isdigit (buf
[1]) && isdigit (buf
[2]))
5129 error (_("Protocol error with Rcmd"));
5131 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5133 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5134 fputc_unfiltered (c
, outbuf
);
5141 packet_command (char *args
, int from_tty
)
5143 struct remote_state
*rs
= get_remote_state ();
5144 char *buf
= alloca (rs
->remote_packet_size
);
5147 error (_("command can only be used with remote target"));
5150 error (_("remote-packet command requires packet text as argument"));
5152 puts_filtered ("sending: ");
5153 print_packet (args
);
5154 puts_filtered ("\n");
5157 getpkt (buf
, (rs
->remote_packet_size
), 0);
5158 puts_filtered ("received: ");
5160 puts_filtered ("\n");
5164 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
5166 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5168 static void threadset_test_cmd (char *cmd
, int tty
);
5170 static void threadalive_test (char *cmd
, int tty
);
5172 static void threadlist_test_cmd (char *cmd
, int tty
);
5174 int get_and_display_threadinfo (threadref
*ref
);
5176 static void threadinfo_test_cmd (char *cmd
, int tty
);
5178 static int thread_display_step (threadref
*ref
, void *context
);
5180 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5182 static void init_remote_threadtests (void);
5184 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
5187 threadset_test_cmd (char *cmd
, int tty
)
5189 int sample_thread
= SAMPLE_THREAD
;
5191 printf_filtered (_("Remote threadset test\n"));
5192 set_thread (sample_thread
, 1);
5197 threadalive_test (char *cmd
, int tty
)
5199 int sample_thread
= SAMPLE_THREAD
;
5201 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5202 printf_filtered ("PASS: Thread alive test\n");
5204 printf_filtered ("FAIL: Thread alive test\n");
5207 void output_threadid (char *title
, threadref
*ref
);
5210 output_threadid (char *title
, threadref
*ref
)
5214 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
5216 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5220 threadlist_test_cmd (char *cmd
, int tty
)
5223 threadref nextthread
;
5224 int done
, result_count
;
5225 threadref threadlist
[3];
5227 printf_filtered ("Remote Threadlist test\n");
5228 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5229 &result_count
, &threadlist
[0]))
5230 printf_filtered ("FAIL: threadlist test\n");
5233 threadref
*scan
= threadlist
;
5234 threadref
*limit
= scan
+ result_count
;
5236 while (scan
< limit
)
5237 output_threadid (" thread ", scan
++);
5242 display_thread_info (struct gdb_ext_thread_info
*info
)
5244 output_threadid ("Threadid: ", &info
->threadid
);
5245 printf_filtered ("Name: %s\n ", info
->shortname
);
5246 printf_filtered ("State: %s\n", info
->display
);
5247 printf_filtered ("other: %s\n\n", info
->more_display
);
5251 get_and_display_threadinfo (threadref
*ref
)
5255 struct gdb_ext_thread_info threadinfo
;
5257 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5258 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5259 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5260 display_thread_info (&threadinfo
);
5265 threadinfo_test_cmd (char *cmd
, int tty
)
5267 int athread
= SAMPLE_THREAD
;
5271 int_to_threadref (&thread
, athread
);
5272 printf_filtered ("Remote Threadinfo test\n");
5273 if (!get_and_display_threadinfo (&thread
))
5274 printf_filtered ("FAIL cannot get thread info\n");
5278 thread_display_step (threadref
*ref
, void *context
)
5280 /* output_threadid(" threadstep ",ref); *//* simple test */
5281 return get_and_display_threadinfo (ref
);
5285 threadlist_update_test_cmd (char *cmd
, int tty
)
5287 printf_filtered ("Remote Threadlist update test\n");
5288 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5292 init_remote_threadtests (void)
5294 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
5295 Fetch and print the remote list of thread identifiers, one pkt only"));
5296 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5297 _("Fetch and display info about one thread"));
5298 add_com ("tset", class_obscure
, threadset_test_cmd
,
5299 _("Test setting to a different thread"));
5300 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5301 _("Iterate through updating all remote thread info"));
5302 add_com ("talive", class_obscure
, threadalive_test
,
5303 _(" Remote thread alive test "));
5308 /* Convert a thread ID to a string. Returns the string in a static
5312 remote_pid_to_str (ptid_t ptid
)
5314 static char buf
[30];
5316 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5321 init_remote_ops (void)
5323 remote_ops
.to_shortname
= "remote";
5324 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5326 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5327 Specify the serial device it is connected to\n\
5328 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5329 remote_ops
.to_open
= remote_open
;
5330 remote_ops
.to_close
= remote_close
;
5331 remote_ops
.to_detach
= remote_detach
;
5332 remote_ops
.to_disconnect
= remote_disconnect
;
5333 remote_ops
.to_resume
= remote_resume
;
5334 remote_ops
.to_wait
= remote_wait
;
5335 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5336 remote_ops
.to_store_registers
= remote_store_registers
;
5337 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5338 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5339 remote_ops
.to_files_info
= remote_files_info
;
5340 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5341 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5342 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5343 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5344 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5345 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5346 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5347 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5348 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5349 remote_ops
.to_kill
= remote_kill
;
5350 remote_ops
.to_load
= generic_load
;
5351 remote_ops
.to_mourn_inferior
= remote_mourn
;
5352 remote_ops
.to_thread_alive
= remote_thread_alive
;
5353 remote_ops
.to_find_new_threads
= remote_threads_info
;
5354 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5355 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5356 remote_ops
.to_stop
= remote_stop
;
5357 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
5358 remote_ops
.to_rcmd
= remote_rcmd
;
5359 remote_ops
.to_stratum
= process_stratum
;
5360 remote_ops
.to_has_all_memory
= 1;
5361 remote_ops
.to_has_memory
= 1;
5362 remote_ops
.to_has_stack
= 1;
5363 remote_ops
.to_has_registers
= 1;
5364 remote_ops
.to_has_execution
= 1;
5365 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5366 remote_ops
.to_magic
= OPS_MAGIC
;
5369 /* Set up the extended remote vector by making a copy of the standard
5370 remote vector and adding to it. */
5373 init_extended_remote_ops (void)
5375 extended_remote_ops
= remote_ops
;
5377 extended_remote_ops
.to_shortname
= "extended-remote";
5378 extended_remote_ops
.to_longname
=
5379 "Extended remote serial target in gdb-specific protocol";
5380 extended_remote_ops
.to_doc
=
5381 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5382 Specify the serial device it is connected to (e.g. /dev/ttya).",
5383 extended_remote_ops
.to_open
= extended_remote_open
;
5384 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5385 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5389 remote_can_async_p (void)
5391 /* We're async whenever the serial device is. */
5392 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5396 remote_is_async_p (void)
5398 /* We're async whenever the serial device is. */
5399 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5402 /* Pass the SERIAL event on and up to the client. One day this code
5403 will be able to delay notifying the client of an event until the
5404 point where an entire packet has been received. */
5406 static void (*async_client_callback
) (enum inferior_event_type event_type
,
5408 static void *async_client_context
;
5409 static serial_event_ftype remote_async_serial_handler
;
5412 remote_async_serial_handler (struct serial
*scb
, void *context
)
5414 /* Don't propogate error information up to the client. Instead let
5415 the client find out about the error by querying the target. */
5416 async_client_callback (INF_REG_EVENT
, async_client_context
);
5420 remote_async (void (*callback
) (enum inferior_event_type event_type
,
5421 void *context
), void *context
)
5423 if (current_target
.to_async_mask_value
== 0)
5424 internal_error (__FILE__
, __LINE__
,
5425 _("Calling remote_async when async is masked"));
5427 if (callback
!= NULL
)
5429 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5430 async_client_callback
= callback
;
5431 async_client_context
= context
;
5434 serial_async (remote_desc
, NULL
, NULL
);
5437 /* Target async and target extended-async.
5439 This are temporary targets, until it is all tested. Eventually
5440 async support will be incorporated int the usual 'remote'
5444 init_remote_async_ops (void)
5446 remote_async_ops
.to_shortname
= "async";
5447 remote_async_ops
.to_longname
=
5448 "Remote serial target in async version of the gdb-specific protocol";
5449 remote_async_ops
.to_doc
=
5450 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5451 Specify the serial device it is connected to (e.g. /dev/ttya).";
5452 remote_async_ops
.to_open
= remote_async_open
;
5453 remote_async_ops
.to_close
= remote_close
;
5454 remote_async_ops
.to_detach
= remote_detach
;
5455 remote_async_ops
.to_disconnect
= remote_disconnect
;
5456 remote_async_ops
.to_resume
= remote_async_resume
;
5457 remote_async_ops
.to_wait
= remote_async_wait
;
5458 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5459 remote_async_ops
.to_store_registers
= remote_store_registers
;
5460 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5461 remote_async_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5462 remote_async_ops
.to_files_info
= remote_files_info
;
5463 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5464 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5465 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5466 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5467 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5468 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5469 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5470 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5471 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5472 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5473 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5474 remote_async_ops
.to_kill
= remote_async_kill
;
5475 remote_async_ops
.to_load
= generic_load
;
5476 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5477 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5478 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5479 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5480 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5481 remote_async_ops
.to_stop
= remote_stop
;
5482 remote_async_ops
.to_xfer_partial
= remote_xfer_partial
;
5483 remote_async_ops
.to_rcmd
= remote_rcmd
;
5484 remote_async_ops
.to_stratum
= process_stratum
;
5485 remote_async_ops
.to_has_all_memory
= 1;
5486 remote_async_ops
.to_has_memory
= 1;
5487 remote_async_ops
.to_has_stack
= 1;
5488 remote_async_ops
.to_has_registers
= 1;
5489 remote_async_ops
.to_has_execution
= 1;
5490 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5491 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5492 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5493 remote_async_ops
.to_async
= remote_async
;
5494 remote_async_ops
.to_async_mask_value
= 1;
5495 remote_async_ops
.to_magic
= OPS_MAGIC
;
5498 /* Set up the async extended remote vector by making a copy of the standard
5499 remote vector and adding to it. */
5502 init_extended_async_remote_ops (void)
5504 extended_async_remote_ops
= remote_async_ops
;
5506 extended_async_remote_ops
.to_shortname
= "extended-async";
5507 extended_async_remote_ops
.to_longname
=
5508 "Extended remote serial target in async gdb-specific protocol";
5509 extended_async_remote_ops
.to_doc
=
5510 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5511 Specify the serial device it is connected to (e.g. /dev/ttya).",
5512 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5513 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5514 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5518 set_remote_cmd (char *args
, int from_tty
)
5523 show_remote_cmd (char *args
, int from_tty
)
5525 /* FIXME: cagney/2002-06-15: This function should iterate over
5526 remote_show_cmdlist for a list of sub commands to show. */
5527 show_remote_protocol_Z_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5528 show_remote_protocol_P_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5529 show_remote_protocol_p_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5530 show_remote_protocol_qSymbol_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5531 show_remote_protocol_vcont_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5532 show_remote_protocol_binary_download_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5533 show_remote_protocol_qPart_auxv_packet_cmd (gdb_stdout
, from_tty
, NULL
, NULL
);
5537 build_remote_gdbarch_data (void)
5539 remote_address_size
= TARGET_ADDR_BIT
;
5542 /* Saved pointer to previous owner of the new_objfile event. */
5543 static void (*remote_new_objfile_chain
) (struct objfile
*);
5545 /* Function to be called whenever a new objfile (shlib) is detected. */
5547 remote_new_objfile (struct objfile
*objfile
)
5549 if (remote_desc
!= 0) /* Have a remote connection. */
5551 remote_check_symbols (objfile
);
5553 /* Call predecessor on chain, if any. */
5554 if (remote_new_objfile_chain
!= 0 &&
5556 remote_new_objfile_chain (objfile
);
5560 _initialize_remote (void)
5562 static struct cmd_list_element
*remote_set_cmdlist
;
5563 static struct cmd_list_element
*remote_show_cmdlist
;
5564 struct cmd_list_element
*tmpcmd
;
5566 /* architecture specific data */
5567 remote_gdbarch_data_handle
=
5568 gdbarch_data_register_post_init (init_remote_state
);
5570 /* Old tacky stuff. NOTE: This comes after the remote protocol so
5571 that the remote protocol has been initialized. */
5572 DEPRECATED_REGISTER_GDBARCH_SWAP (remote_address_size
);
5573 deprecated_register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5576 add_target (&remote_ops
);
5578 init_extended_remote_ops ();
5579 add_target (&extended_remote_ops
);
5581 init_remote_async_ops ();
5582 add_target (&remote_async_ops
);
5584 init_extended_async_remote_ops ();
5585 add_target (&extended_async_remote_ops
);
5587 /* Hook into new objfile notification. */
5588 remote_new_objfile_chain
= deprecated_target_new_objfile_hook
;
5589 deprecated_target_new_objfile_hook
= remote_new_objfile
;
5592 init_remote_threadtests ();
5595 /* set/show remote ... */
5597 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
5598 Remote protocol specific variables\n\
5599 Configure various remote-protocol specific variables such as\n\
5600 the packets being used"),
5601 &remote_set_cmdlist
, "set remote ",
5602 0 /* allow-unknown */, &setlist
);
5603 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
5604 Remote protocol specific variables\n\
5605 Configure various remote-protocol specific variables such as\n\
5606 the packets being used"),
5607 &remote_show_cmdlist
, "show remote ",
5608 0 /* allow-unknown */, &showlist
);
5610 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
5611 Compare section data on target to the exec file.\n\
5612 Argument is a single section name (default: all loaded sections)."),
5615 add_cmd ("packet", class_maintenance
, packet_command
, _("\
5616 Send an arbitrary packet to a remote target.\n\
5617 maintenance packet TEXT\n\
5618 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5619 this command sends the string TEXT to the inferior, and displays the\n\
5620 response packet. GDB supplies the initial `$' character, and the\n\
5621 terminating `#' character and checksum."),
5624 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
5625 Set whether to send break if interrupted."), _("\
5626 Show whether to send break if interrupted."), _("\
5627 If set, a break, instead of a cntrl-c, is sent to the remote target."),
5628 NULL
, NULL
, /* FIXME: i18n: Whether to send break if interrupted is %s. */
5629 &setlist
, &showlist
);
5631 /* Install commands for configuring memory read/write packets. */
5633 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
5634 Set the maximum number of bytes per memory write packet (deprecated)."),
5636 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
5637 Show the maximum number of bytes per memory write packet (deprecated)."),
5639 add_cmd ("memory-write-packet-size", no_class
,
5640 set_memory_write_packet_size
, _("\
5641 Set the maximum number of bytes per memory-write packet.\n\
5642 Specify the number of bytes in a packet or 0 (zero) for the\n\
5643 default packet size. The actual limit is further reduced\n\
5644 dependent on the target. Specify ``fixed'' to disable the\n\
5645 further restriction and ``limit'' to enable that restriction."),
5646 &remote_set_cmdlist
);
5647 add_cmd ("memory-read-packet-size", no_class
,
5648 set_memory_read_packet_size
, _("\
5649 Set the maximum number of bytes per memory-read packet.\n\
5650 Specify the number of bytes in a packet or 0 (zero) for the\n\
5651 default packet size. The actual limit is further reduced\n\
5652 dependent on the target. Specify ``fixed'' to disable the\n\
5653 further restriction and ``limit'' to enable that restriction."),
5654 &remote_set_cmdlist
);
5655 add_cmd ("memory-write-packet-size", no_class
,
5656 show_memory_write_packet_size
,
5657 _("Show the maximum number of bytes per memory-write packet."),
5658 &remote_show_cmdlist
);
5659 add_cmd ("memory-read-packet-size", no_class
,
5660 show_memory_read_packet_size
,
5661 _("Show the maximum number of bytes per memory-read packet."),
5662 &remote_show_cmdlist
);
5664 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
5665 &remote_hw_watchpoint_limit
, _("\
5666 Set the maximum number of target hardware watchpoints."), _("\
5667 Show the maximum number of target hardware watchpoints."), _("\
5668 Specify a negative limit for unlimited."),
5669 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
5670 &remote_set_cmdlist
, &remote_show_cmdlist
);
5671 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
5672 &remote_hw_breakpoint_limit
, _("\
5673 Set the maximum number of target hardware breakpoints."), _("\
5674 Show the maximum number of target hardware breakpoints."), _("\
5675 Specify a negative limit for unlimited."),
5676 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
5677 &remote_set_cmdlist
, &remote_show_cmdlist
);
5679 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
5680 &remote_address_size
, _("\
5681 Set the maximum size of the address (in bits) in a memory packet."), _("\
5682 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
5684 NULL
, /* FIXME: i18n: */
5685 &setlist
, &showlist
);
5687 add_packet_config_cmd (&remote_protocol_binary_download
,
5688 "X", "binary-download",
5689 set_remote_protocol_binary_download_cmd
,
5690 show_remote_protocol_binary_download_cmd
,
5691 &remote_set_cmdlist
, &remote_show_cmdlist
,
5694 add_packet_config_cmd (&remote_protocol_vcont
,
5695 "vCont", "verbose-resume",
5696 set_remote_protocol_vcont_packet_cmd
,
5697 show_remote_protocol_vcont_packet_cmd
,
5698 &remote_set_cmdlist
, &remote_show_cmdlist
,
5701 add_packet_config_cmd (&remote_protocol_qSymbol
,
5702 "qSymbol", "symbol-lookup",
5703 set_remote_protocol_qSymbol_packet_cmd
,
5704 show_remote_protocol_qSymbol_packet_cmd
,
5705 &remote_set_cmdlist
, &remote_show_cmdlist
,
5708 add_packet_config_cmd (&remote_protocol_P
,
5709 "P", "set-register",
5710 set_remote_protocol_P_packet_cmd
,
5711 show_remote_protocol_P_packet_cmd
,
5712 &remote_set_cmdlist
, &remote_show_cmdlist
,
5715 add_packet_config_cmd (&remote_protocol_p
,
5716 "p", "fetch-register",
5717 set_remote_protocol_p_packet_cmd
,
5718 show_remote_protocol_p_packet_cmd
,
5719 &remote_set_cmdlist
, &remote_show_cmdlist
,
5722 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
5723 "Z0", "software-breakpoint",
5724 set_remote_protocol_Z_software_bp_packet_cmd
,
5725 show_remote_protocol_Z_software_bp_packet_cmd
,
5726 &remote_set_cmdlist
, &remote_show_cmdlist
,
5729 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
5730 "Z1", "hardware-breakpoint",
5731 set_remote_protocol_Z_hardware_bp_packet_cmd
,
5732 show_remote_protocol_Z_hardware_bp_packet_cmd
,
5733 &remote_set_cmdlist
, &remote_show_cmdlist
,
5736 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
5737 "Z2", "write-watchpoint",
5738 set_remote_protocol_Z_write_wp_packet_cmd
,
5739 show_remote_protocol_Z_write_wp_packet_cmd
,
5740 &remote_set_cmdlist
, &remote_show_cmdlist
,
5743 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
5744 "Z3", "read-watchpoint",
5745 set_remote_protocol_Z_read_wp_packet_cmd
,
5746 show_remote_protocol_Z_read_wp_packet_cmd
,
5747 &remote_set_cmdlist
, &remote_show_cmdlist
,
5750 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
5751 "Z4", "access-watchpoint",
5752 set_remote_protocol_Z_access_wp_packet_cmd
,
5753 show_remote_protocol_Z_access_wp_packet_cmd
,
5754 &remote_set_cmdlist
, &remote_show_cmdlist
,
5757 add_packet_config_cmd (&remote_protocol_qPart_auxv
,
5758 "qPart_auxv", "read-aux-vector",
5759 set_remote_protocol_qPart_auxv_packet_cmd
,
5760 show_remote_protocol_qPart_auxv_packet_cmd
,
5761 &remote_set_cmdlist
, &remote_show_cmdlist
,
5764 /* Keep the old ``set remote Z-packet ...'' working. */
5765 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
5766 &remote_Z_packet_detect
, _("\
5767 Set use of remote protocol `Z' packets"), _("\
5768 Show use of remote protocol `Z' packets "), _("\
5769 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
5771 set_remote_protocol_Z_packet_cmd
,
5772 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
5773 &remote_set_cmdlist
, &remote_show_cmdlist
);
5775 /* Eventually initialize fileio. See fileio.c */
5776 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);