1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* See the GDB User Guide for details of the GDB remote protocol. */
25 #include "gdb_string.h"
34 /*#include "terminal.h" */
37 #include "gdb-stabs.h"
38 #include "gdbthread.h"
46 #include <sys/types.h>
49 #include "event-loop.h"
50 #include "event-top.h"
56 /* Prototypes for local functions */
57 static void cleanup_sigint_signal_handler (void *dummy
);
58 static void initialize_sigint_signal_handler (void);
60 static void handle_remote_sigint
PARAMS ((int));
61 static void handle_remote_sigint_twice
PARAMS ((int));
62 static void async_remote_interrupt
PARAMS ((gdb_client_data
));
63 void async_remote_interrupt_twice
PARAMS ((gdb_client_data
));
65 static void build_remote_gdbarch_data
PARAMS ((void));
67 static int remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
69 static int remote_read_bytes
PARAMS ((CORE_ADDR memaddr
,
70 char *myaddr
, int len
));
72 static void remote_files_info
PARAMS ((struct target_ops
* ignore
));
74 static int remote_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
,
75 int len
, int should_write
,
76 struct target_ops
* target
));
78 static void remote_prepare_to_store
PARAMS ((void));
80 static void remote_fetch_registers
PARAMS ((int regno
));
82 static void remote_resume
PARAMS ((int pid
, int step
,
83 enum target_signal siggnal
));
84 static void remote_async_resume
PARAMS ((int pid
, int step
,
85 enum target_signal siggnal
));
86 static int remote_start_remote
PARAMS ((PTR
));
88 static void remote_open
PARAMS ((char *name
, int from_tty
));
89 static void remote_async_open
PARAMS ((char *name
, int from_tty
));
91 static void extended_remote_open
PARAMS ((char *name
, int from_tty
));
92 static void extended_remote_async_open
PARAMS ((char *name
, int from_tty
));
94 static void remote_open_1
PARAMS ((char *, int, struct target_ops
*,
96 static void remote_async_open_1
PARAMS ((char *, int, struct target_ops
*,
99 static void remote_close
PARAMS ((int quitting
));
101 static void remote_store_registers
PARAMS ((int regno
));
103 static void remote_mourn
PARAMS ((void));
104 static void remote_async_mourn
PARAMS ((void));
106 static void extended_remote_restart
PARAMS ((void));
108 static void extended_remote_mourn
PARAMS ((void));
110 static void extended_remote_create_inferior
PARAMS ((char *, char *, char **));
111 static void extended_remote_async_create_inferior
PARAMS ((char *, char *, char **));
113 static void remote_mourn_1
PARAMS ((struct target_ops
*));
115 static void remote_send (char *buf
, long sizeof_buf
);
117 static int readchar
PARAMS ((int timeout
));
119 static int remote_wait
PARAMS ((int pid
, struct target_waitstatus
* status
));
120 static int remote_async_wait
PARAMS ((int pid
, struct target_waitstatus
* status
));
122 static void remote_kill
PARAMS ((void));
123 static void remote_async_kill
PARAMS ((void));
125 static int tohex
PARAMS ((int nib
));
127 static void remote_detach
PARAMS ((char *args
, int from_tty
));
128 static void remote_async_detach
PARAMS ((char *args
, int from_tty
));
130 static void remote_interrupt
PARAMS ((int signo
));
132 static void remote_interrupt_twice
PARAMS ((int signo
));
134 static void interrupt_query
PARAMS ((void));
136 static void set_thread
PARAMS ((int, int));
138 static int remote_thread_alive
PARAMS ((int));
140 static void get_offsets
PARAMS ((void));
142 static long read_frame (char *buf
, long sizeof_buf
);
144 static int remote_insert_breakpoint
PARAMS ((CORE_ADDR
, char *));
146 static int remote_remove_breakpoint
PARAMS ((CORE_ADDR
, char *));
148 static int hexnumlen
PARAMS ((ULONGEST num
));
150 static void init_remote_ops
PARAMS ((void));
152 static void init_extended_remote_ops
PARAMS ((void));
154 static void init_remote_cisco_ops
PARAMS ((void));
156 static struct target_ops remote_cisco_ops
;
158 static void remote_stop
PARAMS ((void));
160 static int ishex
PARAMS ((int ch
, int *val
));
162 static int stubhex
PARAMS ((int ch
));
164 static int remote_query
PARAMS ((int /*char */ , char *, char *, int *));
166 static int hexnumstr
PARAMS ((char *, ULONGEST
));
168 static int hexnumnstr
PARAMS ((char *, ULONGEST
, int));
170 static CORE_ADDR remote_address_masked
PARAMS ((CORE_ADDR
));
172 static void print_packet
PARAMS ((char *));
174 static unsigned long crc32
PARAMS ((unsigned char *, int, unsigned int));
176 static void compare_sections_command
PARAMS ((char *, int));
178 static void packet_command
PARAMS ((char *, int));
180 static int stub_unpack_int
PARAMS ((char *buff
, int fieldlength
));
182 static int remote_current_thread
PARAMS ((int oldpid
));
184 static void remote_find_new_threads
PARAMS ((void));
186 static void record_currthread
PARAMS ((int currthread
));
188 /* exported functions */
190 extern int fromhex
PARAMS ((int a
));
192 static int putpkt_binary
PARAMS ((char *buf
, int cnt
));
194 static void check_binary_download
PARAMS ((CORE_ADDR addr
));
196 struct packet_config
;
198 static void show_packet_config_cmd
PARAMS ((struct packet_config
* config
));
200 static void set_packet_config_cmd
PARAMS ((struct packet_config
* config
,
201 struct cmd_list_element
* c
));
203 static void add_packet_config_cmd
PARAMS ((struct packet_config
* config
,
206 void (*set_func
) (char *args
, int from_tty
, struct cmd_list_element
* c
),
207 void (*show_func
) (char *name
, int from_tty
),
208 struct cmd_list_element
**setlist
,
209 struct cmd_list_element
**showlist
));
211 static void init_packet_config
PARAMS ((struct packet_config
* config
));
213 static void set_remote_protocol_P_packet_cmd
PARAMS ((char *args
,
215 struct cmd_list_element
* c
));
217 static void show_remote_protocol_P_packet_cmd
PARAMS ((char *args
,
220 static void set_remote_protocol_Z_packet_cmd
PARAMS ((char *args
,
222 struct cmd_list_element
* c
));
224 static void show_remote_protocol_Z_packet_cmd
PARAMS ((char *args
,
230 /* Define the target subroutine names */
232 void open_remote_target
PARAMS ((char *, int, struct target_ops
*, int));
234 void _initialize_remote
PARAMS ((void));
238 static struct target_ops remote_ops
;
240 static struct target_ops extended_remote_ops
;
242 /* Temporary target ops. Just like the remote_ops and
243 extended_remote_ops, but with asynchronous support. */
244 static struct target_ops remote_async_ops
;
246 static struct target_ops extended_async_remote_ops
;
248 /* This was 5 seconds, which is a long time to sit and wait.
249 Unless this is going though some terminal server or multiplexer or
250 other form of hairy serial connection, I would think 2 seconds would
253 /* Changed to allow option to set timeout value.
254 was static int remote_timeout = 2; */
255 extern int remote_timeout
;
257 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
258 ``forever'' still use the normal timeout mechanism. This is
259 currently used by the ASYNC code to guarentee that target reads
260 during the initial connect always time-out. Once getpkt has been
261 modified to return a timeout indication and, in turn
262 remote_wait()/wait_for_inferior() have gained a timeout parameter
264 static int wait_forever_enabled_p
= 1;
267 /* This variable chooses whether to send a ^C or a break when the user
268 requests program interruption. Although ^C is usually what remote
269 systems expect, and that is the default here, sometimes a break is
270 preferable instead. */
272 static int remote_break
;
274 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
275 remote_open knows that we don't have a file open when the program
277 static serial_t remote_desc
= NULL
;
279 /* This is set by the target (thru the 'S' message)
280 to denote that the target is in kernel mode. */
281 static int cisco_kernel_mode
= 0;
283 /* This variable sets the number of bits in an address that are to be
284 sent in a memory ("M" or "m") packet. Normally, after stripping
285 leading zeros, the entire address would be sent. This variable
286 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
287 initial implementation of remote.c restricted the address sent in
288 memory packets to ``host::sizeof long'' bytes - (typically 32
289 bits). Consequently, for 64 bit targets, the upper 32 bits of an
290 address was never sent. Since fixing this bug may cause a break in
291 some remote targets this variable is principly provided to
292 facilitate backward compatibility. */
294 static int remote_address_size
;
296 /* Tempoary to track who currently owns the terminal. See
297 target_async_terminal_* for more details. */
299 static int remote_async_terminal_ours_p
;
302 /* This is the size (in chars) of the first response to the ``g''
303 packet. It is used as a heuristic when determining the maximum
304 size of memory-read and memory-write packets. A target will
305 typically only reserve a buffer large enough to hold the ``g''
306 packet. The size does not include packet overhead (headers and
309 static long actual_register_packet_size
;
311 /* This is the maximum size (in chars) of a non read/write packet. It
312 is also used as a cap on the size of read/write packets. */
314 static long remote_packet_size
;
316 #define PBUFSIZ (remote_packet_size)
318 /* User configurable variables for the number of characters in a
319 memory read/write packet. MIN (PBUFSIZ, g-packet-size) is the
320 default. Some targets need smaller values (fifo overruns, et.al.)
321 and some users need larger values (speed up transfers). The
322 variables ``preferred_*'' (the user request), ``current_*'' (what
323 was actually set) and ``forced_*'' (Positive - a soft limit,
324 negative - a hard limit). */
326 struct memory_packet_config
333 /* Compute the current size of a read/write packet. Since this makes
334 use of ``actual_register_packet_size'' the computation is dynamic. */
337 get_memory_packet_size (struct memory_packet_config
*config
)
339 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
340 law?) that some hosts don't cope very well with large alloca()
341 calls. Eventually the alloca() code will be replaced by calls to
342 xmalloc() and make_cleanups() allowing this restriction to either
343 be lifted or removed. */
344 #ifndef MAX_REMOTE_PACKET_SIZE
345 #define MAX_REMOTE_PACKET_SIZE 16384
347 /* NOTE: 16 is just chosen at random. */
348 #ifndef MIN_REMOTE_PACKET_SIZE
349 #define MIN_REMOTE_PACKET_SIZE 16
354 if (config
->size
<= 0)
355 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
357 what_they_get
= config
->size
;
361 what_they_get
= remote_packet_size
;
362 /* Limit the packet to the size specified by the user. */
364 && what_they_get
> config
->size
)
365 what_they_get
= config
->size
;
366 /* Limit it to the size of the targets ``g'' response. */
367 if (actual_register_packet_size
> 0
368 && what_they_get
> actual_register_packet_size
)
369 what_they_get
= actual_register_packet_size
;
371 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
372 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
373 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
374 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
375 return what_they_get
;
378 /* Update the size of a read/write packet. If they user wants
379 something really big then do a sanity check. */
382 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
384 int fixed_p
= config
->fixed_p
;
385 long size
= config
->size
;
387 error ("Argument required (integer, `fixed' or `limited').");
388 else if (strcmp (args
, "hard") == 0
389 || strcmp (args
, "fixed") == 0)
391 else if (strcmp (args
, "soft") == 0
392 || strcmp (args
, "limit") == 0)
397 size
= strtoul (args
, &end
, 0);
399 error ("Invalid %s (bad syntax).", config
->name
);
401 /* Instead of explicitly capping the size of a packet to
402 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
403 instead allowed to set the size to something arbitrarily
405 if (size
> MAX_REMOTE_PACKET_SIZE
)
406 error ("Invalid %s (too large).", config
->name
);
410 if (fixed_p
&& !config
->fixed_p
)
412 if (! query ("The target may not be able to correctly handle a %s\n"
413 "of %ld bytes. Change the packet size? ",
415 error ("Packet size not changed.");
417 /* Update the config. */
418 config
->fixed_p
= fixed_p
;
423 show_memory_packet_size (struct memory_packet_config
*config
)
425 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
427 printf_filtered ("Packets are fixed at %ld bytes.\n",
428 get_memory_packet_size (config
));
430 printf_filtered ("Packets are limited to %ld bytes.\n",
431 get_memory_packet_size (config
));
434 static struct memory_packet_config memory_write_packet_config
=
436 "memory-write-packet-size",
440 set_memory_write_packet_size (char *args
, int from_tty
)
442 set_memory_packet_size (args
, &memory_write_packet_config
);
446 show_memory_write_packet_size (char *args
, int from_tty
)
448 show_memory_packet_size (&memory_write_packet_config
);
452 get_memory_write_packet_size (void)
454 return get_memory_packet_size (&memory_write_packet_config
);
457 static struct memory_packet_config memory_read_packet_config
=
459 "memory-read-packet-size",
463 set_memory_read_packet_size (char *args
, int from_tty
)
465 set_memory_packet_size (args
, &memory_read_packet_config
);
469 show_memory_read_packet_size (char *args
, int from_tty
)
471 show_memory_packet_size (&memory_read_packet_config
);
475 get_memory_read_packet_size (void)
477 long size
= get_memory_packet_size (&memory_read_packet_config
);
478 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
479 extra buffer size argument before the memory read size can be
480 increased beyond PBUFSIZ. */
486 /* Register packet size initialization. Since the bounds change when
487 the architecture changes (namely REGISTER_BYTES) this all needs to
491 register_remote_packet_sizes (void)
493 REGISTER_GDBARCH_SWAP (remote_packet_size
);
494 REGISTER_GDBARCH_SWAP (actual_register_packet_size
);
498 build_remote_packet_sizes (void)
500 /* Default maximum number of characters in a packet body. Many
501 remote stubs have a hardwired buffer size of 400 bytes
502 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
503 as the maximum packet-size to ensure that the packet and an extra
504 NUL character can always fit in the buffer. This stops GDB
505 trashing stubs that try to squeeze an extra NUL into what is
506 already a full buffer (As of 1999-12-04 that was most stubs. */
507 remote_packet_size
= 400 - 1;
508 /* Should REGISTER_BYTES needs more space than the default, adjust
509 the size accordingly. Remember that each byte is encoded as two
510 characters. 32 is the overhead for the packet header /
511 footer. NOTE: cagney/1999-10-26: I suspect that 8
512 (``$NN:G...#NN'') is a better guess, the below has been padded a
514 if (REGISTER_BYTES
> ((remote_packet_size
- 32) / 2))
515 remote_packet_size
= (REGISTER_BYTES
* 2 + 32);
517 /* This one is filled in when a ``g'' packet is received. */
518 actual_register_packet_size
= 0;
521 /* Generic configuration support for packets the stub optionally
522 supports. Allows the user to specify the use of the packet as well
523 as allowing GDB to auto-detect support in the remote stub. */
527 PACKET_SUPPORT_UNKNOWN
= 0,
534 PACKET_AUTO_DETECT
= 0,
543 enum packet_detect detect
;
544 enum packet_support support
;
547 static char packet_support_auto
[] = "auto";
548 static char packet_enable
[] = "enable";
549 static char packet_disable
[] = "disable";
550 static char *packet_support_enums
[] =
559 set_packet_config_cmd (config
, c
)
560 struct packet_config
*config
;
561 struct cmd_list_element
*c
;
563 if (config
->state
== packet_enable
)
565 config
->detect
= PACKET_MANUAL_DETECT
;
566 config
->support
= PACKET_ENABLE
;
568 else if (config
->state
== packet_disable
)
570 config
->detect
= PACKET_MANUAL_DETECT
;
571 config
->support
= PACKET_DISABLE
;
573 else if (config
->state
== packet_support_auto
)
575 config
->detect
= PACKET_AUTO_DETECT
;
576 config
->support
= PACKET_SUPPORT_UNKNOWN
;
579 internal_error ("Bad enum value");
583 show_packet_config_cmd (config
)
584 struct packet_config
*config
;
586 char *support
= "internal-error";
587 switch (config
->support
)
593 support
= "disabled";
595 case PACKET_SUPPORT_UNKNOWN
:
599 switch (config
->detect
)
601 case PACKET_AUTO_DETECT
:
602 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
603 config
->name
, config
->title
, support
);
605 case PACKET_MANUAL_DETECT
:
606 printf_filtered ("Support for remote protocol `%s' (%s) is currently %s.\n",
607 config
->name
, config
->title
, support
);
612 add_packet_config_cmd (config
, name
, title
, set_func
, show_func
,
614 struct packet_config
*config
;
617 void (*set_func
) PARAMS ((char *args
, int from_tty
,
618 struct cmd_list_element
* c
));
619 void (*show_func
) PARAMS ((char *name
, int from_tty
));
620 struct cmd_list_element
**setlist
;
621 struct cmd_list_element
**showlist
;
623 struct cmd_list_element
*c
;
628 config
->title
= title
;
629 asprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
631 asprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
633 asprintf (&full_name
, "%s-packet", name
);
634 c
= add_set_enum_cmd (full_name
,
635 class_obscure
, packet_support_enums
,
636 (char *) &config
->state
,
638 c
->function
.sfunc
= set_func
;
639 add_cmd (full_name
, class_obscure
, show_func
, show_doc
, showlist
);
643 init_packet_config (config
)
644 struct packet_config
*config
;
646 switch (config
->detect
)
648 case PACKET_AUTO_DETECT
:
649 config
->support
= PACKET_SUPPORT_UNKNOWN
;
651 case PACKET_MANUAL_DETECT
:
652 /* let the user beware */
657 /* Should we try the 'P' (set register) request? */
659 static struct packet_config remote_protocol_P
;
662 set_remote_protocol_P_packet_cmd (args
, from_tty
, c
)
665 struct cmd_list_element
*c
;
667 set_packet_config_cmd (&remote_protocol_P
, c
);
671 show_remote_protocol_P_packet_cmd (args
, from_tty
)
675 show_packet_config_cmd (&remote_protocol_P
);
678 /* Should we try the 'Z' (set breakpoint) request? */
680 static struct packet_config remote_protocol_Z
;
683 set_remote_protocol_Z_packet_cmd (args
, from_tty
, c
)
686 struct cmd_list_element
*c
;
688 set_packet_config_cmd (&remote_protocol_Z
, c
);
692 show_remote_protocol_Z_packet_cmd (args
, from_tty
)
696 show_packet_config_cmd (&remote_protocol_Z
);
699 /* Should we try the 'X' (remote binary download) packet?
701 This variable (available to the user via "set remote X-packet")
702 dictates whether downloads are sent in binary (via the 'X' packet).
703 We assume that the stub can, and attempt to do it. This will be
704 cleared if the stub does not understand it. This switch is still
705 needed, though in cases when the packet is supported in the stub,
706 but the connection does not allow it (i.e., 7-bit serial connection
709 static struct packet_config remote_protocol_binary_download
;
712 set_remote_protocol_binary_download_cmd (char *args
,
714 struct cmd_list_element
*c
)
716 set_packet_config_cmd (&remote_protocol_binary_download
, c
);
720 show_remote_protocol_binary_download_cmd (char *args
,
723 show_packet_config_cmd (&remote_protocol_binary_download
);
727 /* Tokens for use by the asynchronous signal handlers for SIGINT */
728 PTR sigint_remote_twice_token
;
729 PTR sigint_remote_token
;
731 /* These are pointers to hook functions that may be set in order to
732 modify resume/wait behavior for a particular architecture. */
734 void (*target_resume_hook
) PARAMS ((void));
735 void (*target_wait_loop_hook
) PARAMS ((void));
739 /* These are the threads which we last sent to the remote system.
740 -1 for all or -2 for not sent yet. */
741 static int general_thread
;
742 static int continue_thread
;
744 /* Call this function as a result of
745 1) A halt indication (T packet) containing a thread id
746 2) A direct query of currthread
747 3) Successful execution of set thread
751 record_currthread (currthread
)
754 general_thread
= currthread
;
756 /* If this is a new thread, add it to GDB's thread list.
757 If we leave it up to WFI to do this, bad things will happen. */
758 if (!in_thread_list (currthread
))
760 add_thread (currthread
);
761 printf_filtered ("[New %s]\n", target_pid_to_str (currthread
));
765 #define MAGIC_NULL_PID 42000
772 char *buf
= alloca (PBUFSIZ
);
773 int state
= gen
? general_thread
: continue_thread
;
779 buf
[1] = gen
? 'g' : 'c';
780 if (th
== MAGIC_NULL_PID
)
786 sprintf (&buf
[2], "-%x", -th
);
788 sprintf (&buf
[2], "%x", th
);
790 getpkt (buf
, PBUFSIZ
, 0);
794 continue_thread
= th
;
797 /* Return nonzero if the thread TH is still alive on the remote system. */
800 remote_thread_alive (tid
)
806 sprintf (buf
, "T-%08x", -tid
);
808 sprintf (buf
, "T%08x", tid
);
810 getpkt (buf
, sizeof (buf
), 0);
811 return (buf
[0] == 'O' && buf
[1] == 'K');
814 /* About these extended threadlist and threadinfo packets. They are
815 variable length packets but, the fields within them are often fixed
816 length. They are redundent enough to send over UDP as is the
817 remote protocol in general. There is a matching unit test module
820 #define OPAQUETHREADBYTES 8
822 /* a 64 bit opaque identifier */
823 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
825 /* WARNING: This threadref data structure comes from the remote O.S., libstub
826 protocol encoding, and remote.c. it is not particularly changable */
828 /* Right now, the internal structure is int. We want it to be bigger.
832 typedef int gdb_threadref
; /* internal GDB thread reference */
834 /* gdb_ext_thread_info is an internal GDB data structure which is
835 equivalint to the reply of the remote threadinfo packet */
837 struct gdb_ext_thread_info
839 threadref threadid
; /* External form of thread reference */
840 int active
; /* Has state interesting to GDB? , regs, stack */
841 char display
[256]; /* Brief state display, name, blocked/syspended */
842 char shortname
[32]; /* To be used to name threads */
843 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
846 /* The volume of remote transfers can be limited by submitting
847 a mask containing bits specifying the desired information.
848 Use a union of these values as the 'selection' parameter to
849 get_thread_info. FIXME: Make these TAG names more thread specific.
852 #define TAG_THREADID 1
854 #define TAG_DISPLAY 4
855 #define TAG_THREADNAME 8
856 #define TAG_MOREDISPLAY 16
858 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
860 char *unpack_varlen_hex
PARAMS ((char *buff
, int *result
));
862 static char *unpack_nibble
PARAMS ((char *buf
, int *val
));
864 static char *pack_nibble
PARAMS ((char *buf
, int nibble
));
866 static char *pack_hex_byte
PARAMS ((char *pkt
, int /*unsigned char */ byte
));
868 static char *unpack_byte
PARAMS ((char *buf
, int *value
));
870 static char *pack_int
PARAMS ((char *buf
, int value
));
872 static char *unpack_int
PARAMS ((char *buf
, int *value
));
874 static char *unpack_string
PARAMS ((char *src
, char *dest
, int length
));
876 static char *pack_threadid
PARAMS ((char *pkt
, threadref
* id
));
878 static char *unpack_threadid
PARAMS ((char *inbuf
, threadref
* id
));
880 void int_to_threadref
PARAMS ((threadref
* id
, int value
));
882 static int threadref_to_int
PARAMS ((threadref
* ref
));
884 static void copy_threadref
PARAMS ((threadref
* dest
, threadref
* src
));
886 static int threadmatch
PARAMS ((threadref
* dest
, threadref
* src
));
888 static char *pack_threadinfo_request
PARAMS ((char *pkt
, int mode
,
891 static int remote_unpack_thread_info_response
PARAMS ((char *pkt
,
892 threadref
* expectedref
,
893 struct gdb_ext_thread_info
* info
));
896 static int remote_get_threadinfo
PARAMS ((threadref
* threadid
,
897 int fieldset
, /*TAG mask */
898 struct gdb_ext_thread_info
* info
));
900 static int adapt_remote_get_threadinfo
PARAMS ((gdb_threadref
* ref
,
902 struct gdb_ext_thread_info
* info
));
904 static char *pack_threadlist_request
PARAMS ((char *pkt
, int startflag
,
906 threadref
* nextthread
));
908 static int parse_threadlist_response
PARAMS ((char *pkt
,
910 threadref
* original_echo
,
911 threadref
* resultlist
,
914 static int remote_get_threadlist
PARAMS ((int startflag
,
915 threadref
* nextthread
,
919 threadref
* threadlist
));
921 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
923 static int remote_threadlist_iterator
PARAMS ((rmt_thread_action stepfunction
,
924 void *context
, int looplimit
));
926 static int remote_newthread_step
PARAMS ((threadref
* ref
, void *context
));
928 /* encode 64 bits in 16 chars of hex */
930 static const char hexchars
[] = "0123456789abcdef";
937 if ((ch
>= 'a') && (ch
<= 'f'))
939 *val
= ch
- 'a' + 10;
942 if ((ch
>= 'A') && (ch
<= 'F'))
944 *val
= ch
- 'A' + 10;
947 if ((ch
>= '0') && (ch
<= '9'))
959 if (ch
>= 'a' && ch
<= 'f')
960 return ch
- 'a' + 10;
961 if (ch
>= '0' && ch
<= '9')
963 if (ch
>= 'A' && ch
<= 'F')
964 return ch
- 'A' + 10;
969 stub_unpack_int (buff
, fieldlength
)
978 nibble
= stubhex (*buff
++);
982 retval
= retval
<< 4;
988 unpack_varlen_hex (buff
, result
)
989 char *buff
; /* packet to parse */
995 while (ishex (*buff
, &nibble
))
998 retval
= retval
<< 4;
999 retval
|= nibble
& 0x0f;
1006 unpack_nibble (buf
, val
)
1010 ishex (*buf
++, val
);
1015 pack_nibble (buf
, nibble
)
1019 *buf
++ = hexchars
[(nibble
& 0x0f)];
1024 pack_hex_byte (pkt
, byte
)
1028 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1029 *pkt
++ = hexchars
[(byte
& 0xf)];
1034 unpack_byte (buf
, value
)
1038 *value
= stub_unpack_int (buf
, 2);
1043 pack_int (buf
, value
)
1047 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1048 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1049 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1050 buf
= pack_hex_byte (buf
, (value
& 0xff));
1055 unpack_int (buf
, value
)
1059 *value
= stub_unpack_int (buf
, 8);
1063 #if 0 /* currently unused, uncomment when needed */
1064 static char *pack_string
PARAMS ((char *pkt
, char *string
));
1067 pack_string (pkt
, string
)
1074 len
= strlen (string
);
1076 len
= 200; /* Bigger than most GDB packets, junk??? */
1077 pkt
= pack_hex_byte (pkt
, len
);
1081 if ((ch
== '\0') || (ch
== '#'))
1082 ch
= '*'; /* Protect encapsulation */
1087 #endif /* 0 (unused) */
1090 unpack_string (src
, dest
, length
)
1102 pack_threadid (pkt
, id
)
1107 unsigned char *altid
;
1109 altid
= (unsigned char *) id
;
1110 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1112 pkt
= pack_hex_byte (pkt
, *altid
++);
1118 unpack_threadid (inbuf
, id
)
1123 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1126 altref
= (char *) id
;
1128 while (inbuf
< limit
)
1130 x
= stubhex (*inbuf
++);
1131 y
= stubhex (*inbuf
++);
1132 *altref
++ = (x
<< 4) | y
;
1137 /* Externally, threadrefs are 64 bits but internally, they are still
1138 ints. This is due to a mismatch of specifications. We would like
1139 to use 64bit thread references internally. This is an adapter
1143 int_to_threadref (id
, value
)
1147 unsigned char *scan
;
1149 scan
= (unsigned char *) id
;
1155 *scan
++ = (value
>> 24) & 0xff;
1156 *scan
++ = (value
>> 16) & 0xff;
1157 *scan
++ = (value
>> 8) & 0xff;
1158 *scan
++ = (value
& 0xff);
1162 threadref_to_int (ref
)
1166 unsigned char *scan
;
1168 scan
= (char *) ref
;
1172 value
= (value
<< 8) | ((*scan
++) & 0xff);
1177 copy_threadref (dest
, src
)
1182 unsigned char *csrc
, *cdest
;
1184 csrc
= (unsigned char *) src
;
1185 cdest
= (unsigned char *) dest
;
1192 threadmatch (dest
, src
)
1196 /* things are broken right now, so just assume we got a match */
1198 unsigned char *srcp
, *destp
;
1200 srcp
= (char *) src
;
1201 destp
= (char *) dest
;
1205 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1212 threadid:1, # always request threadid
1219 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1222 pack_threadinfo_request (pkt
, mode
, id
)
1227 *pkt
++ = 'q'; /* Info Query */
1228 *pkt
++ = 'P'; /* process or thread info */
1229 pkt
= pack_int (pkt
, mode
); /* mode */
1230 pkt
= pack_threadid (pkt
, id
); /* threadid */
1231 *pkt
= '\0'; /* terminate */
1235 /* These values tag the fields in a thread info response packet */
1236 /* Tagging the fields allows us to request specific fields and to
1237 add more fields as time goes by */
1239 #define TAG_THREADID 1 /* Echo the thread identifier */
1240 #define TAG_EXISTS 2 /* Is this process defined enough to
1241 fetch registers and its stack */
1242 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1243 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1244 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1248 remote_unpack_thread_info_response (pkt
, expectedref
, info
)
1250 threadref
*expectedref
;
1251 struct gdb_ext_thread_info
*info
;
1256 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
1259 /* info->threadid = 0; FIXME: implement zero_threadref */
1261 info
->display
[0] = '\0';
1262 info
->shortname
[0] = '\0';
1263 info
->more_display
[0] = '\0';
1265 /* Assume the characters indicating the packet type have been stripped */
1266 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1267 pkt
= unpack_threadid (pkt
, &ref
);
1270 warning ("Incomplete response to threadinfo request\n");
1271 if (!threadmatch (&ref
, expectedref
))
1272 { /* This is an answer to a different request */
1273 warning ("ERROR RMT Thread info mismatch\n");
1276 copy_threadref (&info
->threadid
, &ref
);
1278 /* Loop on tagged fields , try to bail if somthing goes wrong */
1280 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1282 pkt
= unpack_int (pkt
, &tag
); /* tag */
1283 pkt
= unpack_byte (pkt
, &length
); /* length */
1284 if (!(tag
& mask
)) /* tags out of synch with mask */
1286 warning ("ERROR RMT: threadinfo tag mismatch\n");
1290 if (tag
== TAG_THREADID
)
1294 warning ("ERROR RMT: length of threadid is not 16\n");
1298 pkt
= unpack_threadid (pkt
, &ref
);
1299 mask
= mask
& ~TAG_THREADID
;
1302 if (tag
== TAG_EXISTS
)
1304 info
->active
= stub_unpack_int (pkt
, length
);
1306 mask
= mask
& ~(TAG_EXISTS
);
1309 warning ("ERROR RMT: 'exists' length too long\n");
1315 if (tag
== TAG_THREADNAME
)
1317 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1318 mask
= mask
& ~TAG_THREADNAME
;
1321 if (tag
== TAG_DISPLAY
)
1323 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1324 mask
= mask
& ~TAG_DISPLAY
;
1327 if (tag
== TAG_MOREDISPLAY
)
1329 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1330 mask
= mask
& ~TAG_MOREDISPLAY
;
1333 warning ("ERROR RMT: unknown thread info tag\n");
1334 break; /* Not a tag we know about */
1340 remote_get_threadinfo (threadid
, fieldset
, info
)
1341 threadref
*threadid
;
1342 int fieldset
; /* TAG mask */
1343 struct gdb_ext_thread_info
*info
;
1346 char *threadinfo_pkt
= alloca (PBUFSIZ
);
1348 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1349 putpkt (threadinfo_pkt
);
1350 getpkt (threadinfo_pkt
, PBUFSIZ
, 0);
1351 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1356 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1357 representation of a threadid. */
1360 adapt_remote_get_threadinfo (ref
, selection
, info
)
1363 struct gdb_ext_thread_info
*info
;
1367 int_to_threadref (&lclref
, *ref
);
1368 return remote_get_threadinfo (&lclref
, selection
, info
);
1371 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1374 pack_threadlist_request (pkt
, startflag
, threadcount
, nextthread
)
1378 threadref
*nextthread
;
1380 *pkt
++ = 'q'; /* info query packet */
1381 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1382 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1383 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1384 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1389 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1392 parse_threadlist_response (pkt
, result_limit
, original_echo
, resultlist
,
1396 threadref
*original_echo
;
1397 threadref
*resultlist
;
1401 int count
, resultcount
, done
;
1404 /* Assume the 'q' and 'M chars have been stripped. */
1405 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1406 pkt
= unpack_byte (pkt
, &count
); /* count field */
1407 pkt
= unpack_nibble (pkt
, &done
);
1408 /* The first threadid is the argument threadid. */
1409 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1410 while ((count
-- > 0) && (pkt
< limit
))
1412 pkt
= unpack_threadid (pkt
, resultlist
++);
1413 if (resultcount
++ >= result_limit
)
1422 remote_get_threadlist (startflag
, nextthread
, result_limit
,
1423 done
, result_count
, threadlist
)
1425 threadref
*nextthread
;
1429 threadref
*threadlist
;
1432 static threadref echo_nextthread
;
1433 char *threadlist_packet
= alloca (PBUFSIZ
);
1434 char *t_response
= alloca (PBUFSIZ
);
1437 /* Trancate result limit to be smaller than the packet size */
1438 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1439 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1441 pack_threadlist_request (threadlist_packet
,
1442 startflag
, result_limit
, nextthread
);
1443 putpkt (threadlist_packet
);
1444 getpkt (t_response
, PBUFSIZ
, 0);
1447 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1450 if (!threadmatch (&echo_nextthread
, nextthread
))
1452 /* FIXME: This is a good reason to drop the packet */
1453 /* Possably, there is a duplicate response */
1455 retransmit immediatly - race conditions
1456 retransmit after timeout - yes
1458 wait for packet, then exit
1460 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1461 return 0; /* I choose simply exiting */
1463 if (*result_count
<= 0)
1467 warning ("RMT ERROR : failed to get remote thread list\n");
1470 return result
; /* break; */
1472 if (*result_count
> result_limit
)
1475 warning ("RMT ERROR: threadlist response longer than requested\n");
1481 /* This is the interface between remote and threads, remotes upper interface */
1483 /* remote_find_new_threads retrieves the thread list and for each
1484 thread in the list, looks up the thread in GDB's internal list,
1485 ading the thread if it does not already exist. This involves
1486 getting partial thread lists from the remote target so, polling the
1487 quit_flag is required. */
1490 /* About this many threadisds fit in a packet. */
1492 #define MAXTHREADLISTRESULTS 32
1495 remote_threadlist_iterator (stepfunction
, context
, looplimit
)
1496 rmt_thread_action stepfunction
;
1500 int done
, i
, result_count
;
1504 static threadref nextthread
;
1505 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1510 if (loopcount
++ > looplimit
)
1513 warning ("Remote fetch threadlist -infinite loop-\n");
1516 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1517 &done
, &result_count
, resultthreadlist
))
1522 /* clear for later iterations */
1524 /* Setup to resume next batch of thread references, set nextthread. */
1525 if (result_count
>= 1)
1526 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1528 while (result_count
--)
1529 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1536 remote_newthread_step (ref
, context
)
1542 pid
= threadref_to_int (ref
);
1543 if (!in_thread_list (pid
))
1545 return 1; /* continue iterator */
1548 #define CRAZY_MAX_THREADS 1000
1551 remote_current_thread (oldpid
)
1554 char *buf
= alloca (PBUFSIZ
);
1557 getpkt (buf
, PBUFSIZ
, 0);
1558 if (buf
[0] == 'Q' && buf
[1] == 'C')
1559 return strtol (&buf
[2], NULL
, 16);
1564 /* Find new threads for info threads command. */
1567 remote_find_new_threads ()
1569 remote_threadlist_iterator (remote_newthread_step
, 0,
1571 if (inferior_pid
== MAGIC_NULL_PID
) /* ack ack ack */
1572 inferior_pid
= remote_current_thread (inferior_pid
);
1576 remote_threads_info (void)
1578 char *buf
= alloca (PBUFSIZ
);
1582 if (remote_desc
== 0) /* paranoia */
1583 error ("Command can only be used when connected to the remote target.");
1585 putpkt ("qfThreadInfo");
1587 getpkt (bufp
, PBUFSIZ
, 0);
1588 if (bufp
[0] == '\0') /* q packet not recognized! */
1589 { /* try old jmetzler method */
1590 remote_find_new_threads ();
1593 else /* try new 'q' method */
1594 while (*bufp
++ == 'm') /* reply contains one or more TID */
1598 tid
= strtol (bufp
, &bufp
, 16);
1599 if (tid
!= 0 && !in_thread_list (tid
))
1602 while (*bufp
++ == ','); /* comma-separated list */
1603 putpkt ("qsThreadInfo");
1605 getpkt (bufp
, PBUFSIZ
, 0);
1610 /* Restart the remote side; this is an extended protocol operation. */
1613 extended_remote_restart ()
1615 char *buf
= alloca (PBUFSIZ
);
1617 /* Send the restart command; for reasons I don't understand the
1618 remote side really expects a number after the "R". */
1620 sprintf (&buf
[1], "%x", 0);
1623 /* Now query for status so this looks just like we restarted
1624 gdbserver from scratch. */
1626 getpkt (buf
, PBUFSIZ
, 0);
1629 /* Clean up connection to a remote debugger. */
1633 remote_close (quitting
)
1637 SERIAL_CLOSE (remote_desc
);
1641 /* Query the remote side for the text, data and bss offsets. */
1646 char *buf
= alloca (PBUFSIZ
);
1649 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1650 struct section_offsets
*offs
;
1652 putpkt ("qOffsets");
1654 getpkt (buf
, PBUFSIZ
, 0);
1656 if (buf
[0] == '\000')
1657 return; /* Return silently. Stub doesn't support
1661 warning ("Remote failure reply: %s", buf
);
1665 /* Pick up each field in turn. This used to be done with scanf, but
1666 scanf will make trouble if CORE_ADDR size doesn't match
1667 conversion directives correctly. The following code will work
1668 with any size of CORE_ADDR. */
1669 text_addr
= data_addr
= bss_addr
= 0;
1673 if (strncmp (ptr
, "Text=", 5) == 0)
1676 /* Don't use strtol, could lose on big values. */
1677 while (*ptr
&& *ptr
!= ';')
1678 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1683 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1686 while (*ptr
&& *ptr
!= ';')
1687 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1692 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1695 while (*ptr
&& *ptr
!= ';')
1696 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1702 error ("Malformed response to offset query, %s", buf
);
1704 if (symfile_objfile
== NULL
)
1707 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1708 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1710 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
1712 /* This is a temporary kludge to force data and bss to use the same offsets
1713 because that's what nlmconv does now. The real solution requires changes
1714 to the stub and remote.c that I don't have time to do right now. */
1716 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
1717 ANOFFSET (offs
, SECT_OFF_BSS
) = data_addr
;
1719 objfile_relocate (symfile_objfile
, offs
);
1723 * Cisco version of section offsets:
1725 * Instead of having GDB query the target for the section offsets,
1726 * Cisco lets the target volunteer the information! It's also in
1727 * a different format, so here are the functions that will decode
1728 * a section offset packet from a Cisco target.
1732 * Function: remote_cisco_section_offsets
1734 * Returns: zero for success, non-zero for failure
1738 remote_cisco_section_offsets (bfd_vma text_addr
,
1741 bfd_signed_vma
*text_offs
,
1742 bfd_signed_vma
*data_offs
,
1743 bfd_signed_vma
*bss_offs
)
1745 bfd_vma text_base
, data_base
, bss_base
;
1746 struct minimal_symbol
*start
;
1752 if (symfile_objfile
== NULL
)
1753 return -1; /* no can do nothin' */
1755 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
1757 return -1; /* Can't find "_start" symbol */
1759 data_base
= bss_base
= 0;
1760 text_base
= SYMBOL_VALUE_ADDRESS (start
);
1762 abfd
= symfile_objfile
->obfd
;
1763 for (sect
= abfd
->sections
;
1767 p
= (unsigned char *) bfd_get_section_name (abfd
, sect
);
1769 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
1770 if (data_base
== 0 ||
1771 data_base
> bfd_get_section_vma (abfd
, sect
))
1772 data_base
= bfd_get_section_vma (abfd
, sect
);
1773 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
1774 if (bss_base
== 0 ||
1775 bss_base
> bfd_get_section_vma (abfd
, sect
))
1776 bss_base
= bfd_get_section_vma (abfd
, sect
);
1778 *text_offs
= text_addr
- text_base
;
1779 *data_offs
= data_addr
- data_base
;
1780 *bss_offs
= bss_addr
- bss_base
;
1785 sprintf (tmp
, "VMA: text = 0x");
1786 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
1787 sprintf (tmp
+ strlen (tmp
), " data = 0x");
1788 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
1789 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
1790 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
1791 fprintf_filtered (gdb_stdlog
, tmp
);
1792 fprintf_filtered (gdb_stdlog
,
1793 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
1794 paddr_nz (*text_offs
),
1795 paddr_nz (*data_offs
),
1796 paddr_nz (*bss_offs
));
1803 * Function: remote_cisco_objfile_relocate
1805 * Relocate the symbol file for a remote target.
1809 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
)
1810 bfd_signed_vma text_off
;
1811 bfd_signed_vma data_off
;
1812 bfd_signed_vma bss_off
;
1814 struct section_offsets
*offs
;
1816 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
1818 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1819 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1820 simple canonical representation for this stuff. */
1822 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1823 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1825 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_off
;
1826 ANOFFSET (offs
, SECT_OFF_DATA
) = data_off
;
1827 ANOFFSET (offs
, SECT_OFF_BSS
) = bss_off
;
1829 /* First call the standard objfile_relocate. */
1830 objfile_relocate (symfile_objfile
, offs
);
1832 /* Now we need to fix up the section entries already attached to
1833 the exec target. These entries will control memory transfers
1834 from the exec file. */
1836 exec_set_section_offsets (text_off
, data_off
, bss_off
);
1840 /* Stub for catch_errors. */
1843 remote_start_remote_dummy (void *dummy
)
1845 start_remote (); /* Initialize gdb process mechanisms */
1850 remote_start_remote (dummy
)
1853 immediate_quit
= 1; /* Allow user to interrupt it */
1855 /* Ack any packet which the remote side has already sent. */
1856 SERIAL_WRITE (remote_desc
, "+", 1);
1858 /* Let the stub know that we want it to return the thread. */
1861 inferior_pid
= remote_current_thread (inferior_pid
);
1863 get_offsets (); /* Get text, data & bss offsets */
1865 putpkt ("?"); /* initiate a query from remote machine */
1868 return remote_start_remote_dummy (dummy
);
1871 /* Open a connection to a remote debugger.
1872 NAME is the filename used for communication. */
1875 remote_open (name
, from_tty
)
1879 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
1882 /* Just like remote_open, but with asynchronous support. */
1884 remote_async_open (name
, from_tty
)
1888 remote_async_open_1 (name
, from_tty
, &remote_async_ops
, 0);
1891 /* Open a connection to a remote debugger using the extended
1892 remote gdb protocol. NAME is the filename used for communication. */
1895 extended_remote_open (name
, from_tty
)
1899 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */ );
1902 /* Just like extended_remote_open, but with asynchronous support. */
1904 extended_remote_async_open (name
, from_tty
)
1908 remote_async_open_1 (name
, from_tty
, &extended_async_remote_ops
, 1 /*extended_p */ );
1911 /* Generic code for opening a connection to a remote target. */
1913 static DCACHE
*remote_dcache
;
1916 remote_open_1 (name
, from_tty
, target
, extended_p
)
1919 struct target_ops
*target
;
1923 error ("To open a remote debug connection, you need to specify what\n\
1924 serial device is attached to the remote system (e.g. /dev/ttya).");
1926 /* See FIXME above */
1927 wait_forever_enabled_p
= 1;
1929 target_preopen (from_tty
);
1931 unpush_target (target
);
1933 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1935 remote_desc
= SERIAL_OPEN (name
);
1937 perror_with_name (name
);
1939 if (baud_rate
!= -1)
1941 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1943 SERIAL_CLOSE (remote_desc
);
1944 perror_with_name (name
);
1948 SERIAL_RAW (remote_desc
);
1950 /* If there is something sitting in the buffer we might take it as a
1951 response to a command, which would be bad. */
1952 SERIAL_FLUSH_INPUT (remote_desc
);
1956 puts_filtered ("Remote debugging using ");
1957 puts_filtered (name
);
1958 puts_filtered ("\n");
1960 push_target (target
); /* Switch to using remote target now */
1962 init_packet_config (&remote_protocol_P
);
1963 init_packet_config (&remote_protocol_Z
);
1965 general_thread
= -2;
1966 continue_thread
= -2;
1968 /* Force remote_write_bytes to check whether target supports
1969 binary downloading. */
1970 init_packet_config (&remote_protocol_binary_download
);
1972 /* Without this, some commands which require an active target (such
1973 as kill) won't work. This variable serves (at least) double duty
1974 as both the pid of the target process (if it has such), and as a
1975 flag indicating that a target is active. These functions should
1976 be split out into seperate variables, especially since GDB will
1977 someday have a notion of debugging several processes. */
1979 inferior_pid
= MAGIC_NULL_PID
;
1980 /* Start the remote connection; if error (0), discard this target.
1981 In particular, if the user quits, be sure to discard it
1982 (we'd be in an inconsistent state otherwise). */
1983 if (!catch_errors (remote_start_remote
, NULL
,
1984 "Couldn't establish connection to remote target\n",
1993 /* tell the remote that we're using the extended protocol. */
1994 char *buf
= alloca (PBUFSIZ
);
1996 getpkt (buf
, PBUFSIZ
, 0);
2000 /* Just like remote_open but with asynchronous support. */
2002 remote_async_open_1 (name
, from_tty
, target
, extended_p
)
2005 struct target_ops
*target
;
2009 error ("To open a remote debug connection, you need to specify what\n\
2010 serial device is attached to the remote system (e.g. /dev/ttya).");
2012 target_preopen (from_tty
);
2014 unpush_target (target
);
2016 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
2018 remote_desc
= SERIAL_OPEN (name
);
2020 perror_with_name (name
);
2022 if (baud_rate
!= -1)
2024 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
2026 SERIAL_CLOSE (remote_desc
);
2027 perror_with_name (name
);
2031 SERIAL_RAW (remote_desc
);
2033 /* If there is something sitting in the buffer we might take it as a
2034 response to a command, which would be bad. */
2035 SERIAL_FLUSH_INPUT (remote_desc
);
2039 puts_filtered ("Remote debugging using ");
2040 puts_filtered (name
);
2041 puts_filtered ("\n");
2044 push_target (target
); /* Switch to using remote target now */
2046 init_packet_config (&remote_protocol_P
);
2047 init_packet_config (&remote_protocol_Z
);
2049 general_thread
= -2;
2050 continue_thread
= -2;
2052 /* Force remote_write_bytes to check whether target supports
2053 binary downloading. */
2054 init_packet_config (&remote_protocol_binary_download
);
2056 /* Without this, some commands which require an active target (such
2057 as kill) won't work. This variable serves (at least) double duty
2058 as both the pid of the target process (if it has such), and as a
2059 flag indicating that a target is active. These functions should
2060 be split out into seperate variables, especially since GDB will
2061 someday have a notion of debugging several processes. */
2062 inferior_pid
= MAGIC_NULL_PID
;
2064 /* With this target we start out by owning the terminal. */
2065 remote_async_terminal_ours_p
= 1;
2067 /* FIXME: cagney/1999-09-23: During the initial connection it is
2068 assumed that the target is already ready and able to respond to
2069 requests. Unfortunatly remote_start_remote() eventually calls
2070 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2071 around this. Eventually a mechanism that allows
2072 wait_for_inferior() to expect/get timeouts will be
2074 wait_forever_enabled_p
= 0;
2076 /* Start the remote connection; if error (0), discard this target.
2077 In particular, if the user quits, be sure to discard it
2078 (we'd be in an inconsistent state otherwise). */
2079 if (!catch_errors (remote_start_remote
, NULL
,
2080 "Couldn't establish connection to remote target\n",
2084 wait_forever_enabled_p
= 1;
2088 wait_forever_enabled_p
= 1;
2092 /* tell the remote that we're using the extended protocol. */
2093 char *buf
= alloca (PBUFSIZ
);
2095 getpkt (buf
, PBUFSIZ
, 0);
2099 /* This takes a program previously attached to and detaches it. After
2100 this is done, GDB can be used to debug some other program. We
2101 better not have left any breakpoints in the target program or it'll
2102 die when it hits one. */
2105 remote_detach (args
, from_tty
)
2109 char *buf
= alloca (PBUFSIZ
);
2112 error ("Argument given to \"detach\" when remotely debugging.");
2114 /* Tell the remote target to detach. */
2116 remote_send (buf
, PBUFSIZ
);
2120 puts_filtered ("Ending remote debugging.\n");
2124 /* Same as remote_detach, but with async support. */
2126 remote_async_detach (args
, from_tty
)
2130 char *buf
= alloca (PBUFSIZ
);
2133 error ("Argument given to \"detach\" when remotely debugging.");
2135 /* Tell the remote target to detach. */
2137 remote_send (buf
, PBUFSIZ
);
2139 /* Unregister the file descriptor from the event loop. */
2140 if (SERIAL_IS_ASYNC_P (remote_desc
))
2141 SERIAL_ASYNC (remote_desc
, NULL
, 0);
2145 puts_filtered ("Ending remote debugging.\n");
2148 /* Convert hex digit A to a number. */
2154 if (a
>= '0' && a
<= '9')
2156 else if (a
>= 'a' && a
<= 'f')
2157 return a
- 'a' + 10;
2158 else if (a
>= 'A' && a
<= 'F')
2159 return a
- 'A' + 10;
2161 error ("Reply contains invalid hex digit %d", a
);
2164 /* Convert number NIB to a hex digit. */
2173 return 'a' + nib
- 10;
2176 /* Tell the remote machine to resume. */
2178 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2180 static int last_sent_step
;
2183 remote_resume (pid
, step
, siggnal
)
2185 enum target_signal siggnal
;
2187 char *buf
= alloca (PBUFSIZ
);
2190 set_thread (0, 0); /* run any thread */
2192 set_thread (pid
, 0); /* run this thread */
2194 dcache_flush (remote_dcache
);
2196 last_sent_signal
= siggnal
;
2197 last_sent_step
= step
;
2199 /* A hook for when we need to do something at the last moment before
2201 if (target_resume_hook
)
2202 (*target_resume_hook
) ();
2204 if (siggnal
!= TARGET_SIGNAL_0
)
2206 buf
[0] = step
? 'S' : 'C';
2207 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2208 buf
[2] = tohex ((int) siggnal
& 0xf);
2212 strcpy (buf
, step
? "s" : "c");
2217 /* Same as remote_resume, but with async support. */
2219 remote_async_resume (pid
, step
, siggnal
)
2221 enum target_signal siggnal
;
2223 char *buf
= alloca (PBUFSIZ
);
2226 set_thread (0, 0); /* run any thread */
2228 set_thread (pid
, 0); /* run this thread */
2230 dcache_flush (remote_dcache
);
2232 last_sent_signal
= siggnal
;
2233 last_sent_step
= step
;
2235 /* A hook for when we need to do something at the last moment before
2237 if (target_resume_hook
)
2238 (*target_resume_hook
) ();
2240 if (siggnal
!= TARGET_SIGNAL_0
)
2242 buf
[0] = step
? 'S' : 'C';
2243 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2244 buf
[2] = tohex ((int) siggnal
& 0xf);
2248 strcpy (buf
, step
? "s" : "c");
2250 /* We are about to start executing the inferior, let's register it
2251 with the event loop. NOTE: this is the one place where all the
2252 execution commands end up. We could alternatively do this in each
2253 of the execution commands in infcmd.c.*/
2254 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2255 into infcmd.c in order to allow inferior function calls to work
2256 NOT asynchronously. */
2257 if (event_loop_p
&& SERIAL_CAN_ASYNC_P (remote_desc
))
2258 target_async (inferior_event_handler
, 0);
2259 /* Tell the world that the target is now executing. */
2260 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2261 this? Instead, should the client of target just assume (for
2262 async targets) that the target is going to start executing? Is
2263 this information already found in the continuation block? */
2264 if (SERIAL_IS_ASYNC_P (remote_desc
))
2265 target_executing
= 1;
2270 /* Set up the signal handler for SIGINT, while the target is
2271 executing, ovewriting the 'regular' SIGINT signal handler. */
2273 initialize_sigint_signal_handler ()
2275 sigint_remote_token
=
2276 create_async_signal_handler (async_remote_interrupt
, NULL
);
2277 signal (SIGINT
, handle_remote_sigint
);
2280 /* Signal handler for SIGINT, while the target is executing. */
2282 handle_remote_sigint (sig
)
2285 signal (sig
, handle_remote_sigint_twice
);
2286 sigint_remote_twice_token
=
2287 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2288 mark_async_signal_handler_wrapper (sigint_remote_token
);
2291 /* Signal handler for SIGINT, installed after SIGINT has already been
2292 sent once. It will take effect the second time that the user sends
2295 handle_remote_sigint_twice (sig
)
2298 signal (sig
, handle_sigint
);
2299 sigint_remote_twice_token
=
2300 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2301 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2304 /* Perform the real interruption of the target execution, in response
2307 async_remote_interrupt (arg
)
2308 gdb_client_data arg
;
2311 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2316 /* Perform interrupt, if the first attempt did not succeed. Just give
2317 up on the target alltogether. */
2319 async_remote_interrupt_twice (arg
)
2320 gdb_client_data arg
;
2323 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2324 /* Do something only if the target was not killed by the previous
2326 if (target_executing
)
2329 signal (SIGINT
, handle_remote_sigint
);
2333 /* Reinstall the usual SIGINT handlers, after the target has
2336 cleanup_sigint_signal_handler (void *dummy
)
2338 signal (SIGINT
, handle_sigint
);
2339 if (sigint_remote_twice_token
)
2340 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2341 if (sigint_remote_token
)
2342 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2345 /* Send ^C to target to halt it. Target will respond, and send us a
2347 static void (*ofunc
) PARAMS ((int));
2349 /* The command line interface's stop routine. This function is installed
2350 as a signal handler for SIGINT. The first time a user requests a
2351 stop, we call remote_stop to send a break or ^C. If there is no
2352 response from the target (it didn't stop when the user requested it),
2353 we ask the user if he'd like to detach from the target. */
2355 remote_interrupt (signo
)
2358 /* If this doesn't work, try more severe steps. */
2359 signal (signo
, remote_interrupt_twice
);
2362 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2367 /* The user typed ^C twice. */
2370 remote_interrupt_twice (signo
)
2373 signal (signo
, ofunc
);
2375 signal (signo
, remote_interrupt
);
2378 /* This is the generic stop called via the target vector. When a target
2379 interrupt is requested, either by the command line or the GUI, we
2380 will eventually end up here. */
2384 /* Send a break or a ^C, depending on user preference. */
2386 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2389 SERIAL_SEND_BREAK (remote_desc
);
2391 SERIAL_WRITE (remote_desc
, "\003", 1);
2394 /* Ask the user what to do when an interrupt is received. */
2399 target_terminal_ours ();
2401 if (query ("Interrupted while waiting for the program.\n\
2402 Give up (and stop debugging it)? "))
2404 target_mourn_inferior ();
2405 return_to_top_level (RETURN_QUIT
);
2408 target_terminal_inferior ();
2411 /* Enable/disable target terminal ownership. Most targets can use
2412 terminal groups to control terminal ownership. Remote targets are
2413 different in that explicit transfer of ownership to/from GDB/target
2417 remote_async_terminal_inferior (void)
2419 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2420 sync_execution here. This function should only be called when
2421 GDB is resuming the inferior in the forground. A background
2422 resume (``run&'') should leave GDB in control of the terminal and
2423 consequently should not call this code. */
2424 if (!sync_execution
)
2426 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2427 calls target_terminal_*() idenpotent. The event-loop GDB talking
2428 to an asynchronous target with a synchronous command calls this
2429 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2430 stops trying to transfer the terminal to the target when it
2431 shouldn't this guard can go away. */
2432 if (!remote_async_terminal_ours_p
)
2434 delete_file_handler (input_fd
);
2435 remote_async_terminal_ours_p
= 0;
2436 initialize_sigint_signal_handler ();
2437 /* NOTE: At this point we could also register our selves as the
2438 recipient of all input. Any characters typed could then be
2439 passed on down to the target. */
2443 remote_async_terminal_ours (void)
2445 /* See FIXME in remote_async_terminal_inferior. */
2446 if (!sync_execution
)
2448 /* See FIXME in remote_async_terminal_inferior. */
2449 if (remote_async_terminal_ours_p
)
2451 cleanup_sigint_signal_handler (NULL
);
2452 add_file_handler (input_fd
, stdin_event_handler
, 0);
2453 remote_async_terminal_ours_p
= 1;
2456 /* If nonzero, ignore the next kill. */
2461 remote_console_output (char *msg
)
2465 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2468 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2471 fputs_unfiltered (tb
, gdb_stdtarg
);
2473 gdb_flush (gdb_stdtarg
);
2476 /* Wait until the remote machine stops, then return,
2477 storing status in STATUS just as `wait' would.
2478 Returns "pid", which in the case of a multi-threaded
2479 remote OS, is the thread-id. */
2482 remote_wait (pid
, status
)
2484 struct target_waitstatus
*status
;
2486 unsigned char *buf
= alloca (PBUFSIZ
);
2487 int thread_num
= -1;
2489 status
->kind
= TARGET_WAITKIND_EXITED
;
2490 status
->value
.integer
= 0;
2496 ofunc
= signal (SIGINT
, remote_interrupt
);
2497 getpkt (buf
, PBUFSIZ
, 1);
2498 signal (SIGINT
, ofunc
);
2500 /* This is a hook for when we need to do something (perhaps the
2501 collection of trace data) every time the target stops. */
2502 if (target_wait_loop_hook
)
2503 (*target_wait_loop_hook
) ();
2507 case 'E': /* Error of some sort */
2508 warning ("Remote failure reply: %s", buf
);
2510 case 'T': /* Status with PC, SP, FP, ... */
2514 char regs
[MAX_REGISTER_RAW_SIZE
];
2516 /* Expedited reply, containing Signal, {regno, reg} repeat */
2517 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2519 n... = register number
2520 r... = register contents
2522 p
= &buf
[3]; /* after Txx */
2529 /* Read the register number */
2530 regno
= strtol ((const char *) p
, &p_temp
, 16);
2531 p1
= (unsigned char *) p_temp
;
2533 if (p1
== p
) /* No register number present here */
2535 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2537 warning ("Malformed packet(a) (missing colon): %s\n\
2540 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2542 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2543 record_currthread (thread_num
);
2544 p
= (unsigned char *) p_temp
;
2552 warning ("Malformed packet(b) (missing colon): %s\n\
2556 if (regno
>= NUM_REGS
)
2557 warning ("Remote sent bad register number %ld: %s\n\
2561 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2563 if (p
[0] == 0 || p
[1] == 0)
2564 warning ("Remote reply is too short: %s", buf
);
2565 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2568 supply_register (regno
, regs
);
2573 warning ("Remote register badly formatted: %s", buf
);
2574 warning (" here: %s", p
);
2579 case 'S': /* Old style status, just signal only */
2580 status
->kind
= TARGET_WAITKIND_STOPPED
;
2581 status
->value
.sig
= (enum target_signal
)
2582 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2586 /* Export Cisco kernel mode as a convenience variable
2587 (so that it can be used in the GDB prompt if desired). */
2589 if (cisco_kernel_mode
== 1)
2590 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2591 value_from_string ("PDEBUG-"));
2592 cisco_kernel_mode
= 0;
2593 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2594 record_currthread (thread_num
);
2596 else if (buf
[3] == 'k')
2598 /* Export Cisco kernel mode as a convenience variable
2599 (so that it can be used in the GDB prompt if desired). */
2601 if (cisco_kernel_mode
== 1)
2602 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2603 value_from_string ("KDEBUG-"));
2604 cisco_kernel_mode
= 1;
2607 case 'N': /* Cisco special: status and offsets */
2609 bfd_vma text_addr
, data_addr
, bss_addr
;
2610 bfd_signed_vma text_off
, data_off
, bss_off
;
2613 status
->kind
= TARGET_WAITKIND_STOPPED
;
2614 status
->value
.sig
= (enum target_signal
)
2615 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2617 if (symfile_objfile
== NULL
)
2619 warning ("Relocation packet received with no symbol file. \
2624 /* Relocate object file. Buffer format is NAATT;DD;BB
2625 * where AA is the signal number, TT is the new text
2626 * address, DD * is the new data address, and BB is the
2627 * new bss address. */
2630 text_addr
= strtoul (p
, (char **) &p1
, 16);
2631 if (p1
== p
|| *p1
!= ';')
2632 warning ("Malformed relocation packet: Packet '%s'", buf
);
2634 data_addr
= strtoul (p
, (char **) &p1
, 16);
2635 if (p1
== p
|| *p1
!= ';')
2636 warning ("Malformed relocation packet: Packet '%s'", buf
);
2638 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2640 warning ("Malformed relocation packet: Packet '%s'", buf
);
2642 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2643 &text_off
, &data_off
, &bss_off
)
2645 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2646 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2650 case 'W': /* Target exited */
2652 /* The remote process exited. */
2653 status
->kind
= TARGET_WAITKIND_EXITED
;
2654 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2658 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2659 status
->value
.sig
= (enum target_signal
)
2660 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2664 case 'O': /* Console output */
2665 remote_console_output (buf
+ 1);
2668 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2670 /* Zero length reply means that we tried 'S' or 'C' and
2671 the remote system doesn't support it. */
2672 target_terminal_ours_for_output ();
2674 ("Can't send signals to this remote system. %s not sent.\n",
2675 target_signal_to_name (last_sent_signal
));
2676 last_sent_signal
= TARGET_SIGNAL_0
;
2677 target_terminal_inferior ();
2679 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2680 putpkt ((char *) buf
);
2683 /* else fallthrough */
2685 warning ("Invalid remote reply: %s", buf
);
2690 if (thread_num
!= -1)
2694 return inferior_pid
;
2697 /* Async version of remote_wait. */
2699 remote_async_wait (pid
, status
)
2701 struct target_waitstatus
*status
;
2703 unsigned char *buf
= alloca (PBUFSIZ
);
2704 int thread_num
= -1;
2706 status
->kind
= TARGET_WAITKIND_EXITED
;
2707 status
->value
.integer
= 0;
2713 if (!SERIAL_IS_ASYNC_P (remote_desc
))
2714 ofunc
= signal (SIGINT
, remote_interrupt
);
2715 /* FIXME: cagney/1999-09-27: If we're in async mode we should
2716 _never_ wait for ever -> test on target_is_async_p().
2717 However, before we do that we need to ensure that the caller
2718 knows how to take the target into/out of async mode. */
2719 getpkt (buf
, PBUFSIZ
, wait_forever_enabled_p
);
2720 if (!SERIAL_IS_ASYNC_P (remote_desc
))
2721 signal (SIGINT
, ofunc
);
2723 /* This is a hook for when we need to do something (perhaps the
2724 collection of trace data) every time the target stops. */
2725 if (target_wait_loop_hook
)
2726 (*target_wait_loop_hook
) ();
2730 case 'E': /* Error of some sort */
2731 warning ("Remote failure reply: %s", buf
);
2733 case 'T': /* Status with PC, SP, FP, ... */
2737 char regs
[MAX_REGISTER_RAW_SIZE
];
2739 /* Expedited reply, containing Signal, {regno, reg} repeat */
2740 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2742 n... = register number
2743 r... = register contents
2745 p
= &buf
[3]; /* after Txx */
2752 /* Read the register number */
2753 regno
= strtol ((const char *) p
, &p_temp
, 16);
2754 p1
= (unsigned char *) p_temp
;
2756 if (p1
== p
) /* No register number present here */
2758 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2760 warning ("Malformed packet(a) (missing colon): %s\n\
2763 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2765 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2766 record_currthread (thread_num
);
2767 p
= (unsigned char *) p_temp
;
2775 warning ("Malformed packet(b) (missing colon): %s\n\
2779 if (regno
>= NUM_REGS
)
2780 warning ("Remote sent bad register number %ld: %s\n\
2784 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2786 if (p
[0] == 0 || p
[1] == 0)
2787 warning ("Remote reply is too short: %s", buf
);
2788 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2791 supply_register (regno
, regs
);
2796 warning ("Remote register badly formatted: %s", buf
);
2797 warning (" here: %s", p
);
2802 case 'S': /* Old style status, just signal only */
2803 status
->kind
= TARGET_WAITKIND_STOPPED
;
2804 status
->value
.sig
= (enum target_signal
)
2805 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2809 /* Export Cisco kernel mode as a convenience variable
2810 (so that it can be used in the GDB prompt if desired). */
2812 if (cisco_kernel_mode
== 1)
2813 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2814 value_from_string ("PDEBUG-"));
2815 cisco_kernel_mode
= 0;
2816 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2817 record_currthread (thread_num
);
2819 else if (buf
[3] == 'k')
2821 /* Export Cisco kernel mode as a convenience variable
2822 (so that it can be used in the GDB prompt if desired). */
2824 if (cisco_kernel_mode
== 1)
2825 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2826 value_from_string ("KDEBUG-"));
2827 cisco_kernel_mode
= 1;
2830 case 'N': /* Cisco special: status and offsets */
2832 bfd_vma text_addr
, data_addr
, bss_addr
;
2833 bfd_signed_vma text_off
, data_off
, bss_off
;
2836 status
->kind
= TARGET_WAITKIND_STOPPED
;
2837 status
->value
.sig
= (enum target_signal
)
2838 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2840 if (symfile_objfile
== NULL
)
2842 warning ("Relocation packet recieved with no symbol file. \
2847 /* Relocate object file. Buffer format is NAATT;DD;BB
2848 * where AA is the signal number, TT is the new text
2849 * address, DD * is the new data address, and BB is the
2850 * new bss address. */
2853 text_addr
= strtoul (p
, (char **) &p1
, 16);
2854 if (p1
== p
|| *p1
!= ';')
2855 warning ("Malformed relocation packet: Packet '%s'", buf
);
2857 data_addr
= strtoul (p
, (char **) &p1
, 16);
2858 if (p1
== p
|| *p1
!= ';')
2859 warning ("Malformed relocation packet: Packet '%s'", buf
);
2861 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2863 warning ("Malformed relocation packet: Packet '%s'", buf
);
2865 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2866 &text_off
, &data_off
, &bss_off
)
2868 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2869 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2873 case 'W': /* Target exited */
2875 /* The remote process exited. */
2876 status
->kind
= TARGET_WAITKIND_EXITED
;
2877 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2881 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2882 status
->value
.sig
= (enum target_signal
)
2883 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2887 case 'O': /* Console output */
2888 remote_console_output (buf
+ 1);
2891 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2893 /* Zero length reply means that we tried 'S' or 'C' and
2894 the remote system doesn't support it. */
2895 target_terminal_ours_for_output ();
2897 ("Can't send signals to this remote system. %s not sent.\n",
2898 target_signal_to_name (last_sent_signal
));
2899 last_sent_signal
= TARGET_SIGNAL_0
;
2900 target_terminal_inferior ();
2902 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2903 putpkt ((char *) buf
);
2906 /* else fallthrough */
2908 warning ("Invalid remote reply: %s", buf
);
2913 if (thread_num
!= -1)
2917 return inferior_pid
;
2920 /* Number of bytes of registers this stub implements. */
2922 static int register_bytes_found
;
2924 /* Read the remote registers into the block REGS. */
2925 /* Currently we just read all the registers, so we don't use regno. */
2929 remote_fetch_registers (regno
)
2932 char *buf
= alloca (PBUFSIZ
);
2935 char regs
[REGISTER_BYTES
];
2937 set_thread (inferior_pid
, 1);
2940 remote_send (buf
, PBUFSIZ
);
2942 /* Save the size of the packet sent to us by the target. Its used
2943 as a heuristic when determining the max size of packets that the
2944 target can safely receive. */
2945 if (actual_register_packet_size
== 0)
2946 actual_register_packet_size
= strlen (buf
);
2948 /* Unimplemented registers read as all bits zero. */
2949 memset (regs
, 0, REGISTER_BYTES
);
2951 /* We can get out of synch in various cases. If the first character
2952 in the buffer is not a hex character, assume that has happened
2953 and try to fetch another packet to read. */
2954 while ((buf
[0] < '0' || buf
[0] > '9')
2955 && (buf
[0] < 'a' || buf
[0] > 'f')
2956 && buf
[0] != 'x') /* New: unavailable register value */
2959 fprintf_unfiltered (gdb_stdlog
,
2960 "Bad register packet; fetching a new packet\n");
2961 getpkt (buf
, PBUFSIZ
, 0);
2964 /* Reply describes registers byte by byte, each byte encoded as two
2965 hex characters. Suck them all up, then supply them to the
2966 register cacheing/storage mechanism. */
2969 for (i
= 0; i
< REGISTER_BYTES
; i
++)
2975 warning ("Remote reply is of odd length: %s", buf
);
2976 /* Don't change register_bytes_found in this case, and don't
2977 print a second warning. */
2980 if (p
[0] == 'x' && p
[1] == 'x')
2981 regs
[i
] = 0; /* 'x' */
2983 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2987 if (i
!= register_bytes_found
)
2989 register_bytes_found
= i
;
2990 #ifdef REGISTER_BYTES_OK
2991 if (!REGISTER_BYTES_OK (i
))
2992 warning ("Remote reply is too short: %s", buf
);
2997 for (i
= 0; i
< NUM_REGS
; i
++)
2999 supply_register (i
, ®s
[REGISTER_BYTE (i
)]);
3000 if (buf
[REGISTER_BYTE (i
) * 2] == 'x')
3001 register_valid
[i
] = -1; /* register value not available */
3005 /* Prepare to store registers. Since we may send them all (using a
3006 'G' request), we have to read out the ones we don't want to change
3010 remote_prepare_to_store ()
3012 /* Make sure the entire registers array is valid. */
3013 switch (remote_protocol_P
.support
)
3015 case PACKET_DISABLE
:
3016 case PACKET_SUPPORT_UNKNOWN
:
3017 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
);
3024 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
3025 packet was not recognized. */
3028 store_register_using_P (int regno
)
3030 /* Try storing a single register. */
3031 char *buf
= alloca (PBUFSIZ
);
3036 sprintf (buf
, "P%x=", regno
);
3037 p
= buf
+ strlen (buf
);
3038 regp
= ®isters
[REGISTER_BYTE (regno
)];
3039 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
3041 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
3042 *p
++ = tohex (regp
[i
] & 0xf);
3045 remote_send (buf
, PBUFSIZ
);
3047 return buf
[0] != '\0';
3051 /* Store register REGNO, or all registers if REGNO == -1, from the contents
3052 of REGISTERS. FIXME: ignores errors. */
3055 remote_store_registers (regno
)
3058 char *buf
= alloca (PBUFSIZ
);
3062 set_thread (inferior_pid
, 1);
3066 switch (remote_protocol_P
.support
)
3068 case PACKET_DISABLE
:
3071 if (store_register_using_P (regno
))
3074 error ("Protocol error: P packet not recognized by stub");
3075 case PACKET_SUPPORT_UNKNOWN
:
3076 if (store_register_using_P (regno
))
3078 /* The stub recognized the 'P' packet. Remember this. */
3079 remote_protocol_P
.support
= PACKET_ENABLE
;
3084 /* The stub does not support the 'P' packet. Use 'G'
3085 instead, and don't try using 'P' in the future (it
3086 will just waste our time). */
3087 remote_protocol_P
.support
= PACKET_DISABLE
;
3095 /* Command describes registers byte by byte,
3096 each byte encoded as two hex characters. */
3099 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3100 for (i
= 0; i
< register_bytes_found
; i
++)
3102 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
3103 *p
++ = tohex (registers
[i
] & 0xf);
3107 remote_send (buf
, PBUFSIZ
);
3110 /* Use of the data cache *used* to be disabled because it loses for looking
3111 at and changing hardware I/O ports and the like. Accepting `volatile'
3112 would perhaps be one way to fix it. Another idea would be to use the
3113 executable file for the text segment (for all SEC_CODE sections?
3114 For all SEC_READONLY sections?). This has problems if you want to
3115 actually see what the memory contains (e.g. self-modifying code,
3116 clobbered memory, user downloaded the wrong thing).
3118 Because it speeds so much up, it's now enabled, if you're playing
3119 with registers you turn it of (set remotecache 0). */
3121 /* Read a word from remote address ADDR and return it.
3122 This goes through the data cache. */
3126 remote_fetch_word (addr
)
3129 return dcache_fetch (remote_dcache
, addr
);
3132 /* Write a word WORD into remote address ADDR.
3133 This goes through the data cache. */
3136 remote_store_word (addr
, word
)
3140 dcache_poke (remote_dcache
, addr
, word
);
3142 #endif /* 0 (unused?) */
3146 /* Return the number of hex digits in num. */
3154 for (i
= 0; num
!= 0; i
++)
3160 /* Set BUF to the minimum number of hex digits representing NUM. */
3163 hexnumstr (buf
, num
)
3167 int len
= hexnumlen (num
);
3168 return hexnumnstr (buf
, num
, len
);
3172 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3175 hexnumnstr (buf
, num
, width
)
3184 for (i
= width
- 1; i
>= 0; i
--)
3186 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3193 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3196 remote_address_masked (addr
)
3199 if (remote_address_size
> 0
3200 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3202 /* Only create a mask when that mask can safely be constructed
3203 in a ULONGEST variable. */
3205 mask
= (mask
<< remote_address_size
) - 1;
3211 /* Determine whether the remote target supports binary downloading.
3212 This is accomplished by sending a no-op memory write of zero length
3213 to the target at the specified address. It does not suffice to send
3214 the whole packet, since many stubs strip the eighth bit and subsequently
3215 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3217 NOTE: This can still lose if the serial line is not eight-bit
3218 clean. In cases like this, the user should clear "remote
3222 check_binary_download (addr
)
3225 switch (remote_protocol_binary_download
.support
)
3227 case PACKET_DISABLE
:
3231 case PACKET_SUPPORT_UNKNOWN
:
3233 char *buf
= alloca (PBUFSIZ
);
3238 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3240 p
+= hexnumstr (p
, (ULONGEST
) 0);
3244 putpkt_binary (buf
, (int) (p
- buf
));
3245 getpkt (buf
, PBUFSIZ
, 0);
3250 fprintf_unfiltered (gdb_stdlog
,
3251 "binary downloading NOT suppported by target\n");
3252 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3257 fprintf_unfiltered (gdb_stdlog
,
3258 "binary downloading suppported by target\n");
3259 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3266 /* Write memory data directly to the remote machine.
3267 This does not inform the data cache; the data cache uses this.
3268 MEMADDR is the address in the remote memory space.
3269 MYADDR is the address of the buffer in our space.
3270 LEN is the number of bytes.
3272 Returns number of bytes transferred, or 0 (setting errno) for
3273 error. Only transfer a single packet. */
3276 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3279 int max_buf_size
; /* Max size of packet output buffer */
3281 unsigned char *plen
;
3287 /* Verify that the target can support a binary download */
3288 check_binary_download (memaddr
);
3290 /* Determine the max packet size. */
3291 max_buf_size
= get_memory_write_packet_size ();
3292 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3293 buf
= alloca (sizeof_buf
);
3295 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3296 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3298 /* construct "M"<memaddr>","<len>":" */
3299 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3302 /* Append [XM]. Compute a best guess of the number of bytes
3303 actually transfered. */
3304 switch (remote_protocol_binary_download
.support
)
3308 /* Best guess at number of bytes that will fit. */
3309 todo
= min (len
, max_buf_size
);
3311 case PACKET_DISABLE
:
3313 /* num bytes that will fit */
3314 todo
= min (len
, max_buf_size
/ 2);
3316 case PACKET_SUPPORT_UNKNOWN
:
3317 internal_error ("remote_write_bytes: bad switch");
3320 /* Append <memaddr> */
3321 memaddr
= remote_address_masked (memaddr
);
3322 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3325 /* Append <len>. Retain the location/size of <len>. It may
3326 need to be adjusted once the packet body has been created. */
3328 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3333 /* Append the packet body. */
3334 switch (remote_protocol_binary_download
.support
)
3337 /* Binary mode. Send target system values byte by byte, in
3338 increasing byte addresses. Only escape certain critical
3341 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3344 switch (myaddr
[nr_bytes
] & 0xff)
3349 /* These must be escaped */
3351 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3354 *p
++ = myaddr
[nr_bytes
] & 0xff;
3358 if (nr_bytes
< todo
)
3360 /* Escape chars have filled up the buffer prematurely,
3361 and we have actually sent fewer bytes than planned.
3362 Fix-up the length field of the packet. Use the same
3363 number of characters as before. */
3365 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3366 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3369 case PACKET_DISABLE
:
3370 /* Normal mode: Send target system values byte by byte, in
3371 increasing byte addresses. Each byte is encoded as a two hex
3373 for (nr_bytes
= 0; nr_bytes
< todo
; nr_bytes
++)
3375 *p
++ = tohex ((myaddr
[nr_bytes
] >> 4) & 0xf);
3376 *p
++ = tohex (myaddr
[nr_bytes
] & 0xf);
3380 case PACKET_SUPPORT_UNKNOWN
:
3381 internal_error ("remote_write_bytes: bad switch");
3384 putpkt_binary (buf
, (int) (p
- buf
));
3385 getpkt (buf
, sizeof_buf
, 0);
3389 /* There is no correspondance between what the remote protocol
3390 uses for errors and errno codes. We would like a cleaner way
3391 of representing errors (big enough to include errno codes,
3392 bfd_error codes, and others). But for now just return EIO. */
3397 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3398 bytes than we'd planned. */
3402 /* Read memory data directly from the remote machine.
3403 This does not use the data cache; the data cache uses this.
3404 MEMADDR is the address in the remote memory space.
3405 MYADDR is the address of the buffer in our space.
3406 LEN is the number of bytes.
3408 Returns number of bytes transferred, or 0 for error. */
3410 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3411 remote targets) shouldn't attempt to read the entire buffer.
3412 Instead it should read a single packet worth of data and then
3413 return the byte size of that packet to the caller. The caller (its
3414 caller and its callers caller ;-) already contains code for
3415 handling partial reads. */
3418 remote_read_bytes (memaddr
, myaddr
, len
)
3424 int max_buf_size
; /* Max size of packet output buffer */
3428 /* Create a buffer big enough for this packet. */
3429 max_buf_size
= get_memory_read_packet_size ();
3430 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3431 buf
= alloca (sizeof_buf
);
3440 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3442 /* construct "m"<memaddr>","<len>" */
3443 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3444 memaddr
= remote_address_masked (memaddr
);
3447 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3449 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3453 getpkt (buf
, sizeof_buf
, 0);
3457 /* There is no correspondance between what the remote protocol uses
3458 for errors and errno codes. We would like a cleaner way of
3459 representing errors (big enough to include errno codes, bfd_error
3460 codes, and others). But for now just return EIO. */
3465 /* Reply describes memory byte by byte,
3466 each byte encoded as two hex characters. */
3469 for (i
= 0; i
< todo
; i
++)
3471 if (p
[0] == 0 || p
[1] == 0)
3472 /* Reply is short. This means that we were able to read
3473 only part of what we wanted to. */
3474 return i
+ (origlen
- len
);
3475 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3485 /* Read or write LEN bytes from inferior memory at MEMADDR,
3486 transferring to or from debugger address BUFFER. Write to inferior if
3487 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3490 #ifndef REMOTE_TRANSLATE_XFER_ADDRESS
3491 #define REMOTE_TRANSLATE_XFER_ADDRESS(MEM_ADDR, MEM_LEN, TARG_ADDR, TARG_LEN) \
3492 (*(TARG_ADDR) = (MEM_ADDR), *(TARG_LEN) = (MEM_LEN))
3497 remote_xfer_memory (mem_addr
, buffer
, mem_len
, should_write
, target
)
3502 struct target_ops
*target
; /* ignored */
3504 CORE_ADDR targ_addr
;
3506 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3510 return dcache_xfer_memory (remote_dcache
, targ_addr
, buffer
,
3511 targ_len
, should_write
);
3516 /* Enable after 4.12. */
3519 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
3520 addr_found
, data_found
)
3524 CORE_ADDR startaddr
;
3528 CORE_ADDR
*addr_found
;
3531 if (increment
== -4 && len
== 4)
3533 long mask_long
, data_long
;
3534 long data_found_long
;
3535 CORE_ADDR addr_we_found
;
3536 char *buf
= alloca (PBUFSIZ
);
3537 long returned_long
[2];
3540 mask_long
= extract_unsigned_integer (mask
, len
);
3541 data_long
= extract_unsigned_integer (data
, len
);
3542 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
3544 getpkt (buf
, PBUFSIZ
, 0);
3547 /* The stub doesn't support the 't' request. We might want to
3548 remember this fact, but on the other hand the stub could be
3549 switched on us. Maybe we should remember it only until
3550 the next "target remote". */
3551 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3552 hirange
, addr_found
, data_found
);
3557 /* There is no correspondance between what the remote protocol uses
3558 for errors and errno codes. We would like a cleaner way of
3559 representing errors (big enough to include errno codes, bfd_error
3560 codes, and others). But for now just use EIO. */
3561 memory_error (EIO
, startaddr
);
3564 while (*p
!= '\0' && *p
!= ',')
3565 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
3567 error ("Protocol error: short return for search");
3569 data_found_long
= 0;
3570 while (*p
!= '\0' && *p
!= ',')
3571 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
3572 /* Ignore anything after this comma, for future extensions. */
3574 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
3580 *addr_found
= addr_we_found
;
3581 *data_found
= store_unsigned_integer (data_we_found
, len
);
3584 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3585 hirange
, addr_found
, data_found
);
3590 remote_files_info (ignore
)
3591 struct target_ops
*ignore
;
3593 puts_filtered ("Debugging a target over a serial line.\n");
3596 /* Stuff for dealing with the packets which are part of this protocol.
3597 See comment at top of file for details. */
3599 /* Read a single character from the remote end, masking it down to 7 bits. */
3607 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
3612 switch ((enum serial_rc
) ch
)
3615 target_mourn_inferior ();
3616 error ("Remote connection closed");
3619 perror_with_name ("Remote communication error");
3621 case SERIAL_TIMEOUT
:
3627 /* Send the command in BUF to the remote machine, and read the reply
3628 into BUF. Report an error if we get an error reply. */
3631 remote_send (char *buf
,
3635 getpkt (buf
, sizeof_buf
, 0);
3638 error ("Remote failure reply: %s", buf
);
3641 /* Display a null-terminated packet on stdout, for debugging, using C
3648 puts_filtered ("\"");
3649 fputstr_filtered (buf
, '"', gdb_stdout
);
3650 puts_filtered ("\"");
3657 return putpkt_binary (buf
, strlen (buf
));
3660 /* Send a packet to the remote machine, with error checking. The data
3661 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3662 to account for the $, # and checksum, and for a possible /0 if we are
3663 debugging (remote_debug) and want to print the sent packet as a string */
3666 putpkt_binary (buf
, cnt
)
3671 unsigned char csum
= 0;
3672 char *buf2
= alloca (cnt
+ 6);
3673 long sizeof_junkbuf
= PBUFSIZ
;
3674 char *junkbuf
= alloca (sizeof_junkbuf
);
3680 /* Copy the packet into buffer BUF2, encapsulating it
3681 and giving it a checksum. */
3686 for (i
= 0; i
< cnt
; i
++)
3692 *p
++ = tohex ((csum
>> 4) & 0xf);
3693 *p
++ = tohex (csum
& 0xf);
3695 /* Send it over and over until we get a positive ack. */
3699 int started_error_output
= 0;
3704 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
3705 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
3706 fprintf_unfiltered (gdb_stdlog
, "...");
3707 gdb_flush (gdb_stdlog
);
3709 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
3710 perror_with_name ("putpkt: write failed");
3712 /* read until either a timeout occurs (-2) or '+' is read */
3715 ch
= readchar (remote_timeout
);
3722 case SERIAL_TIMEOUT
:
3724 if (started_error_output
)
3726 putchar_unfiltered ('\n');
3727 started_error_output
= 0;
3736 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
3738 case SERIAL_TIMEOUT
:
3742 break; /* Retransmit buffer */
3745 /* It's probably an old response, and we're out of sync.
3746 Just gobble up the packet and ignore it. */
3747 getpkt (junkbuf
, sizeof_junkbuf
, 0);
3748 continue; /* Now, go look for + */
3753 if (!started_error_output
)
3755 started_error_output
= 1;
3756 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
3758 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
3762 break; /* Here to retransmit */
3766 /* This is wrong. If doing a long backtrace, the user should be
3767 able to get out next time we call QUIT, without anything as
3768 violent as interrupt_query. If we want to provide a way out of
3769 here without getting to the next QUIT, it should be based on
3770 hitting ^C twice as in remote_wait. */
3780 static int remote_cisco_mode
;
3782 /* Come here after finding the start of the frame. Collect the rest
3783 into BUF, verifying the checksum, length, and handling run-length
3784 compression. No more than sizeof_buf-1 characters are read so that
3785 the buffer can be NUL terminated.
3787 Returns -1 on error, number of characters in buffer (ignoring the
3788 trailing NULL) on success. (could be extended to return one of the
3789 SERIAL status indications). */
3792 read_frame (char *buf
,
3804 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
3805 c
= readchar (remote_timeout
);
3808 case SERIAL_TIMEOUT
:
3810 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
3814 fputs_filtered ("Saw new packet start in middle of old one\n",
3816 return -1; /* Start a new packet, count retries */
3819 unsigned char pktcsum
;
3823 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
3824 pktcsum
|= fromhex (readchar (remote_timeout
));
3826 if (csum
== pktcsum
)
3831 fprintf_filtered (gdb_stdlog
,
3832 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3834 fputs_filtered (buf
, gdb_stdlog
);
3835 fputs_filtered ("\n", gdb_stdlog
);
3837 /* Number of characters in buffer ignoring trailing
3841 case '*': /* Run length encoding */
3846 if (remote_cisco_mode
== 0)
3848 c
= readchar (remote_timeout
);
3850 repeat
= c
- ' ' + 3; /* Compute repeat count */
3854 /* Cisco's run-length encoding variant uses two
3855 hex chars to represent the repeat count. */
3857 c
= readchar (remote_timeout
);
3859 repeat
= fromhex (c
) << 4;
3860 c
= readchar (remote_timeout
);
3862 repeat
+= fromhex (c
);
3865 /* The character before ``*'' is repeated. */
3867 if (repeat
> 0 && repeat
<= 255
3869 && bc
+ repeat
< sizeof_buf
- 1)
3871 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
3877 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
3878 puts_filtered (buf
);
3879 puts_filtered ("\n");
3883 if (bc
< sizeof_buf
- 1)
3891 puts_filtered ("Remote packet too long: ");
3892 puts_filtered (buf
);
3893 puts_filtered ("\n");
3900 /* Read a packet from the remote machine, with error checking, and
3901 store it in BUF. If FOREVER, wait forever rather than timing out;
3902 this is used (in synchronous mode) to wait for a target that is is
3903 executing user code to stop. */
3915 strcpy (buf
, "timeout");
3919 timeout
= watchdog
> 0 ? watchdog
: -1;
3923 timeout
= remote_timeout
;
3927 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
3929 /* This can loop forever if the remote side sends us characters
3930 continuously, but if it pauses, we'll get a zero from readchar
3931 because of timeout. Then we'll count that as a retry. */
3933 /* Note that we will only wait forever prior to the start of a packet.
3934 After that, we expect characters to arrive at a brisk pace. They
3935 should show up within remote_timeout intervals. */
3939 c
= readchar (timeout
);
3941 if (c
== SERIAL_TIMEOUT
)
3943 if (forever
) /* Watchdog went off? Kill the target. */
3946 target_mourn_inferior ();
3947 error ("Watchdog has expired. Target detached.\n");
3950 fputs_filtered ("Timed out.\n", gdb_stdlog
);
3956 /* We've found the start of a packet, now collect the data. */
3958 val
= read_frame (buf
, sizeof_buf
);
3964 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
3965 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
3966 fprintf_unfiltered (gdb_stdlog
, "\n");
3968 SERIAL_WRITE (remote_desc
, "+", 1);
3972 /* Try the whole thing again. */
3974 SERIAL_WRITE (remote_desc
, "-", 1);
3977 /* We have tried hard enough, and just can't receive the packet. Give up. */
3979 printf_unfiltered ("Ignoring packet error, continuing...\n");
3980 SERIAL_WRITE (remote_desc
, "+", 1);
3986 /* For some mysterious reason, wait_for_inferior calls kill instead of
3987 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3991 target_mourn_inferior ();
3995 /* Use catch_errors so the user can quit from gdb even when we aren't on
3996 speaking terms with the remote system. */
3997 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
3999 /* Don't wait for it to die. I'm not really sure it matters whether
4000 we do or not. For the existing stubs, kill is a noop. */
4001 target_mourn_inferior ();
4004 /* Async version of remote_kill. */
4006 remote_async_kill ()
4008 /* Unregister the file descriptor from the event loop. */
4009 if (SERIAL_IS_ASYNC_P (remote_desc
))
4010 SERIAL_ASYNC (remote_desc
, NULL
, 0);
4012 /* For some mysterious reason, wait_for_inferior calls kill instead of
4013 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4017 target_mourn_inferior ();
4021 /* Use catch_errors so the user can quit from gdb even when we aren't on
4022 speaking terms with the remote system. */
4023 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4025 /* Don't wait for it to die. I'm not really sure it matters whether
4026 we do or not. For the existing stubs, kill is a noop. */
4027 target_mourn_inferior ();
4033 remote_mourn_1 (&remote_ops
);
4037 remote_async_mourn ()
4039 remote_mourn_1 (&remote_async_ops
);
4043 extended_remote_mourn ()
4045 /* We do _not_ want to mourn the target like this; this will
4046 remove the extended remote target from the target stack,
4047 and the next time the user says "run" it'll fail.
4049 FIXME: What is the right thing to do here? */
4051 remote_mourn_1 (&extended_remote_ops
);
4055 /* Worker function for remote_mourn. */
4057 remote_mourn_1 (target
)
4058 struct target_ops
*target
;
4060 unpush_target (target
);
4061 generic_mourn_inferior ();
4064 /* In the extended protocol we want to be able to do things like
4065 "run" and have them basically work as expected. So we need
4066 a special create_inferior function.
4068 FIXME: One day add support for changing the exec file
4069 we're debugging, arguments and an environment. */
4072 extended_remote_create_inferior (exec_file
, args
, env
)
4077 /* Rip out the breakpoints; we'll reinsert them after restarting
4078 the remote server. */
4079 remove_breakpoints ();
4081 /* Now restart the remote server. */
4082 extended_remote_restart ();
4084 /* Now put the breakpoints back in. This way we're safe if the
4085 restart function works via a unix fork on the remote side. */
4086 insert_breakpoints ();
4088 /* Clean up from the last time we were running. */
4089 clear_proceed_status ();
4091 /* Let the remote process run. */
4092 proceed (-1, TARGET_SIGNAL_0
, 0);
4095 /* Async version of extended_remote_create_inferior. */
4097 extended_remote_async_create_inferior (exec_file
, args
, env
)
4102 /* Rip out the breakpoints; we'll reinsert them after restarting
4103 the remote server. */
4104 remove_breakpoints ();
4106 /* If running asynchronously, register the target file descriptor
4107 with the event loop. */
4108 if (event_loop_p
&& target_can_async_p ())
4109 target_async (inferior_event_handler
, 0);
4111 /* Now restart the remote server. */
4112 extended_remote_restart ();
4114 /* Now put the breakpoints back in. This way we're safe if the
4115 restart function works via a unix fork on the remote side. */
4116 insert_breakpoints ();
4118 /* Clean up from the last time we were running. */
4119 clear_proceed_status ();
4121 /* Let the remote process run. */
4122 proceed (-1, TARGET_SIGNAL_0
, 0);
4126 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4127 than other targets; in those use REMOTE_BREAKPOINT instead of just
4128 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4129 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4130 the standard routines that are in mem-break.c. */
4132 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4133 the choice of breakpoint instruction affects target program design and
4134 vice versa, and by making it user-tweakable, the special code here
4135 goes away and we need fewer special GDB configurations. */
4137 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4138 #define REMOTE_BREAKPOINT
4141 #ifdef REMOTE_BREAKPOINT
4143 /* If the target isn't bi-endian, just pretend it is. */
4144 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4145 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4146 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4149 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
4150 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
4152 #endif /* REMOTE_BREAKPOINT */
4154 /* Insert a breakpoint on targets that don't have any better breakpoint
4155 support. We read the contents of the target location and stash it,
4156 then overwrite it with a breakpoint instruction. ADDR is the target
4157 location in the target machine. CONTENTS_CACHE is a pointer to
4158 memory allocated for saving the target contents. It is guaranteed
4159 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4160 is accomplished via BREAKPOINT_MAX). */
4163 remote_insert_breakpoint (addr
, contents_cache
)
4165 char *contents_cache
;
4167 #ifdef REMOTE_BREAKPOINT
4172 /* Try the "Z" packet if it is not already disabled.
4173 If it succeeds, then set the support to PACKET_ENABLE.
4174 If it fails, and the user has explicitly requested the Z support
4175 then report an error, otherwise, mark it disabled and go on. */
4177 if ((remote_protocol_Z
.support
== PACKET_ENABLE
)
4178 || (remote_protocol_Z
.support
== PACKET_SUPPORT_UNKNOWN
))
4180 char *buf
= alloca (PBUFSIZ
);
4183 addr
= remote_address_masked (addr
);
4187 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4188 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4189 sprintf (p
, ",%d", bp_size
);
4192 getpkt (buf
, PBUFSIZ
, 0);
4196 remote_protocol_Z
.support
= PACKET_ENABLE
;
4197 return (buf
[0] == 'E');
4200 /* The stub does not support the 'Z' request. If the user has
4201 explicitly requested the Z support, or if the stub previously
4202 said it supported the packet, this is an error,
4203 otherwise, mark it disabled. */
4205 else if (remote_protocol_Z
.support
== PACKET_ENABLE
)
4207 error ("Protocol error: Z packet not recognized by stub");
4211 remote_protocol_Z
.support
= PACKET_DISABLE
;
4215 #ifdef REMOTE_BREAKPOINT
4216 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4220 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
4221 val
= target_write_memory (addr
, (char *) big_break_insn
,
4222 sizeof big_break_insn
);
4224 val
= target_write_memory (addr
, (char *) little_break_insn
,
4225 sizeof little_break_insn
);
4230 return memory_insert_breakpoint (addr
, contents_cache
);
4231 #endif /* REMOTE_BREAKPOINT */
4235 remote_remove_breakpoint (addr
, contents_cache
)
4237 char *contents_cache
;
4241 if ((remote_protocol_Z
.support
== PACKET_ENABLE
)
4242 || (remote_protocol_Z
.support
== PACKET_SUPPORT_UNKNOWN
))
4244 char *buf
= alloca (PBUFSIZ
);
4251 addr
= remote_address_masked (addr
);
4252 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4253 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4254 sprintf (p
, ",%d", bp_size
);
4257 getpkt (buf
, PBUFSIZ
, 0);
4259 return (buf
[0] == 'E');
4262 #ifdef REMOTE_BREAKPOINT
4263 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4265 return memory_remove_breakpoint (addr
, contents_cache
);
4266 #endif /* REMOTE_BREAKPOINT */
4269 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
4271 remote_insert_watchpoint (addr
, len
, type
)
4276 char *buf
= alloca (PBUFSIZ
);
4279 if (remote_protocol_Z
.support
== PACKET_DISABLE
)
4280 error ("Can't set hardware watchpoints without the 'Z' packet\n");
4282 sprintf (buf
, "Z%x,", type
+ 2 );
4283 p
= strchr (buf
, '\0');
4284 addr
= remote_address_masked (addr
);
4285 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4286 sprintf (p
, ",%x", len
);
4289 getpkt (buf
, PBUFSIZ
, 0);
4291 if (buf
[0] == '\0' || buf
[0] == 'E')
4298 remote_remove_watchpoint (addr
, len
, type
)
4303 char *buf
= alloca (PBUFSIZ
);
4306 sprintf (buf
, "z%x,", type
+ 2 );
4307 p
= strchr (buf
, '\0');
4308 addr
= remote_address_masked (addr
);
4309 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4310 sprintf (p
, ",%x", len
);
4312 getpkt (buf
, PBUFSIZ
, 0);
4314 if (buf
[0] == '\0' || buf
[0] == 'E')
4321 remote_insert_hw_breakpoint (addr
, len
)
4325 char *buf
= alloca (PBUFSIZ
);
4328 if (remote_protocol_Z
.support
== PACKET_DISABLE
)
4329 error ("Can't set hardware breakpoints without the 'Z' packet\n");
4335 addr
= remote_address_masked (addr
);
4336 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4340 getpkt (buf
, PBUFSIZ
, 0);
4342 if (buf
[0] == '\0' || buf
[0] == 'E')
4349 remote_remove_hw_breakpoint (addr
, len
)
4353 char *buf
= alloca (PBUFSIZ
);
4360 addr
= remote_address_masked (addr
);
4361 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4365 getpkt (buf
, PBUFSIZ
, 0);
4367 if (buf
[0] == '\0' || buf
[0] == 'E')
4374 /* Some targets are only capable of doing downloads, and afterwards
4375 they switch to the remote serial protocol. This function provides
4376 a clean way to get from the download target to the remote target.
4377 It's basically just a wrapper so that we don't have to expose any
4378 of the internal workings of remote.c.
4380 Prior to calling this routine, you should shutdown the current
4381 target code, else you will get the "A program is being debugged
4382 already..." message. Usually a call to pop_target() suffices. */
4385 push_remote_target (name
, from_tty
)
4389 printf_filtered ("Switching to remote protocol\n");
4390 remote_open (name
, from_tty
);
4393 /* Other targets want to use the entire remote serial module but with
4394 certain remote_ops overridden. */
4397 open_remote_target (name
, from_tty
, target
, extended_p
)
4400 struct target_ops
*target
;
4403 printf_filtered ("Selecting the %sremote protocol\n",
4404 (extended_p
? "extended-" : ""));
4405 remote_open_1 (name
, from_tty
, target
, extended_p
);
4408 /* Table used by the crc32 function to calcuate the checksum. */
4410 static unsigned long crc32_table
[256] =
4413 static unsigned long
4414 crc32 (buf
, len
, crc
)
4419 if (!crc32_table
[1])
4421 /* Initialize the CRC table and the decoding table. */
4425 for (i
= 0; i
< 256; i
++)
4427 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4428 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4435 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4441 /* compare-sections command
4443 With no arguments, compares each loadable section in the exec bfd
4444 with the same memory range on the target, and reports mismatches.
4445 Useful for verifying the image on the target against the exec file.
4446 Depends on the target understanding the new "qCRC:" request. */
4448 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4449 target method (target verify memory) and generic version of the
4450 actual command. This will allow other high-level code (especially
4451 generic_load()) to make use of this target functionality. */
4454 compare_sections_command (args
, from_tty
)
4459 unsigned long host_crc
, target_crc
;
4460 extern bfd
*exec_bfd
;
4461 struct cleanup
*old_chain
;
4465 char *buf
= alloca (PBUFSIZ
);
4472 error ("command cannot be used without an exec file");
4473 if (!current_target
.to_shortname
||
4474 strcmp (current_target
.to_shortname
, "remote") != 0)
4475 error ("command can only be used with remote target");
4477 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4479 if (!(s
->flags
& SEC_LOAD
))
4480 continue; /* skip non-loadable section */
4482 size
= bfd_get_section_size_before_reloc (s
);
4484 continue; /* skip zero-length section */
4486 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
4487 if (args
&& strcmp (args
, sectname
) != 0)
4488 continue; /* not the section selected by user */
4490 matched
= 1; /* do this section */
4492 /* FIXME: assumes lma can fit into long */
4493 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
4496 /* be clever; compute the host_crc before waiting for target reply */
4497 sectdata
= xmalloc (size
);
4498 old_chain
= make_cleanup (free
, sectdata
);
4499 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4500 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4502 getpkt (buf
, PBUFSIZ
, 0);
4504 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4505 sectname
, lma
, lma
+ size
);
4507 error ("remote target does not support this operation");
4509 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4510 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4512 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4513 sectname
, paddr (lma
), paddr (lma
+ size
));
4514 if (host_crc
== target_crc
)
4515 printf_filtered ("matched.\n");
4518 printf_filtered ("MIS-MATCHED!\n");
4522 do_cleanups (old_chain
);
4525 warning ("One or more sections of the remote executable does not match\n\
4526 the loaded file\n");
4527 if (args
&& !matched
)
4528 printf_filtered ("No loaded section named '%s'.\n", args
);
4532 remote_query (query_type
, buf
, outbuf
, bufsiz
)
4539 char *buf2
= alloca (PBUFSIZ
);
4540 char *p2
= &buf2
[0];
4543 error ("null pointer to remote bufer size specified");
4545 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4546 the caller know and return what the minimum size is */
4547 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4548 if (*bufsiz
< PBUFSIZ
)
4554 /* except for querying the minimum buffer size, target must be open */
4556 error ("remote query is only available after target open");
4558 /* we only take uppercase letters as query types, at least for now */
4559 if ((query_type
< 'A') || (query_type
> 'Z'))
4560 error ("invalid remote query type");
4563 error ("null remote query specified");
4566 error ("remote query requires a buffer to receive data");
4573 /* we used one buffer char for the remote protocol q command and another
4574 for the query type. As the remote protocol encapsulation uses 4 chars
4575 plus one extra in case we are debugging (remote_debug),
4576 we have PBUFZIZ - 7 left to pack the query string */
4578 while (buf
[i
] && (i
< (PBUFSIZ
- 8)))
4580 /* bad caller may have sent forbidden characters */
4581 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
4582 error ("illegal characters in query string");
4590 error ("query larger than available buffer");
4596 getpkt (outbuf
, *bufsiz
, 0);
4602 remote_rcmd (char *command
,
4603 struct gdb_file
*outbuf
)
4606 char *buf
= alloca (PBUFSIZ
);
4610 error ("remote rcmd is only available after target open");
4612 /* Send a NULL command across as an empty command */
4613 if (command
== NULL
)
4616 /* The query prefix */
4617 strcpy (buf
, "qRcmd,");
4618 p
= strchr (buf
, '\0');
4620 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > PBUFSIZ
)
4621 error ("\"monitor\" command ``%s'' is too long\n", command
);
4623 /* Encode the actual command */
4624 for (i
= 0; command
[i
]; i
++)
4626 *p
++ = tohex ((command
[i
] >> 4) & 0xf);
4627 *p
++ = tohex (command
[i
] & 0xf);
4631 if (putpkt (buf
) < 0)
4632 error ("Communication problem with target\n");
4634 /* get/display the response */
4637 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4639 getpkt (buf
, PBUFSIZ
, 0);
4641 error ("Target does not support this command\n");
4642 if (buf
[0] == 'O' && buf
[1] != 'K')
4644 remote_console_output (buf
+ 1); /* 'O' message from stub */
4647 if (strcmp (buf
, "OK") == 0)
4649 if (strlen (buf
) == 3 && buf
[0] == 'E'
4650 && isdigit (buf
[1]) && isdigit (buf
[2]))
4652 error ("Protocol error with Rcmd");
4654 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
4656 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
4657 fputc_unfiltered (c
, outbuf
);
4664 packet_command (args
, from_tty
)
4668 char *buf
= alloca (PBUFSIZ
);
4671 error ("command can only be used with remote target");
4674 error ("remote-packet command requires packet text as argument");
4676 puts_filtered ("sending: ");
4677 print_packet (args
);
4678 puts_filtered ("\n");
4681 getpkt (buf
, PBUFSIZ
, 0);
4682 puts_filtered ("received: ");
4684 puts_filtered ("\n");
4688 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4690 static void display_thread_info
PARAMS ((struct gdb_ext_thread_info
* info
));
4692 static void threadset_test_cmd
PARAMS ((char *cmd
, int tty
));
4694 static void threadalive_test
PARAMS ((char *cmd
, int tty
));
4696 static void threadlist_test_cmd
PARAMS ((char *cmd
, int tty
));
4698 int get_and_display_threadinfo
PARAMS ((threadref
* ref
));
4700 static void threadinfo_test_cmd
PARAMS ((char *cmd
, int tty
));
4702 static int thread_display_step
PARAMS ((threadref
* ref
, void *context
));
4704 static void threadlist_update_test_cmd
PARAMS ((char *cmd
, int tty
));
4706 static void init_remote_threadtests
PARAMS ((void));
4708 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4711 threadset_test_cmd (cmd
, tty
)
4715 int sample_thread
= SAMPLE_THREAD
;
4717 printf_filtered ("Remote threadset test\n");
4718 set_thread (sample_thread
, 1);
4723 threadalive_test (cmd
, tty
)
4727 int sample_thread
= SAMPLE_THREAD
;
4729 if (remote_thread_alive (sample_thread
))
4730 printf_filtered ("PASS: Thread alive test\n");
4732 printf_filtered ("FAIL: Thread alive test\n");
4735 void output_threadid
PARAMS ((char *title
, threadref
* ref
));
4738 output_threadid (title
, ref
)
4744 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
4746 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
4750 threadlist_test_cmd (cmd
, tty
)
4755 threadref nextthread
;
4756 int done
, result_count
;
4757 threadref threadlist
[3];
4759 printf_filtered ("Remote Threadlist test\n");
4760 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
4761 &result_count
, &threadlist
[0]))
4762 printf_filtered ("FAIL: threadlist test\n");
4765 threadref
*scan
= threadlist
;
4766 threadref
*limit
= scan
+ result_count
;
4768 while (scan
< limit
)
4769 output_threadid (" thread ", scan
++);
4774 display_thread_info (info
)
4775 struct gdb_ext_thread_info
*info
;
4777 output_threadid ("Threadid: ", &info
->threadid
);
4778 printf_filtered ("Name: %s\n ", info
->shortname
);
4779 printf_filtered ("State: %s\n", info
->display
);
4780 printf_filtered ("other: %s\n\n", info
->more_display
);
4784 get_and_display_threadinfo (ref
)
4789 struct gdb_ext_thread_info threadinfo
;
4791 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
4792 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
4793 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
4794 display_thread_info (&threadinfo
);
4799 threadinfo_test_cmd (cmd
, tty
)
4803 int athread
= SAMPLE_THREAD
;
4807 int_to_threadref (&thread
, athread
);
4808 printf_filtered ("Remote Threadinfo test\n");
4809 if (!get_and_display_threadinfo (&thread
))
4810 printf_filtered ("FAIL cannot get thread info\n");
4814 thread_display_step (ref
, context
)
4818 /* output_threadid(" threadstep ",ref); *//* simple test */
4819 return get_and_display_threadinfo (ref
);
4823 threadlist_update_test_cmd (cmd
, tty
)
4827 printf_filtered ("Remote Threadlist update test\n");
4828 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
4832 init_remote_threadtests (void)
4834 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
4835 "Fetch and print the remote list of thread identifiers, one pkt only");
4836 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
4837 "Fetch and display info about one thread");
4838 add_com ("tset", class_obscure
, threadset_test_cmd
,
4839 "Test setting to a different thread");
4840 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
4841 "Iterate through updating all remote thread info");
4842 add_com ("talive", class_obscure
, threadalive_test
,
4843 " Remote thread alive test ");
4851 remote_ops
.to_shortname
= "remote";
4852 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
4854 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4855 Specify the serial device it is connected to (e.g. /dev/ttya).";
4856 remote_ops
.to_open
= remote_open
;
4857 remote_ops
.to_close
= remote_close
;
4858 remote_ops
.to_detach
= remote_detach
;
4859 remote_ops
.to_resume
= remote_resume
;
4860 remote_ops
.to_wait
= remote_wait
;
4861 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
4862 remote_ops
.to_store_registers
= remote_store_registers
;
4863 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
4864 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
4865 remote_ops
.to_files_info
= remote_files_info
;
4866 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
4867 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
4868 remote_ops
.to_kill
= remote_kill
;
4869 remote_ops
.to_load
= generic_load
;
4870 remote_ops
.to_mourn_inferior
= remote_mourn
;
4871 remote_ops
.to_thread_alive
= remote_thread_alive
;
4872 remote_ops
.to_find_new_threads
= remote_threads_info
;
4873 remote_ops
.to_stop
= remote_stop
;
4874 remote_ops
.to_query
= remote_query
;
4875 remote_ops
.to_rcmd
= remote_rcmd
;
4876 remote_ops
.to_stratum
= process_stratum
;
4877 remote_ops
.to_has_all_memory
= 1;
4878 remote_ops
.to_has_memory
= 1;
4879 remote_ops
.to_has_stack
= 1;
4880 remote_ops
.to_has_registers
= 1;
4881 remote_ops
.to_has_execution
= 1;
4882 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
4883 remote_ops
.to_magic
= OPS_MAGIC
;
4886 /* Set up the extended remote vector by making a copy of the standard
4887 remote vector and adding to it. */
4890 init_extended_remote_ops ()
4892 extended_remote_ops
= remote_ops
;
4894 extended_remote_ops
.to_shortname
= "extended-remote";
4895 extended_remote_ops
.to_longname
=
4896 "Extended remote serial target in gdb-specific protocol";
4897 extended_remote_ops
.to_doc
=
4898 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4899 Specify the serial device it is connected to (e.g. /dev/ttya).",
4900 extended_remote_ops
.to_open
= extended_remote_open
;
4901 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
4902 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
4906 * Command: info remote-process
4908 * This implements Cisco's version of the "info proc" command.
4910 * This query allows the target stub to return an arbitrary string
4911 * (or strings) giving arbitrary information about the target process.
4912 * This is optional; the target stub isn't required to implement it.
4914 * Syntax: qfProcessInfo request first string
4915 * qsProcessInfo request subsequent string
4916 * reply: 'O'<hex-encoded-string>
4917 * 'l' last reply (empty)
4921 remote_info_process (char *args
, int from_tty
)
4923 char *buf
= alloca (PBUFSIZ
);
4925 if (remote_desc
== 0)
4926 error ("Command can only be used when connected to the remote target.");
4928 putpkt ("qfProcessInfo");
4929 getpkt (buf
, PBUFSIZ
, 0);
4931 return; /* Silently: target does not support this feature. */
4934 error ("info proc: target error.");
4936 while (buf
[0] == 'O') /* Capitol-O packet */
4938 remote_console_output (&buf
[1]);
4939 putpkt ("qsProcessInfo");
4940 getpkt (buf
, PBUFSIZ
, 0);
4949 remote_cisco_open (char *name
, int from_tty
)
4953 "To open a remote debug connection, you need to specify what \n\
4954 device is attached to the remote system (e.g. host:port).");
4956 /* See FIXME above */
4957 wait_forever_enabled_p
= 1;
4959 target_preopen (from_tty
);
4961 unpush_target (&remote_cisco_ops
);
4963 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
4965 remote_desc
= SERIAL_OPEN (name
);
4967 perror_with_name (name
);
4970 * If a baud rate was specified on the gdb command line it will
4971 * be greater than the initial value of -1. If it is, use it otherwise
4975 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
4976 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
4978 SERIAL_CLOSE (remote_desc
);
4979 perror_with_name (name
);
4982 SERIAL_RAW (remote_desc
);
4984 /* If there is something sitting in the buffer we might take it as a
4985 response to a command, which would be bad. */
4986 SERIAL_FLUSH_INPUT (remote_desc
);
4990 puts_filtered ("Remote debugging using ");
4991 puts_filtered (name
);
4992 puts_filtered ("\n");
4995 remote_cisco_mode
= 1;
4997 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
4999 init_packet_config (&remote_protocol_P
);
5000 init_packet_config (&remote_protocol_Z
);
5002 general_thread
= -2;
5003 continue_thread
= -2;
5005 /* Force remote_write_bytes to check whether target supports
5006 binary downloading. */
5007 init_packet_config (&remote_protocol_binary_download
);
5009 /* Without this, some commands which require an active target (such
5010 as kill) won't work. This variable serves (at least) double duty
5011 as both the pid of the target process (if it has such), and as a
5012 flag indicating that a target is active. These functions should
5013 be split out into seperate variables, especially since GDB will
5014 someday have a notion of debugging several processes. */
5015 inferior_pid
= MAGIC_NULL_PID
;
5017 /* Start the remote connection; if error (0), discard this target. */
5019 if (!catch_errors (remote_start_remote_dummy
, (char *) 0,
5020 "Couldn't establish connection to remote target\n",
5029 remote_cisco_close (int quitting
)
5031 remote_cisco_mode
= 0;
5032 remote_close (quitting
);
5039 remote_mourn_1 (&remote_cisco_ops
);
5051 /* shared between readsocket() and readtty() */
5052 static char *tty_input
;
5054 static int escape_count
;
5055 static int echo_check
;
5056 extern int quit_flag
;
5063 /* Loop until the socket doesn't have any more data */
5065 while ((data
= readchar (0)) >= 0)
5067 /* Check for the escape sequence */
5070 /* If this is the fourth escape, get out */
5071 if (++escape_count
== 4)
5076 { /* This is a '|', but not the fourth in a row.
5077 Continue without echoing it. If it isn't actually
5078 one of four in a row, it'll be echoed later. */
5085 /* Ensure any pending '|'s are flushed. */
5087 for (; escape_count
> 0; escape_count
--)
5091 if (data
== '\r') /* If this is a return character, */
5092 continue; /* - just supress it. */
5094 if (echo_check
!= -1) /* Check for echo of user input. */
5096 if (tty_input
[echo_check
] == data
)
5098 echo_check
++; /* Character matched user input: */
5099 continue; /* Continue without echoing it. */
5101 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5102 { /* End of the line (and of echo checking). */
5103 echo_check
= -1; /* No more echo supression */
5104 continue; /* Continue without echoing. */
5107 { /* Failed check for echo of user input.
5108 We now have some suppressed output to flush! */
5111 for (j
= 0; j
< echo_check
; j
++)
5112 putchar (tty_input
[j
]);
5116 putchar (data
); /* Default case: output the char. */
5119 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5120 return READ_MORE
; /* Try to read some more */
5122 return FATAL_ERROR
; /* Trouble, bail out */
5130 /* First, read a buffer full from the terminal */
5131 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5132 if (tty_bytecount
== -1)
5134 perror ("readtty: read failed");
5138 /* Remove a quoted newline. */
5139 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5140 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5142 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5143 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5146 /* Turn trailing newlines into returns */
5147 if (tty_input
[tty_bytecount
- 1] == '\n')
5148 tty_input
[tty_bytecount
- 1] = '\r';
5150 /* If the line consists of a ~, enter debugging mode. */
5151 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5154 /* Make this a zero terminated string and write it out */
5155 tty_input
[tty_bytecount
] = 0;
5156 if (SERIAL_WRITE (remote_desc
, tty_input
, tty_bytecount
))
5158 perror_with_name ("readtty: write failed");
5168 fd_set input
; /* file descriptors for select */
5169 int tablesize
; /* max number of FDs for select */
5173 extern int escape_count
; /* global shared by readsocket */
5174 extern int echo_check
; /* ditto */
5179 tablesize
= 8 * sizeof (input
);
5183 /* Check for anything from our socket - doesn't block. Note that
5184 this must be done *before* the select as there may be
5185 buffered I/O waiting to be processed. */
5187 if ((status
= readsocket ()) == FATAL_ERROR
)
5189 error ("Debugging terminated by communications error");
5191 else if (status
!= READ_MORE
)
5196 fflush (stdout
); /* Flush output before blocking */
5198 /* Now block on more socket input or TTY input */
5201 FD_SET (fileno (stdin
), &input
);
5202 FD_SET (DEPRECATED_SERIAL_FD (remote_desc
), &input
);
5204 status
= select (tablesize
, &input
, 0, 0, 0);
5205 if ((status
== -1) && (errno
!= EINTR
))
5207 error ("Communications error on select %d", errno
);
5210 /* Handle Control-C typed */
5214 if ((++quit_count
) == 2)
5216 if (query ("Interrupt GDB? "))
5218 printf_filtered ("Interrupted by user.\n");
5219 return_to_top_level (RETURN_QUIT
);
5226 SERIAL_SEND_BREAK (remote_desc
);
5228 SERIAL_WRITE (remote_desc
, "\003", 1);
5233 /* Handle console input */
5235 if (FD_ISSET (fileno (stdin
), &input
))
5239 status
= readtty ();
5240 if (status
== READ_MORE
)
5243 return status
; /* telnet session ended */
5249 remote_cisco_wait (int pid
, struct target_waitstatus
*status
)
5251 if (minitelnet () != ENTER_DEBUG
)
5253 error ("Debugging session terminated by protocol error");
5256 return remote_wait (pid
, status
);
5260 init_remote_cisco_ops ()
5262 remote_cisco_ops
.to_shortname
= "cisco";
5263 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5264 remote_cisco_ops
.to_doc
=
5265 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5266 Specify the serial device it is connected to (e.g. host:2020).";
5267 remote_cisco_ops
.to_open
= remote_cisco_open
;
5268 remote_cisco_ops
.to_close
= remote_cisco_close
;
5269 remote_cisco_ops
.to_detach
= remote_detach
;
5270 remote_cisco_ops
.to_resume
= remote_resume
;
5271 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5272 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5273 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5274 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5275 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5276 remote_cisco_ops
.to_files_info
= remote_files_info
;
5277 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5278 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5279 remote_cisco_ops
.to_kill
= remote_kill
;
5280 remote_cisco_ops
.to_load
= generic_load
;
5281 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5282 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5283 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5284 remote_cisco_ops
.to_stratum
= process_stratum
;
5285 remote_cisco_ops
.to_has_all_memory
= 1;
5286 remote_cisco_ops
.to_has_memory
= 1;
5287 remote_cisco_ops
.to_has_stack
= 1;
5288 remote_cisco_ops
.to_has_registers
= 1;
5289 remote_cisco_ops
.to_has_execution
= 1;
5290 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5294 remote_can_async_p (void)
5296 /* We're async whenever the serial device is. */
5297 return SERIAL_CAN_ASYNC_P (remote_desc
);
5301 remote_is_async_p (void)
5303 /* We're async whenever the serial device is. */
5304 return SERIAL_IS_ASYNC_P (remote_desc
);
5307 /* Pass the SERIAL event on and up to the client. One day this code
5308 will be able to delay notifying the client of an event until the
5309 point where an entire packet has been received. */
5311 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5312 static void *async_client_context
;
5313 static serial_event_ftype remote_async_serial_handler
;
5316 remote_async_serial_handler (serial_t scb
, void *context
)
5318 /* Don't propogate error information up to the client. Instead let
5319 the client find out about the error by querying the target. */
5320 async_client_callback (INF_REG_EVENT
, async_client_context
);
5324 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5326 if (callback
!= NULL
)
5328 SERIAL_ASYNC (remote_desc
, remote_async_serial_handler
, NULL
);
5329 async_client_callback
= callback
;
5330 async_client_context
= context
;
5333 SERIAL_ASYNC (remote_desc
, NULL
, NULL
);
5336 /* Target async and target extended-async.
5338 This are temporary targets, until it is all tested. Eventually
5339 async support will be incorporated int the usual 'remote'
5343 init_remote_async_ops (void)
5345 remote_async_ops
.to_shortname
= "async";
5346 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5347 remote_async_ops
.to_doc
=
5348 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5349 Specify the serial device it is connected to (e.g. /dev/ttya).";
5350 remote_async_ops
.to_open
= remote_async_open
;
5351 remote_async_ops
.to_close
= remote_close
;
5352 remote_async_ops
.to_detach
= remote_async_detach
;
5353 remote_async_ops
.to_resume
= remote_async_resume
;
5354 remote_async_ops
.to_wait
= remote_async_wait
;
5355 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5356 remote_async_ops
.to_store_registers
= remote_store_registers
;
5357 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5358 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5359 remote_async_ops
.to_files_info
= remote_files_info
;
5360 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5361 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5362 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5363 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5364 remote_async_ops
.to_kill
= remote_async_kill
;
5365 remote_async_ops
.to_load
= generic_load
;
5366 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5367 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5368 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5369 remote_async_ops
.to_stop
= remote_stop
;
5370 remote_async_ops
.to_query
= remote_query
;
5371 remote_async_ops
.to_rcmd
= remote_rcmd
;
5372 remote_async_ops
.to_stratum
= process_stratum
;
5373 remote_async_ops
.to_has_all_memory
= 1;
5374 remote_async_ops
.to_has_memory
= 1;
5375 remote_async_ops
.to_has_stack
= 1;
5376 remote_async_ops
.to_has_registers
= 1;
5377 remote_async_ops
.to_has_execution
= 1;
5378 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5379 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5380 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5381 remote_async_ops
.to_async
= remote_async
;
5382 remote_async_ops
.to_magic
= OPS_MAGIC
;
5385 /* Set up the async extended remote vector by making a copy of the standard
5386 remote vector and adding to it. */
5389 init_extended_async_remote_ops (void)
5391 extended_async_remote_ops
= remote_async_ops
;
5393 extended_async_remote_ops
.to_shortname
= "extended-async";
5394 extended_async_remote_ops
.to_longname
=
5395 "Extended remote serial target in async gdb-specific protocol";
5396 extended_async_remote_ops
.to_doc
=
5397 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5398 Specify the serial device it is connected to (e.g. /dev/ttya).",
5399 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5400 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5401 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5405 set_remote_cmd (char *args
, int from_tty
)
5412 build_remote_gdbarch_data ()
5414 build_remote_packet_sizes ();
5417 tty_input
= xmalloc (PBUFSIZ
);
5418 remote_address_size
= TARGET_PTR_BIT
;
5422 _initialize_remote ()
5424 static struct cmd_list_element
*remote_set_cmdlist
;
5425 static struct cmd_list_element
*remote_show_cmdlist
;
5426 struct cmd_list_element
*tmpcmd
;
5428 /* architecture specific data */
5429 build_remote_gdbarch_data ();
5430 register_gdbarch_swap (&tty_input
, sizeof (&tty_input
), NULL
);
5431 register_remote_packet_sizes ();
5432 register_gdbarch_swap (&remote_address_size
,
5433 sizeof (&remote_address_size
), NULL
);
5434 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5437 add_target (&remote_ops
);
5439 init_extended_remote_ops ();
5440 add_target (&extended_remote_ops
);
5442 init_remote_async_ops ();
5443 add_target (&remote_async_ops
);
5445 init_extended_async_remote_ops ();
5446 add_target (&extended_async_remote_ops
);
5448 init_remote_cisco_ops ();
5449 add_target (&remote_cisco_ops
);
5452 init_remote_threadtests ();
5455 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5456 Remote protocol specific variables\n\
5457 Configure various remote-protocol specific variables such as\n\
5458 the packets being used",
5459 &remote_set_cmdlist
, "set remote ",
5460 0/*allow-unknown*/, &setlist
);
5461 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5462 Remote protocol specific variables\n\
5463 Configure various remote-protocol specific variables such as\n\
5464 the packets being used",
5465 &remote_show_cmdlist
, "show remote ",
5466 0/*allow-unknown*/, &showlist
);
5468 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
5469 "Compare section data on target to the exec file.\n\
5470 Argument is a single section name (default: all loaded sections).",
5473 add_cmd ("packet", class_maintenance
, packet_command
,
5474 "Send an arbitrary packet to a remote target.\n\
5475 maintenance packet TEXT\n\
5476 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5477 this command sends the string TEXT to the inferior, and displays the\n\
5478 response packet. GDB supplies the initial `$' character, and the\n\
5479 terminating `#' character and checksum.",
5483 (add_set_cmd ("remotetimeout", no_class
,
5484 var_integer
, (char *) &remote_timeout
,
5485 "Set timeout value for remote read.\n",
5490 (add_set_cmd ("remotebreak", no_class
,
5491 var_boolean
, (char *) &remote_break
,
5492 "Set whether to send break if interrupted.\n",
5496 /* Install commands for configuring memory read/write packets. */
5498 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
5499 "Set the maximum number of bytes per memory write packet (deprecated).\n",
5501 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
5502 "Show the maximum number of bytes per memory write packet (deprecated).\n",
5504 add_cmd ("memory-write-packet-size", no_class
,
5505 set_memory_write_packet_size
,
5506 "Set the maximum number of bytes per memory-write packet.\n"
5507 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5508 "default packet size. The actual limit is further reduced\n"
5509 "dependent on the target. Specify ``fixed'' to disable the\n"
5510 "further restriction and ``limit'' to enable that restriction\n",
5511 &remote_set_cmdlist
);
5512 add_cmd ("memory-read-packet-size", no_class
,
5513 set_memory_read_packet_size
,
5514 "Set the maximum number of bytes per memory-read packet.\n"
5515 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5516 "default packet size. The actual limit is further reduced\n"
5517 "dependent on the target. Specify ``fixed'' to disable the\n"
5518 "further restriction and ``limit'' to enable that restriction\n",
5519 &remote_set_cmdlist
);
5520 add_cmd ("memory-write-packet-size", no_class
,
5521 show_memory_write_packet_size
,
5522 "Show the maximum number of bytes per memory-write packet.\n",
5523 &remote_show_cmdlist
);
5524 add_cmd ("memory-read-packet-size", no_class
,
5525 show_memory_read_packet_size
,
5526 "Show the maximum number of bytes per memory-read packet.\n",
5527 &remote_show_cmdlist
);
5530 (add_set_cmd ("remoteaddresssize", class_obscure
,
5531 var_integer
, (char *) &remote_address_size
,
5532 "Set the maximum size of the address (in bits) \
5533 in a memory packet.\n",
5537 add_packet_config_cmd (&remote_protocol_binary_download
,
5538 "X", "binary-download",
5539 set_remote_protocol_binary_download_cmd
,
5540 show_remote_protocol_binary_download_cmd
,
5541 &remote_set_cmdlist
, &remote_show_cmdlist
);
5543 /* XXXX - should ``set remotebinarydownload'' be retained for
5546 (add_set_cmd ("remotebinarydownload", no_class
,
5547 var_boolean
, (char *) &remote_binary_download
,
5548 "Set binary downloads.\n", &setlist
),
5552 add_info ("remote-process", remote_info_process
,
5553 "Query the remote system for process info.");
5555 add_packet_config_cmd (&remote_protocol_P
, "P", "set-register",
5556 set_remote_protocol_P_packet_cmd
,
5557 show_remote_protocol_P_packet_cmd
,
5558 &remote_set_cmdlist
, &remote_show_cmdlist
);
5560 add_packet_config_cmd (&remote_protocol_Z
, "Z", "breakpoint",
5561 set_remote_protocol_Z_packet_cmd
,
5562 show_remote_protocol_Z_packet_cmd
,
5563 &remote_set_cmdlist
, &remote_show_cmdlist
);