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"
45 #include <sys/types.h>
48 #include "event-loop.h"
53 /* Prototypes for local functions */
54 static void initialize_sigint_signal_handler
PARAMS ((void));
55 static void handle_remote_sigint
PARAMS ((int));
56 static void handle_remote_sigint_twice
PARAMS ((int));
57 static void async_remote_interrupt
PARAMS ((gdb_client_data
));
58 static void async_remote_interrupt_twice
PARAMS ((gdb_client_data
));
60 static void set_extended_protocol
PARAMS ((struct continuation_arg
*));
62 static void build_remote_gdbarch_data
PARAMS ((void));
64 static int remote_write_bytes
PARAMS ((CORE_ADDR memaddr
,
65 char *myaddr
, int len
));
67 static int remote_read_bytes
PARAMS ((CORE_ADDR memaddr
,
68 char *myaddr
, int len
));
70 static void remote_files_info
PARAMS ((struct target_ops
* ignore
));
72 static int remote_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
,
73 int len
, int should_write
,
74 struct target_ops
* target
));
76 static void remote_prepare_to_store
PARAMS ((void));
78 static void remote_fetch_registers
PARAMS ((int regno
));
80 static void remote_resume
PARAMS ((int pid
, int step
,
81 enum target_signal siggnal
));
82 static void remote_async_resume
PARAMS ((int pid
, int step
,
83 enum target_signal siggnal
));
85 static int remote_start_remote
PARAMS ((PTR
));
87 static void remote_open
PARAMS ((char *name
, int from_tty
));
88 static void remote_async_open
PARAMS ((char *name
, int from_tty
));
90 static void extended_remote_open
PARAMS ((char *name
, int from_tty
));
91 static void extended_remote_async_open
PARAMS ((char *name
, int from_tty
));
93 static void remote_open_1
PARAMS ((char *, int, struct target_ops
*,
95 static void remote_async_open_1
PARAMS ((char *, int, struct target_ops
*,
98 static void remote_close
PARAMS ((int quitting
));
100 static void remote_store_registers
PARAMS ((int regno
));
102 static void remote_mourn
PARAMS ((void));
104 static void extended_remote_restart
PARAMS ((void));
106 static void extended_remote_mourn
PARAMS ((void));
108 static void extended_remote_create_inferior
PARAMS ((char *, char *, char **));
109 static void extended_remote_async_create_inferior
PARAMS ((char *, char *, char **));
111 static void remote_mourn_1
PARAMS ((struct target_ops
*));
113 static void remote_send
PARAMS ((char *buf
));
115 static int readchar
PARAMS ((int timeout
));
117 static int remote_wait
PARAMS ((int pid
, struct target_waitstatus
* status
));
118 static int remote_async_wait
PARAMS ((int pid
, struct target_waitstatus
* status
));
120 static void remote_kill
PARAMS ((void));
121 static void remote_async_kill
PARAMS ((void));
123 static int tohex
PARAMS ((int nib
));
125 static void remote_detach
PARAMS ((char *args
, int from_tty
));
126 static void remote_async_detach
PARAMS ((char *args
, int from_tty
));
128 static void remote_interrupt
PARAMS ((int signo
));
130 static void remote_interrupt_twice
PARAMS ((int signo
));
132 static void interrupt_query
PARAMS ((void));
134 static void set_thread
PARAMS ((int, int));
136 static int remote_thread_alive
PARAMS ((int));
138 static void get_offsets
PARAMS ((void));
140 static int read_frame
PARAMS ((char *));
142 static int remote_insert_breakpoint
PARAMS ((CORE_ADDR
, char *));
144 static int remote_remove_breakpoint
PARAMS ((CORE_ADDR
, char *));
146 static int hexnumlen
PARAMS ((ULONGEST num
));
148 static void init_remote_ops
PARAMS ((void));
150 static void init_extended_remote_ops
PARAMS ((void));
152 static void init_remote_cisco_ops
PARAMS ((void));
154 static struct target_ops remote_cisco_ops
;
156 static void remote_stop
PARAMS ((void));
158 static int ishex
PARAMS ((int ch
, int *val
));
160 static int stubhex
PARAMS ((int ch
));
162 static int remote_query
PARAMS ((int /*char */ , char *, char *, int *));
164 static int hexnumstr
PARAMS ((char *, ULONGEST
));
166 static CORE_ADDR remote_address_masked
PARAMS ((CORE_ADDR
));
168 static void print_packet
PARAMS ((char *));
170 static unsigned long crc32
PARAMS ((unsigned char *, int, unsigned int));
172 static void compare_sections_command
PARAMS ((char *, int));
174 static void packet_command
PARAMS ((char *, int));
176 static int stub_unpack_int
PARAMS ((char *buff
, int fieldlength
));
178 static int remote_current_thread
PARAMS ((int oldpid
));
180 static void remote_find_new_threads
PARAMS ((void));
182 static void record_currthread
PARAMS ((int currthread
));
184 /* exported functions */
186 extern int fromhex
PARAMS ((int a
));
188 extern void getpkt
PARAMS ((char *buf
, int forever
));
190 extern int putpkt
PARAMS ((char *buf
));
192 static int putpkt_binary
PARAMS ((char *buf
, int cnt
));
194 void remote_console_output
PARAMS ((char *));
196 static void check_binary_download
PARAMS ((CORE_ADDR addr
));
199 struct packet_config
;
202 static void show_packet_config_cmd
PARAMS ((struct packet_config
* config
));
204 static void set_packet_config_cmd
PARAMS ((struct packet_config
* config
,
205 struct cmd_list_element
* c
));
207 static void add_packet_config_cmd
PARAMS ((struct packet_config
* config
,
210 void (*set_func
) (char *args
, int from_tty
, struct cmd_list_element
* c
),
211 void (*show_func
) (char *name
, int from_tty
),
212 struct cmd_list_element
**setlist
,
213 struct cmd_list_element
**showlist
));
215 static void init_packet_config
PARAMS ((struct packet_config
* config
));
217 static void set_remote_protocol_P_packet_cmd
PARAMS ((char *args
,
219 struct cmd_list_element
* c
));
221 static void show_remote_protocol_P_packet_cmd
PARAMS ((char *args
,
224 static void set_remote_protocol_Z_packet_cmd
PARAMS ((char *args
,
226 struct cmd_list_element
* c
));
228 static void show_remote_protocol_Z_packet_cmd
PARAMS ((char *args
,
234 /* Define the target subroutine names */
236 void open_remote_target
PARAMS ((char *, int, struct target_ops
*, int));
238 void _initialize_remote
PARAMS ((void));
242 static struct target_ops remote_ops
;
244 static struct target_ops extended_remote_ops
;
246 /* Temporary target ops. Just like the remote_ops and
247 extended_remote_ops, but with asynchronous support. */
248 static struct target_ops remote_async_ops
;
250 static struct target_ops extended_async_remote_ops
;
252 /* This was 5 seconds, which is a long time to sit and wait.
253 Unless this is going though some terminal server or multiplexer or
254 other form of hairy serial connection, I would think 2 seconds would
257 /* Changed to allow option to set timeout value.
258 was static int remote_timeout = 2; */
259 extern int remote_timeout
;
261 /* This variable chooses whether to send a ^C or a break when the user
262 requests program interruption. Although ^C is usually what remote
263 systems expect, and that is the default here, sometimes a break is
264 preferable instead. */
266 static int remote_break
;
268 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
269 remote_open knows that we don't have a file open when the program
271 static serial_t remote_desc
= NULL
;
273 /* This is set by the target (thru the 'S' message)
274 to denote that the target is in kernel mode. */
275 static int cisco_kernel_mode
= 0;
277 /* Maximum number of bytes to read/write at once. The value here
278 is chosen to fill up a packet (the headers account for the 32). */
279 #define MAXBUFBYTES(N) (((N)-32)/2)
281 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
282 and i386-stub.c. Normally, no one would notice because it only matters
283 for writing large chunks of memory (e.g. in downloads). Also, this needs
284 to be more than 400 if required to hold the registers (see below, where
285 we round it up based on REGISTER_BYTES). */
286 /* Round up PBUFSIZ to hold all the registers, at least. */
287 #define PBUFSIZ ((REGISTER_BYTES > MAXBUFBYTES (400)) \
288 ? (REGISTER_BYTES * 2 + 32) \
292 /* This variable sets the number of bytes to be written to the target
293 in a single packet. Normally PBUFSIZ is satisfactory, but some
294 targets need smaller values (perhaps because the receiving end
297 static int remote_write_size
;
299 /* This variable sets the number of bits in an address that are to be
300 sent in a memory ("M" or "m") packet. Normally, after stripping
301 leading zeros, the entire address would be sent. This variable
302 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
303 initial implementation of remote.c restricted the address sent in
304 memory packets to ``host::sizeof long'' bytes - (typically 32
305 bits). Consequently, for 64 bit targets, the upper 32 bits of an
306 address was never sent. Since fixing this bug may cause a break in
307 some remote targets this variable is principly provided to
308 facilitate backward compatibility. */
310 static int remote_address_size
;
312 /* This is the size (in chars) of the first response to the `g' command. This
313 is used to limit the size of the memory read and write commands to prevent
314 stub buffers from overflowing. The size does not include headers and
315 trailers, it is only the payload size. */
317 static int remote_register_buf_size
= 0;
319 /* Generic configuration support for packets the stub optionally
320 supports. Allows the user to specify the use of the packet as well
321 as allowing GDB to auto-detect support in the remote stub. */
325 PACKET_SUPPORT_UNKNOWN
= 0,
332 PACKET_AUTO_DETECT
= 0,
341 enum packet_detect detect
;
342 enum packet_support support
;
345 static char packet_support_auto
[] = "auto";
346 static char packet_enable
[] = "enable";
347 static char packet_disable
[] = "disable";
348 static char *packet_support_enums
[] =
357 set_packet_config_cmd (config
, c
)
358 struct packet_config
*config
;
359 struct cmd_list_element
*c
;
361 if (config
->state
== packet_enable
)
363 config
->detect
= PACKET_MANUAL_DETECT
;
364 config
->support
= PACKET_ENABLE
;
366 else if (config
->state
== packet_disable
)
368 config
->detect
= PACKET_MANUAL_DETECT
;
369 config
->support
= PACKET_DISABLE
;
371 else if (config
->state
== packet_support_auto
)
373 config
->detect
= PACKET_AUTO_DETECT
;
374 config
->support
= PACKET_SUPPORT_UNKNOWN
;
377 internal_error ("Bad enum value");
381 show_packet_config_cmd (config
)
382 struct packet_config
*config
;
384 char *support
= "internal-error";
385 switch (config
->support
)
391 support
= "disabled";
393 case PACKET_SUPPORT_UNKNOWN
:
397 switch (config
->detect
)
399 case PACKET_AUTO_DETECT
:
400 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
401 config
->name
, config
->title
, support
);
403 case PACKET_MANUAL_DETECT
:
404 printf_filtered ("Support for remote protocol `%s' (%s) is currently %s.\n",
405 config
->name
, config
->title
, support
);
410 add_packet_config_cmd (config
, name
, title
, set_func
, show_func
,
412 struct packet_config
*config
;
415 void (*set_func
) PARAMS ((char *args
, int from_tty
,
416 struct cmd_list_element
* c
));
417 void (*show_func
) PARAMS ((char *name
, int from_tty
));
418 struct cmd_list_element
**setlist
;
419 struct cmd_list_element
**showlist
;
421 struct cmd_list_element
*c
;
426 config
->title
= title
;
427 asprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
429 asprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
431 asprintf (&full_name
, "%s-packet", name
);
432 c
= add_set_enum_cmd (full_name
,
433 class_obscure
, packet_support_enums
,
434 (char *) &config
->state
,
436 c
->function
.sfunc
= set_func
;
437 add_cmd (full_name
, class_obscure
, show_func
, show_doc
, showlist
);
441 init_packet_config (config
)
442 struct packet_config
*config
;
444 switch (config
->detect
)
446 case PACKET_AUTO_DETECT
:
447 config
->support
= PACKET_SUPPORT_UNKNOWN
;
449 case PACKET_MANUAL_DETECT
:
450 /* let the user beware */
455 /* Should we try the 'P' (set register) request? */
457 static struct packet_config remote_protocol_P
;
460 set_remote_protocol_P_packet_cmd (args
, from_tty
, c
)
463 struct cmd_list_element
*c
;
465 set_packet_config_cmd (&remote_protocol_P
, c
);
469 show_remote_protocol_P_packet_cmd (args
, from_tty
)
473 show_packet_config_cmd (&remote_protocol_P
);
476 /* Should we try the 'Z' (set breakpoint) request? */
478 static struct packet_config remote_protocol_Z
;
481 set_remote_protocol_Z_packet_cmd (args
, from_tty
, c
)
484 struct cmd_list_element
*c
;
486 set_packet_config_cmd (&remote_protocol_Z
, c
);
490 show_remote_protocol_Z_packet_cmd (args
, from_tty
)
494 show_packet_config_cmd (&remote_protocol_Z
);
497 /* Should we try the 'X' (remote binary download) packet?
499 This variable (available to the user via "set remote X-packet")
500 dictates whether downloads are sent in binary (via the 'X' packet).
501 We assume that the stub can, and attempt to do it. This will be
502 cleared if the stub does not understand it. This switch is still
503 needed, though in cases when the packet is supported in the stub,
504 but the connection does not allow it (i.e., 7-bit serial connection
507 static struct packet_config remote_protocol_binary_download
;
510 set_remote_protocol_binary_download_cmd (char *args
,
512 struct cmd_list_element
*c
)
514 set_packet_config_cmd (&remote_protocol_binary_download
, c
);
518 show_remote_protocol_binary_download_cmd (char *args
,
521 show_packet_config_cmd (&remote_protocol_binary_download
);
525 /* Tokens for use by the asynchronous signal handlers for SIGINT */
526 PTR sigint_remote_twice_token
;
527 PTR sigint_remote_token
;
529 /* These are pointers to hook functions that may be set in order to
530 modify resume/wait behavior for a particular architecture. */
532 void (*target_resume_hook
) PARAMS ((void));
533 void (*target_wait_loop_hook
) PARAMS ((void));
537 /* These are the threads which we last sent to the remote system.
538 -1 for all or -2 for not sent yet. */
539 static int general_thread
;
540 static int continue_thread
;
542 /* Call this function as a result of
543 1) A halt indication (T packet) containing a thread id
544 2) A direct query of currthread
545 3) Successful execution of set thread
549 record_currthread (currthread
)
552 general_thread
= currthread
;
554 /* If this is a new thread, add it to GDB's thread list.
555 If we leave it up to WFI to do this, bad things will happen. */
556 if (!in_thread_list (currthread
))
558 add_thread (currthread
);
559 printf_filtered ("[New %s]\n", target_pid_to_str (currthread
));
563 #define MAGIC_NULL_PID 42000
570 char *buf
= alloca (PBUFSIZ
);
571 int state
= gen
? general_thread
: continue_thread
;
577 buf
[1] = gen
? 'g' : 'c';
578 if (th
== MAGIC_NULL_PID
)
584 sprintf (&buf
[2], "-%x", -th
);
586 sprintf (&buf
[2], "%x", th
);
592 continue_thread
= th
;
595 /* Return nonzero if the thread TH is still alive on the remote system. */
598 remote_thread_alive (tid
)
604 sprintf (buf
, "T-%08x", -tid
);
606 sprintf (buf
, "T%08x", tid
);
609 return (buf
[0] == 'O' && buf
[1] == 'K');
612 /* About these extended threadlist and threadinfo packets. They are
613 variable length packets but, the fields within them are often fixed
614 length. They are redundent enough to send over UDP as is the
615 remote protocol in general. There is a matching unit test module
618 #define OPAQUETHREADBYTES 8
620 /* a 64 bit opaque identifier */
621 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
623 /* WARNING: This threadref data structure comes from the remote O.S., libstub
624 protocol encoding, and remote.c. it is not particularly changable */
626 /* Right now, the internal structure is int. We want it to be bigger.
630 typedef int gdb_threadref
; /* internal GDB thread reference */
632 /* gdb_ext_thread_info is an internal GDB data structure which is
633 equivalint to the reply of the remote threadinfo packet */
635 struct gdb_ext_thread_info
637 threadref threadid
; /* External form of thread reference */
638 int active
; /* Has state interesting to GDB? , regs, stack */
639 char display
[256]; /* Brief state display, name, blocked/syspended */
640 char shortname
[32]; /* To be used to name threads */
641 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
644 /* The volume of remote transfers can be limited by submitting
645 a mask containing bits specifying the desired information.
646 Use a union of these values as the 'selection' parameter to
647 get_thread_info. FIXME: Make these TAG names more thread specific.
650 #define TAG_THREADID 1
652 #define TAG_DISPLAY 4
653 #define TAG_THREADNAME 8
654 #define TAG_MOREDISPLAY 16
656 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
658 char *unpack_varlen_hex
PARAMS ((char *buff
, int *result
));
660 static char *unpack_nibble
PARAMS ((char *buf
, int *val
));
662 static char *pack_nibble
PARAMS ((char *buf
, int nibble
));
664 static char *pack_hex_byte
PARAMS ((char *pkt
, int /*unsigned char */ byte
));
666 static char *unpack_byte
PARAMS ((char *buf
, int *value
));
668 static char *pack_int
PARAMS ((char *buf
, int value
));
670 static char *unpack_int
PARAMS ((char *buf
, int *value
));
672 static char *unpack_string
PARAMS ((char *src
, char *dest
, int length
));
674 static char *pack_threadid
PARAMS ((char *pkt
, threadref
* id
));
676 static char *unpack_threadid
PARAMS ((char *inbuf
, threadref
* id
));
678 void int_to_threadref
PARAMS ((threadref
* id
, int value
));
680 static int threadref_to_int
PARAMS ((threadref
* ref
));
682 static void copy_threadref
PARAMS ((threadref
* dest
, threadref
* src
));
684 static int threadmatch
PARAMS ((threadref
* dest
, threadref
* src
));
686 static char *pack_threadinfo_request
PARAMS ((char *pkt
, int mode
,
689 static int remote_unpack_thread_info_response
PARAMS ((char *pkt
,
690 threadref
* expectedref
,
691 struct gdb_ext_thread_info
* info
));
694 static int remote_get_threadinfo
PARAMS ((threadref
* threadid
,
695 int fieldset
, /*TAG mask */
696 struct gdb_ext_thread_info
* info
));
698 static int adapt_remote_get_threadinfo
PARAMS ((gdb_threadref
* ref
,
700 struct gdb_ext_thread_info
* info
));
702 static char *pack_threadlist_request
PARAMS ((char *pkt
, int startflag
,
704 threadref
* nextthread
));
706 static int parse_threadlist_response
PARAMS ((char *pkt
,
708 threadref
* original_echo
,
709 threadref
* resultlist
,
712 static int remote_get_threadlist
PARAMS ((int startflag
,
713 threadref
* nextthread
,
717 threadref
* threadlist
));
719 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
721 static int remote_threadlist_iterator
PARAMS ((rmt_thread_action stepfunction
,
722 void *context
, int looplimit
));
724 static int remote_newthread_step
PARAMS ((threadref
* ref
, void *context
));
726 /* encode 64 bits in 16 chars of hex */
728 static const char hexchars
[] = "0123456789abcdef";
735 if ((ch
>= 'a') && (ch
<= 'f'))
737 *val
= ch
- 'a' + 10;
740 if ((ch
>= 'A') && (ch
<= 'F'))
742 *val
= ch
- 'A' + 10;
745 if ((ch
>= '0') && (ch
<= '9'))
757 if (ch
>= 'a' && ch
<= 'f')
758 return ch
- 'a' + 10;
759 if (ch
>= '0' && ch
<= '9')
761 if (ch
>= 'A' && ch
<= 'F')
762 return ch
- 'A' + 10;
767 stub_unpack_int (buff
, fieldlength
)
776 nibble
= stubhex (*buff
++);
780 retval
= retval
<< 4;
786 unpack_varlen_hex (buff
, result
)
787 char *buff
; /* packet to parse */
793 while (ishex (*buff
, &nibble
))
796 retval
= retval
<< 4;
797 retval
|= nibble
& 0x0f;
804 unpack_nibble (buf
, val
)
813 pack_nibble (buf
, nibble
)
817 *buf
++ = hexchars
[(nibble
& 0x0f)];
822 pack_hex_byte (pkt
, byte
)
826 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
827 *pkt
++ = hexchars
[(byte
& 0xf)];
832 unpack_byte (buf
, value
)
836 *value
= stub_unpack_int (buf
, 2);
841 pack_int (buf
, value
)
845 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
846 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
847 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
848 buf
= pack_hex_byte (buf
, (value
& 0xff));
853 unpack_int (buf
, value
)
857 *value
= stub_unpack_int (buf
, 8);
861 #if 0 /* currently unused, uncomment when needed */
862 static char *pack_string
PARAMS ((char *pkt
, char *string
));
865 pack_string (pkt
, string
)
872 len
= strlen (string
);
874 len
= 200; /* Bigger than most GDB packets, junk??? */
875 pkt
= pack_hex_byte (pkt
, len
);
879 if ((ch
== '\0') || (ch
== '#'))
880 ch
= '*'; /* Protect encapsulation */
885 #endif /* 0 (unused) */
888 unpack_string (src
, dest
, length
)
900 pack_threadid (pkt
, id
)
905 unsigned char *altid
;
907 altid
= (unsigned char *) id
;
908 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
910 pkt
= pack_hex_byte (pkt
, *altid
++);
916 unpack_threadid (inbuf
, id
)
921 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
924 altref
= (char *) id
;
926 while (inbuf
< limit
)
928 x
= stubhex (*inbuf
++);
929 y
= stubhex (*inbuf
++);
930 *altref
++ = (x
<< 4) | y
;
935 /* Externally, threadrefs are 64 bits but internally, they are still
936 ints. This is due to a mismatch of specifications. We would like
937 to use 64bit thread references internally. This is an adapter
941 int_to_threadref (id
, value
)
947 scan
= (unsigned char *) id
;
953 *scan
++ = (value
>> 24) & 0xff;
954 *scan
++ = (value
>> 16) & 0xff;
955 *scan
++ = (value
>> 8) & 0xff;
956 *scan
++ = (value
& 0xff);
960 threadref_to_int (ref
)
970 value
= (value
<< 8) | ((*scan
++) & 0xff);
975 copy_threadref (dest
, src
)
980 unsigned char *csrc
, *cdest
;
982 csrc
= (unsigned char *) src
;
983 cdest
= (unsigned char *) dest
;
990 threadmatch (dest
, src
)
994 /* things are broken right now, so just assume we got a match */
996 unsigned char *srcp
, *destp
;
999 destp
= (char *) dest
;
1003 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1010 threadid:1, # always request threadid
1017 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1020 pack_threadinfo_request (pkt
, mode
, id
)
1025 *pkt
++ = 'q'; /* Info Query */
1026 *pkt
++ = 'P'; /* process or thread info */
1027 pkt
= pack_int (pkt
, mode
); /* mode */
1028 pkt
= pack_threadid (pkt
, id
); /* threadid */
1029 *pkt
= '\0'; /* terminate */
1033 /* These values tag the fields in a thread info response packet */
1034 /* Tagging the fields allows us to request specific fields and to
1035 add more fields as time goes by */
1037 #define TAG_THREADID 1 /* Echo the thread identifier */
1038 #define TAG_EXISTS 2 /* Is this process defined enough to
1039 fetch registers and its stack */
1040 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1041 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1042 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1046 remote_unpack_thread_info_response (pkt
, expectedref
, info
)
1048 threadref
*expectedref
;
1049 struct gdb_ext_thread_info
*info
;
1054 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
1057 /* info->threadid = 0; FIXME: implement zero_threadref */
1059 info
->display
[0] = '\0';
1060 info
->shortname
[0] = '\0';
1061 info
->more_display
[0] = '\0';
1063 /* Assume the characters indicating the packet type have been stripped */
1064 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1065 pkt
= unpack_threadid (pkt
, &ref
);
1068 warning ("Incomplete response to threadinfo request\n");
1069 if (!threadmatch (&ref
, expectedref
))
1070 { /* This is an answer to a different request */
1071 warning ("ERROR RMT Thread info mismatch\n");
1074 copy_threadref (&info
->threadid
, &ref
);
1076 /* Loop on tagged fields , try to bail if somthing goes wrong */
1078 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1080 pkt
= unpack_int (pkt
, &tag
); /* tag */
1081 pkt
= unpack_byte (pkt
, &length
); /* length */
1082 if (!(tag
& mask
)) /* tags out of synch with mask */
1084 warning ("ERROR RMT: threadinfo tag mismatch\n");
1088 if (tag
== TAG_THREADID
)
1092 warning ("ERROR RMT: length of threadid is not 16\n");
1096 pkt
= unpack_threadid (pkt
, &ref
);
1097 mask
= mask
& ~TAG_THREADID
;
1100 if (tag
== TAG_EXISTS
)
1102 info
->active
= stub_unpack_int (pkt
, length
);
1104 mask
= mask
& ~(TAG_EXISTS
);
1107 warning ("ERROR RMT: 'exists' length too long\n");
1113 if (tag
== TAG_THREADNAME
)
1115 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1116 mask
= mask
& ~TAG_THREADNAME
;
1119 if (tag
== TAG_DISPLAY
)
1121 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1122 mask
= mask
& ~TAG_DISPLAY
;
1125 if (tag
== TAG_MOREDISPLAY
)
1127 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1128 mask
= mask
& ~TAG_MOREDISPLAY
;
1131 warning ("ERROR RMT: unknown thread info tag\n");
1132 break; /* Not a tag we know about */
1138 remote_get_threadinfo (threadid
, fieldset
, info
)
1139 threadref
*threadid
;
1140 int fieldset
; /* TAG mask */
1141 struct gdb_ext_thread_info
*info
;
1144 char *threadinfo_pkt
= alloca (PBUFSIZ
);
1146 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1147 putpkt (threadinfo_pkt
);
1148 getpkt (threadinfo_pkt
, 0);
1149 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1154 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1155 representation of a threadid. */
1158 adapt_remote_get_threadinfo (ref
, selection
, info
)
1161 struct gdb_ext_thread_info
*info
;
1165 int_to_threadref (&lclref
, *ref
);
1166 return remote_get_threadinfo (&lclref
, selection
, info
);
1169 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1172 pack_threadlist_request (pkt
, startflag
, threadcount
, nextthread
)
1176 threadref
*nextthread
;
1178 *pkt
++ = 'q'; /* info query packet */
1179 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1180 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1181 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1182 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1187 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1190 parse_threadlist_response (pkt
, result_limit
, original_echo
, resultlist
,
1194 threadref
*original_echo
;
1195 threadref
*resultlist
;
1199 int count
, resultcount
, done
;
1202 /* Assume the 'q' and 'M chars have been stripped. */
1203 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1204 pkt
= unpack_byte (pkt
, &count
); /* count field */
1205 pkt
= unpack_nibble (pkt
, &done
);
1206 /* The first threadid is the argument threadid. */
1207 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1208 while ((count
-- > 0) && (pkt
< limit
))
1210 pkt
= unpack_threadid (pkt
, resultlist
++);
1211 if (resultcount
++ >= result_limit
)
1220 remote_get_threadlist (startflag
, nextthread
, result_limit
,
1221 done
, result_count
, threadlist
)
1223 threadref
*nextthread
;
1227 threadref
*threadlist
;
1230 static threadref echo_nextthread
;
1231 char *threadlist_packet
= alloca (PBUFSIZ
);
1232 char *t_response
= alloca (PBUFSIZ
);
1235 /* Trancate result limit to be smaller than the packet size */
1236 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1237 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1239 pack_threadlist_request (threadlist_packet
,
1240 startflag
, result_limit
, nextthread
);
1241 putpkt (threadlist_packet
);
1242 getpkt (t_response
, 0);
1245 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1248 if (!threadmatch (&echo_nextthread
, nextthread
))
1250 /* FIXME: This is a good reason to drop the packet */
1251 /* Possably, there is a duplicate response */
1253 retransmit immediatly - race conditions
1254 retransmit after timeout - yes
1256 wait for packet, then exit
1258 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1259 return 0; /* I choose simply exiting */
1261 if (*result_count
<= 0)
1265 warning ("RMT ERROR : failed to get remote thread list\n");
1268 return result
; /* break; */
1270 if (*result_count
> result_limit
)
1273 warning ("RMT ERROR: threadlist response longer than requested\n");
1279 /* This is the interface between remote and threads, remotes upper interface */
1281 /* remote_find_new_threads retrieves the thread list and for each
1282 thread in the list, looks up the thread in GDB's internal list,
1283 ading the thread if it does not already exist. This involves
1284 getting partial thread lists from the remote target so, polling the
1285 quit_flag is required. */
1288 /* About this many threadisds fit in a packet. */
1290 #define MAXTHREADLISTRESULTS 32
1293 remote_threadlist_iterator (stepfunction
, context
, looplimit
)
1294 rmt_thread_action stepfunction
;
1298 int done
, i
, result_count
;
1302 static threadref nextthread
;
1303 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1308 if (loopcount
++ > looplimit
)
1311 warning ("Remote fetch threadlist -infinite loop-\n");
1314 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1315 &done
, &result_count
, resultthreadlist
))
1320 /* clear for later iterations */
1322 /* Setup to resume next batch of thread references, set nextthread. */
1323 if (result_count
>= 1)
1324 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1326 while (result_count
--)
1327 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1334 remote_newthread_step (ref
, context
)
1340 pid
= threadref_to_int (ref
);
1341 if (!in_thread_list (pid
))
1343 return 1; /* continue iterator */
1346 #define CRAZY_MAX_THREADS 1000
1349 remote_current_thread (oldpid
)
1352 char *buf
= alloca (PBUFSIZ
);
1356 if (buf
[0] == 'Q' && buf
[1] == 'C')
1357 return strtol (&buf
[2], NULL
, 16);
1362 /* Find new threads for info threads command. */
1365 remote_find_new_threads ()
1367 remote_threadlist_iterator (remote_newthread_step
, 0,
1369 if (inferior_pid
== MAGIC_NULL_PID
) /* ack ack ack */
1370 inferior_pid
= remote_current_thread (inferior_pid
);
1374 remote_threads_info (void)
1376 char *buf
= alloca (PBUFSIZ
);
1380 if (remote_desc
== 0) /* paranoia */
1381 error ("Command can only be used when connected to the remote target.");
1383 putpkt ("qfThreadInfo");
1384 getpkt (bufp
= buf
, 0);
1385 if (bufp
[0] == '\0') /* q packet not recognized! */
1386 { /* try old jmetzler method */
1387 remote_find_new_threads ();
1390 else /* try new 'q' method */
1391 while (*bufp
++ == 'm') /* reply contains one or more TID */
1395 tid
= strtol (bufp
, &bufp
, 16);
1396 if (tid
!= 0 && !in_thread_list (tid
))
1399 while (*bufp
++ == ','); /* comma-separated list */
1400 putpkt ("qsThreadInfo");
1401 getpkt (bufp
= buf
, 0);
1406 /* Restart the remote side; this is an extended protocol operation. */
1409 extended_remote_restart ()
1411 char *buf
= alloca (PBUFSIZ
);
1413 /* Send the restart command; for reasons I don't understand the
1414 remote side really expects a number after the "R". */
1416 sprintf (&buf
[1], "%x", 0);
1419 /* Now query for status so this looks just like we restarted
1420 gdbserver from scratch. */
1425 /* Clean up connection to a remote debugger. */
1429 remote_close (quitting
)
1433 SERIAL_CLOSE (remote_desc
);
1437 /* Query the remote side for the text, data and bss offsets. */
1442 char *buf
= alloca (PBUFSIZ
);
1445 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1446 struct section_offsets
*offs
;
1448 putpkt ("qOffsets");
1452 if (buf
[0] == '\000')
1453 return; /* Return silently. Stub doesn't support
1457 warning ("Remote failure reply: %s", buf
);
1461 /* Pick up each field in turn. This used to be done with scanf, but
1462 scanf will make trouble if CORE_ADDR size doesn't match
1463 conversion directives correctly. The following code will work
1464 with any size of CORE_ADDR. */
1465 text_addr
= data_addr
= bss_addr
= 0;
1469 if (strncmp (ptr
, "Text=", 5) == 0)
1472 /* Don't use strtol, could lose on big values. */
1473 while (*ptr
&& *ptr
!= ';')
1474 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1479 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1482 while (*ptr
&& *ptr
!= ';')
1483 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1488 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1491 while (*ptr
&& *ptr
!= ';')
1492 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1498 error ("Malformed response to offset query, %s", buf
);
1500 if (symfile_objfile
== NULL
)
1503 offs
= alloca (sizeof (struct section_offsets
)
1504 + symfile_objfile
->num_sections
1505 * sizeof (offs
->offsets
));
1506 memcpy (offs
, symfile_objfile
->section_offsets
,
1507 sizeof (struct section_offsets
)
1508 + symfile_objfile
->num_sections
1509 * sizeof (offs
->offsets
));
1511 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
1513 /* This is a temporary kludge to force data and bss to use the same offsets
1514 because that's what nlmconv does now. The real solution requires changes
1515 to the stub and remote.c that I don't have time to do right now. */
1517 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
1518 ANOFFSET (offs
, SECT_OFF_BSS
) = data_addr
;
1520 objfile_relocate (symfile_objfile
, offs
);
1524 * Cisco version of section offsets:
1526 * Instead of having GDB query the target for the section offsets,
1527 * Cisco lets the target volunteer the information! It's also in
1528 * a different format, so here are the functions that will decode
1529 * a section offset packet from a Cisco target.
1533 * Function: remote_cisco_section_offsets
1535 * Returns: zero for success, non-zero for failure
1539 remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
1540 text_offs
, data_offs
, bss_offs
)
1544 bfd_signed_vma
*text_offs
;
1545 bfd_signed_vma
*data_offs
;
1546 bfd_signed_vma
*bss_offs
;
1548 bfd_vma text_base
, data_base
, bss_base
;
1549 struct minimal_symbol
*start
;
1555 if (symfile_objfile
== NULL
)
1556 return -1; /* no can do nothin' */
1558 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
1560 return -1; /* Can't find "_start" symbol */
1562 data_base
= bss_base
= 0;
1563 text_base
= SYMBOL_VALUE_ADDRESS (start
);
1565 abfd
= symfile_objfile
->obfd
;
1566 for (sect
= abfd
->sections
;
1570 p
= (unsigned char *) bfd_get_section_name (abfd
, sect
);
1572 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
1573 if (data_base
== 0 ||
1574 data_base
> bfd_get_section_vma (abfd
, sect
))
1575 data_base
= bfd_get_section_vma (abfd
, sect
);
1576 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
1577 if (bss_base
== 0 ||
1578 bss_base
> bfd_get_section_vma (abfd
, sect
))
1579 bss_base
= bfd_get_section_vma (abfd
, sect
);
1581 *text_offs
= text_addr
- text_base
;
1582 *data_offs
= data_addr
- data_base
;
1583 *bss_offs
= bss_addr
- bss_base
;
1588 sprintf (tmp
, "VMA: text = 0x");
1589 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
1590 sprintf (tmp
+ strlen (tmp
), " data = 0x");
1591 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
1592 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
1593 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
1594 fprintf_filtered (gdb_stdlog
, tmp
);
1595 fprintf_filtered (gdb_stdlog
,
1596 "Reloc offset: text = 0x%x data = 0x%x bss = 0x%x\n",
1597 (long) *text_offs
, (long) *data_offs
, (long) *bss_offs
);
1604 * Function: remote_cisco_objfile_relocate
1606 * Relocate the symbol file for a remote target.
1610 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
)
1611 bfd_signed_vma text_off
;
1612 bfd_signed_vma data_off
;
1613 bfd_signed_vma bss_off
;
1615 struct section_offsets
*offs
;
1617 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
1619 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1620 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1621 simple canonical representation for this stuff. */
1623 offs
= ((struct section_offsets
*)
1624 alloca (sizeof (struct section_offsets
)
1625 + (symfile_objfile
->num_sections
1626 * sizeof (offs
->offsets
))));
1628 memcpy (offs
, symfile_objfile
->section_offsets
,
1629 (sizeof (struct section_offsets
)
1630 + (symfile_objfile
->num_sections
1631 * sizeof (offs
->offsets
))));
1633 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_off
;
1634 ANOFFSET (offs
, SECT_OFF_DATA
) = data_off
;
1635 ANOFFSET (offs
, SECT_OFF_BSS
) = bss_off
;
1637 /* First call the standard objfile_relocate. */
1638 objfile_relocate (symfile_objfile
, offs
);
1640 /* Now we need to fix up the section entries already attached to
1641 the exec target. These entries will control memory transfers
1642 from the exec file. */
1644 exec_set_section_offsets (text_off
, data_off
, bss_off
);
1648 /* Stub for catch_errors. */
1651 remote_start_remote_dummy (dummy
)
1654 start_remote (); /* Initialize gdb process mechanisms */
1659 remote_start_remote (dummy
)
1662 immediate_quit
= 1; /* Allow user to interrupt it */
1664 /* Ack any packet which the remote side has already sent. */
1665 SERIAL_WRITE (remote_desc
, "+", 1);
1667 /* Let the stub know that we want it to return the thread. */
1670 inferior_pid
= remote_current_thread (inferior_pid
);
1672 get_offsets (); /* Get text, data & bss offsets */
1674 putpkt ("?"); /* initiate a query from remote machine */
1677 return remote_start_remote_dummy (dummy
);
1680 /* Open a connection to a remote debugger.
1681 NAME is the filename used for communication. */
1684 remote_open (name
, from_tty
)
1688 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
1691 /* Just like remote_open, but with asynchronous support. */
1693 remote_async_open (name
, from_tty
)
1697 remote_async_open_1 (name
, from_tty
, &remote_async_ops
, 0);
1700 /* Open a connection to a remote debugger using the extended
1701 remote gdb protocol. NAME is the filename used for communication. */
1704 extended_remote_open (name
, from_tty
)
1708 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */ );
1711 /* Just like extended_remote_open, but with asynchronous support. */
1713 extended_remote_async_open (name
, from_tty
)
1717 remote_async_open_1 (name
, from_tty
, &extended_async_remote_ops
, 1 /*extended_p */ );
1720 /* Generic code for opening a connection to a remote target. */
1722 static DCACHE
*remote_dcache
;
1725 remote_open_1 (name
, from_tty
, target
, extended_p
)
1728 struct target_ops
*target
;
1732 error ("To open a remote debug connection, you need to specify what\n\
1733 serial device is attached to the remote system (e.g. /dev/ttya).");
1735 target_preopen (from_tty
);
1737 unpush_target (target
);
1739 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1741 remote_desc
= SERIAL_OPEN (name
);
1743 perror_with_name (name
);
1745 if (baud_rate
!= -1)
1747 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1749 SERIAL_CLOSE (remote_desc
);
1750 perror_with_name (name
);
1754 SERIAL_RAW (remote_desc
);
1756 /* If there is something sitting in the buffer we might take it as a
1757 response to a command, which would be bad. */
1758 SERIAL_FLUSH_INPUT (remote_desc
);
1762 puts_filtered ("Remote debugging using ");
1763 puts_filtered (name
);
1764 puts_filtered ("\n");
1766 push_target (target
); /* Switch to using remote target now */
1768 init_packet_config (&remote_protocol_P
);
1769 init_packet_config (&remote_protocol_Z
);
1771 general_thread
= -2;
1772 continue_thread
= -2;
1774 /* Force remote_write_bytes to check whether target supports
1775 binary downloading. */
1776 init_packet_config (&remote_protocol_binary_download
);
1778 /* Without this, some commands which require an active target (such
1779 as kill) won't work. This variable serves (at least) double duty
1780 as both the pid of the target process (if it has such), and as a
1781 flag indicating that a target is active. These functions should
1782 be split out into seperate variables, especially since GDB will
1783 someday have a notion of debugging several processes. */
1785 inferior_pid
= MAGIC_NULL_PID
;
1786 /* Start the remote connection; if error (0), discard this target.
1787 In particular, if the user quits, be sure to discard it
1788 (we'd be in an inconsistent state otherwise). */
1789 if (!catch_errors (remote_start_remote
, NULL
,
1790 "Couldn't establish connection to remote target\n",
1799 /* tell the remote that we're using the extended protocol. */
1800 char *buf
= alloca (PBUFSIZ
);
1806 /* Just like remote_open but with asynchronous support. */
1808 remote_async_open_1 (name
, from_tty
, target
, extended_p
)
1811 struct target_ops
*target
;
1815 error ("To open a remote debug connection, you need to specify what\n\
1816 serial device is attached to the remote system (e.g. /dev/ttya).");
1818 target_preopen (from_tty
);
1820 unpush_target (target
);
1822 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1824 remote_desc
= SERIAL_OPEN (name
);
1826 perror_with_name (name
);
1828 if (baud_rate
!= -1)
1830 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1832 SERIAL_CLOSE (remote_desc
);
1833 perror_with_name (name
);
1837 SERIAL_RAW (remote_desc
);
1839 /* If there is something sitting in the buffer we might take it as a
1840 response to a command, which would be bad. */
1841 SERIAL_FLUSH_INPUT (remote_desc
);
1845 puts_filtered ("Remote debugging using ");
1846 puts_filtered (name
);
1847 puts_filtered ("\n");
1850 /* If running in asynchronous mode, register the target with the
1851 event loop. Set things up so that when there is an event on the
1852 file descriptor, the event loop will call fetch_inferior_event,
1853 which will do the proper analysis to determine what happened. */
1855 add_file_handler (remote_desc
->fd
, fetch_inferior_event
, 0);
1857 push_target (target
); /* Switch to using remote target now */
1859 init_packet_config (&remote_protocol_P
);
1860 init_packet_config (&remote_protocol_Z
);
1862 general_thread
= -2;
1863 continue_thread
= -2;
1865 /* Force remote_write_bytes to check whether target supports
1866 binary downloading. */
1867 init_packet_config (&remote_protocol_binary_download
);
1869 /* If running asynchronously, set things up for telling the target
1870 to use the extended protocol. This will happen only after the
1871 target has been connected to, in fetch_inferior_event. */
1872 if (extended_p
&& async_p
)
1873 add_continuation (set_extended_protocol
, NULL
);
1875 /* Without this, some commands which require an active target (such
1876 as kill) won't work. This variable serves (at least) double duty
1877 as both the pid of the target process (if it has such), and as a
1878 flag indicating that a target is active. These functions should
1879 be split out into seperate variables, especially since GDB will
1880 someday have a notion of debugging several processes. */
1882 inferior_pid
= MAGIC_NULL_PID
;
1883 /* Start the remote connection; if error (0), discard this target.
1884 In particular, if the user quits, be sure to discard it
1885 (we'd be in an inconsistent state otherwise). */
1886 if (!catch_errors (remote_start_remote
, NULL
,
1887 "Couldn't establish connection to remote target\n",
1890 /* Unregister the file descriptor from the event loop. */
1892 delete_file_handler (remote_desc
->fd
);
1901 /* tell the remote that we're using the extended protocol. */
1902 char *buf
= alloca (PBUFSIZ
);
1909 /* This will be called by fetch_inferior_event, via the
1910 cmd_continuation pointer, only after the target has stopped. */
1912 set_extended_protocol (arg
)
1913 struct continuation_arg
*arg
;
1915 /* tell the remote that we're using the extended protocol. */
1916 char *buf
= alloca (PBUFSIZ
);
1921 /* This takes a program previously attached to and detaches it. After
1922 this is done, GDB can be used to debug some other program. We
1923 better not have left any breakpoints in the target program or it'll
1924 die when it hits one. */
1927 remote_detach (args
, from_tty
)
1931 char *buf
= alloca (PBUFSIZ
);
1934 error ("Argument given to \"detach\" when remotely debugging.");
1936 /* Tell the remote target to detach. */
1942 puts_filtered ("Ending remote debugging.\n");
1946 /* Same as remote_detach, but with async support. */
1948 remote_async_detach (args
, from_tty
)
1952 char *buf
= alloca (PBUFSIZ
);
1955 error ("Argument given to \"detach\" when remotely debugging.");
1957 /* Tell the remote target to detach. */
1961 /* Unregister the file descriptor from the event loop. */
1963 delete_file_handler (remote_desc
->fd
);
1967 puts_filtered ("Ending remote debugging.\n");
1970 /* Convert hex digit A to a number. */
1976 if (a
>= '0' && a
<= '9')
1978 else if (a
>= 'a' && a
<= 'f')
1979 return a
- 'a' + 10;
1980 else if (a
>= 'A' && a
<= 'F')
1981 return a
- 'A' + 10;
1983 error ("Reply contains invalid hex digit %d", a
);
1986 /* Convert number NIB to a hex digit. */
1995 return 'a' + nib
- 10;
1998 /* Tell the remote machine to resume. */
2000 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2002 static int last_sent_step
;
2005 remote_resume (pid
, step
, siggnal
)
2007 enum target_signal siggnal
;
2009 char *buf
= alloca (PBUFSIZ
);
2012 set_thread (0, 0); /* run any thread */
2014 set_thread (pid
, 0); /* run this thread */
2016 dcache_flush (remote_dcache
);
2018 last_sent_signal
= siggnal
;
2019 last_sent_step
= step
;
2021 /* A hook for when we need to do something at the last moment before
2023 if (target_resume_hook
)
2024 (*target_resume_hook
) ();
2026 if (siggnal
!= TARGET_SIGNAL_0
)
2028 buf
[0] = step
? 'S' : 'C';
2029 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2030 buf
[2] = tohex ((int) siggnal
& 0xf);
2034 strcpy (buf
, step
? "s" : "c");
2039 /* Same as remote_resume, but with async support. */
2041 remote_async_resume (pid
, step
, siggnal
)
2043 enum target_signal siggnal
;
2045 char *buf
= alloca (PBUFSIZ
);
2048 set_thread (0, 0); /* run any thread */
2050 set_thread (pid
, 0); /* run this thread */
2052 dcache_flush (remote_dcache
);
2054 last_sent_signal
= siggnal
;
2055 last_sent_step
= step
;
2057 /* A hook for when we need to do something at the last moment before
2059 if (target_resume_hook
)
2060 (*target_resume_hook
) ();
2062 /* Set things up before execution starts for async commands. */
2063 /* This function can be entered more than once for the same execution
2064 command, because it is also called by handle_inferior_event. So
2065 we make sure that we don't do the initialization for sync
2066 execution more than once. */
2067 if (async_p
&& !target_executing
)
2069 target_executing
= 1;
2071 /* If the command must look synchronous, fake it, by making gdb
2072 display an empty prompt after the command has completed. Also
2076 push_prompt ("", "", "");
2077 delete_file_handler (input_fd
);
2078 initialize_sigint_signal_handler ();
2082 if (siggnal
!= TARGET_SIGNAL_0
)
2084 buf
[0] = step
? 'S' : 'C';
2085 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2086 buf
[2] = tohex ((int) siggnal
& 0xf);
2090 strcpy (buf
, step
? "s" : "c");
2096 /* Set up the signal handler for SIGINT, while the target is
2097 executing, ovewriting the 'regular' SIGINT signal handler. */
2099 initialize_sigint_signal_handler ()
2101 sigint_remote_token
=
2102 create_async_signal_handler (async_remote_interrupt
, NULL
);
2103 signal (SIGINT
, handle_remote_sigint
);
2106 /* Signal handler for SIGINT, while the target is executing. */
2108 handle_remote_sigint (sig
)
2111 signal (sig
, handle_remote_sigint_twice
);
2112 sigint_remote_twice_token
=
2113 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2114 mark_async_signal_handler_wrapper (sigint_remote_token
);
2117 /* Signal handler for SIGINT, installed after SIGINT has already been
2118 sent once. It will take effect the second time that the user sends
2121 handle_remote_sigint_twice (sig
)
2124 signal (sig
, handle_sigint
);
2125 sigint_remote_twice_token
=
2126 create_async_signal_handler (async_remote_interrupt
, NULL
);
2127 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2130 /* Perform the real interruption of hte target execution, in response
2133 async_remote_interrupt (arg
)
2134 gdb_client_data arg
;
2137 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2142 /* Perform interrupt, if the first attempt did not succeed. Just give
2143 up on the target alltogether. */
2145 async_remote_interrupt_twice (arg
)
2146 gdb_client_data arg
;
2149 signal (SIGINT
, handle_remote_sigint
);
2152 /* Reinstall the usual SIGINT handlers, after the target has
2155 cleanup_sigint_signal_handler ()
2157 signal (SIGINT
, handle_sigint
);
2158 if (sigint_remote_twice_token
)
2159 delete_async_signal_handler ((async_signal_handler
**) & sigint_remote_twice_token
);
2160 if (sigint_remote_token
)
2161 delete_async_signal_handler ((async_signal_handler
**) & sigint_remote_token
);
2164 /* Send ^C to target to halt it. Target will respond, and send us a
2166 static void (*ofunc
) PARAMS ((int));
2168 /* The command line interface's stop routine. This function is installed
2169 as a signal handler for SIGINT. The first time a user requests a
2170 stop, we call remote_stop to send a break or ^C. If there is no
2171 response from the target (it didn't stop when the user requested it),
2172 we ask the user if he'd like to detach from the target. */
2174 remote_interrupt (signo
)
2177 /* If this doesn't work, try more severe steps. */
2178 signal (signo
, remote_interrupt_twice
);
2181 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2186 /* The user typed ^C twice. */
2189 remote_interrupt_twice (signo
)
2192 signal (signo
, ofunc
);
2194 signal (signo
, remote_interrupt
);
2197 /* This is the generic stop called via the target vector. When a target
2198 interrupt is requested, either by the command line or the GUI, we
2199 will eventually end up here. */
2203 /* Send a break or a ^C, depending on user preference. */
2205 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2208 SERIAL_SEND_BREAK (remote_desc
);
2210 SERIAL_WRITE (remote_desc
, "\003", 1);
2213 /* Ask the user what to do when an interrupt is received. */
2218 target_terminal_ours ();
2220 if (query ("Interrupted while waiting for the program.\n\
2221 Give up (and stop debugging it)? "))
2223 target_mourn_inferior ();
2224 return_to_top_level (RETURN_QUIT
);
2227 target_terminal_inferior ();
2230 /* If nonzero, ignore the next kill. */
2235 remote_console_output (msg
)
2240 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2243 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2246 fputs_unfiltered (tb
, gdb_stdtarg
);
2250 /* Wait until the remote machine stops, then return,
2251 storing status in STATUS just as `wait' would.
2252 Returns "pid", which in the case of a multi-threaded
2253 remote OS, is the thread-id. */
2256 remote_wait (pid
, status
)
2258 struct target_waitstatus
*status
;
2260 unsigned char *buf
= alloca (PBUFSIZ
);
2261 int thread_num
= -1;
2263 status
->kind
= TARGET_WAITKIND_EXITED
;
2264 status
->value
.integer
= 0;
2270 ofunc
= signal (SIGINT
, remote_interrupt
);
2271 getpkt ((char *) buf
, 1);
2272 signal (SIGINT
, ofunc
);
2274 /* This is a hook for when we need to do something (perhaps the
2275 collection of trace data) every time the target stops. */
2276 if (target_wait_loop_hook
)
2277 (*target_wait_loop_hook
) ();
2281 case 'E': /* Error of some sort */
2282 warning ("Remote failure reply: %s", buf
);
2284 case 'T': /* Status with PC, SP, FP, ... */
2288 char regs
[MAX_REGISTER_RAW_SIZE
];
2290 /* Expedited reply, containing Signal, {regno, reg} repeat */
2291 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2293 n... = register number
2294 r... = register contents
2296 p
= &buf
[3]; /* after Txx */
2303 /* Read the register number */
2304 regno
= strtol ((const char *) p
, &p_temp
, 16);
2305 p1
= (unsigned char *) p_temp
;
2307 if (p1
== p
) /* No register number present here */
2309 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2311 warning ("Malformed packet(a) (missing colon): %s\n\
2314 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2316 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2317 record_currthread (thread_num
);
2318 p
= (unsigned char *) p_temp
;
2326 warning ("Malformed packet(b) (missing colon): %s\n\
2330 if (regno
>= NUM_REGS
)
2331 warning ("Remote sent bad register number %ld: %s\n\
2335 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2337 if (p
[0] == 0 || p
[1] == 0)
2338 warning ("Remote reply is too short: %s", buf
);
2339 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2342 supply_register (regno
, regs
);
2347 warning ("Remote register badly formatted: %s", buf
);
2348 warning (" here: %s", p
);
2353 case 'S': /* Old style status, just signal only */
2354 status
->kind
= TARGET_WAITKIND_STOPPED
;
2355 status
->value
.sig
= (enum target_signal
)
2356 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2360 /* Export Cisco kernel mode as a convenience variable
2361 (so that it can be used in the GDB prompt if desired). */
2363 if (cisco_kernel_mode
== 1)
2364 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2365 value_from_string ("PDEBUG-"));
2366 cisco_kernel_mode
= 0;
2367 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2368 record_currthread (thread_num
);
2370 else if (buf
[3] == 'k')
2372 /* Export Cisco kernel mode as a convenience variable
2373 (so that it can be used in the GDB prompt if desired). */
2375 if (cisco_kernel_mode
== 1)
2376 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2377 value_from_string ("KDEBUG-"));
2378 cisco_kernel_mode
= 1;
2381 case 'N': /* Cisco special: status and offsets */
2383 bfd_vma text_addr
, data_addr
, bss_addr
;
2384 bfd_signed_vma text_off
, data_off
, bss_off
;
2387 status
->kind
= TARGET_WAITKIND_STOPPED
;
2388 status
->value
.sig
= (enum target_signal
)
2389 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2391 if (symfile_objfile
== NULL
)
2393 warning ("Relocation packet recieved with no symbol file. \
2398 /* Relocate object file. Buffer format is NAATT;DD;BB
2399 * where AA is the signal number, TT is the new text
2400 * address, DD * is the new data address, and BB is the
2401 * new bss address. */
2404 text_addr
= strtoul (p
, (char **) &p1
, 16);
2405 if (p1
== p
|| *p1
!= ';')
2406 warning ("Malformed relocation packet: Packet '%s'", buf
);
2408 data_addr
= strtoul (p
, (char **) &p1
, 16);
2409 if (p1
== p
|| *p1
!= ';')
2410 warning ("Malformed relocation packet: Packet '%s'", buf
);
2412 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2414 warning ("Malformed relocation packet: Packet '%s'", buf
);
2416 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2417 &text_off
, &data_off
, &bss_off
)
2419 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2420 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2424 case 'W': /* Target exited */
2426 /* The remote process exited. */
2427 status
->kind
= TARGET_WAITKIND_EXITED
;
2428 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2432 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2433 status
->value
.sig
= (enum target_signal
)
2434 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2438 case 'O': /* Console output */
2439 remote_console_output (buf
+ 1);
2442 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2444 /* Zero length reply means that we tried 'S' or 'C' and
2445 the remote system doesn't support it. */
2446 target_terminal_ours_for_output ();
2448 ("Can't send signals to this remote system. %s not sent.\n",
2449 target_signal_to_name (last_sent_signal
));
2450 last_sent_signal
= TARGET_SIGNAL_0
;
2451 target_terminal_inferior ();
2453 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2454 putpkt ((char *) buf
);
2457 /* else fallthrough */
2459 warning ("Invalid remote reply: %s", buf
);
2464 if (thread_num
!= -1)
2468 return inferior_pid
;
2471 /* Async version of remote_wait. */
2473 remote_async_wait (pid
, status
)
2475 struct target_waitstatus
*status
;
2477 unsigned char *buf
= alloca (PBUFSIZ
);
2478 int thread_num
= -1;
2480 status
->kind
= TARGET_WAITKIND_EXITED
;
2481 status
->value
.integer
= 0;
2488 ofunc
= signal (SIGINT
, remote_interrupt
);
2489 getpkt ((char *) buf
, 1);
2491 signal (SIGINT
, ofunc
);
2493 /* This is a hook for when we need to do something (perhaps the
2494 collection of trace data) every time the target stops. */
2495 if (target_wait_loop_hook
)
2496 (*target_wait_loop_hook
) ();
2500 case 'E': /* Error of some sort */
2501 warning ("Remote failure reply: %s", buf
);
2503 case 'T': /* Status with PC, SP, FP, ... */
2507 char regs
[MAX_REGISTER_RAW_SIZE
];
2509 /* Expedited reply, containing Signal, {regno, reg} repeat */
2510 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2512 n... = register number
2513 r... = register contents
2515 p
= &buf
[3]; /* after Txx */
2522 /* Read the register number */
2523 regno
= strtol ((const char *) p
, &p_temp
, 16);
2524 p1
= (unsigned char *) p_temp
;
2526 if (p1
== p
) /* No register number present here */
2528 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2530 warning ("Malformed packet(a) (missing colon): %s\n\
2533 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2535 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2536 record_currthread (thread_num
);
2537 p
= (unsigned char *) p_temp
;
2545 warning ("Malformed packet(b) (missing colon): %s\n\
2549 if (regno
>= NUM_REGS
)
2550 warning ("Remote sent bad register number %ld: %s\n\
2554 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2556 if (p
[0] == 0 || p
[1] == 0)
2557 warning ("Remote reply is too short: %s", buf
);
2558 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2561 supply_register (regno
, regs
);
2566 warning ("Remote register badly formatted: %s", buf
);
2567 warning (" here: %s", p
);
2572 case 'S': /* Old style status, just signal only */
2573 status
->kind
= TARGET_WAITKIND_STOPPED
;
2574 status
->value
.sig
= (enum target_signal
)
2575 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2579 /* Export Cisco kernel mode as a convenience variable
2580 (so that it can be used in the GDB prompt if desired). */
2582 if (cisco_kernel_mode
== 1)
2583 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2584 value_from_string ("PDEBUG-"));
2585 cisco_kernel_mode
= 0;
2586 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2587 record_currthread (thread_num
);
2589 else if (buf
[3] == 'k')
2591 /* Export Cisco kernel mode as a convenience variable
2592 (so that it can be used in the GDB prompt if desired). */
2594 if (cisco_kernel_mode
== 1)
2595 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2596 value_from_string ("KDEBUG-"));
2597 cisco_kernel_mode
= 1;
2600 case 'N': /* Cisco special: status and offsets */
2602 bfd_vma text_addr
, data_addr
, bss_addr
;
2603 bfd_signed_vma text_off
, data_off
, bss_off
;
2606 status
->kind
= TARGET_WAITKIND_STOPPED
;
2607 status
->value
.sig
= (enum target_signal
)
2608 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2610 if (symfile_objfile
== NULL
)
2612 warning ("Relocation packet recieved with no symbol file. \
2617 /* Relocate object file. Buffer format is NAATT;DD;BB
2618 * where AA is the signal number, TT is the new text
2619 * address, DD * is the new data address, and BB is the
2620 * new bss address. */
2623 text_addr
= strtoul (p
, (char **) &p1
, 16);
2624 if (p1
== p
|| *p1
!= ';')
2625 warning ("Malformed relocation packet: Packet '%s'", buf
);
2627 data_addr
= strtoul (p
, (char **) &p1
, 16);
2628 if (p1
== p
|| *p1
!= ';')
2629 warning ("Malformed relocation packet: Packet '%s'", buf
);
2631 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2633 warning ("Malformed relocation packet: Packet '%s'", buf
);
2635 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2636 &text_off
, &data_off
, &bss_off
)
2638 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2639 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2643 case 'W': /* Target exited */
2645 /* The remote process exited. */
2646 status
->kind
= TARGET_WAITKIND_EXITED
;
2647 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2651 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2652 status
->value
.sig
= (enum target_signal
)
2653 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2657 case 'O': /* Console output */
2658 remote_console_output (buf
+ 1);
2661 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2663 /* Zero length reply means that we tried 'S' or 'C' and
2664 the remote system doesn't support it. */
2665 target_terminal_ours_for_output ();
2667 ("Can't send signals to this remote system. %s not sent.\n",
2668 target_signal_to_name (last_sent_signal
));
2669 last_sent_signal
= TARGET_SIGNAL_0
;
2670 target_terminal_inferior ();
2672 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2673 putpkt ((char *) buf
);
2676 /* else fallthrough */
2678 warning ("Invalid remote reply: %s", buf
);
2683 if (thread_num
!= -1)
2687 return inferior_pid
;
2690 /* Number of bytes of registers this stub implements. */
2692 static int register_bytes_found
;
2694 /* Read the remote registers into the block REGS. */
2695 /* Currently we just read all the registers, so we don't use regno. */
2699 remote_fetch_registers (regno
)
2702 char *buf
= alloca (PBUFSIZ
);
2705 char regs
[REGISTER_BYTES
];
2707 set_thread (inferior_pid
, 1);
2712 if (remote_register_buf_size
== 0)
2713 remote_register_buf_size
= strlen (buf
);
2715 /* Unimplemented registers read as all bits zero. */
2716 memset (regs
, 0, REGISTER_BYTES
);
2718 /* We can get out of synch in various cases. If the first character
2719 in the buffer is not a hex character, assume that has happened
2720 and try to fetch another packet to read. */
2721 while ((buf
[0] < '0' || buf
[0] > '9')
2722 && (buf
[0] < 'a' || buf
[0] > 'f')
2723 && buf
[0] != 'x') /* New: unavailable register value */
2726 fprintf_unfiltered (gdb_stdlog
,
2727 "Bad register packet; fetching a new packet\n");
2731 /* Reply describes registers byte by byte, each byte encoded as two
2732 hex characters. Suck them all up, then supply them to the
2733 register cacheing/storage mechanism. */
2736 for (i
= 0; i
< REGISTER_BYTES
; i
++)
2742 warning ("Remote reply is of odd length: %s", buf
);
2743 /* Don't change register_bytes_found in this case, and don't
2744 print a second warning. */
2747 if (p
[0] == 'x' && p
[1] == 'x')
2748 regs
[i
] = 0; /* 'x' */
2750 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2754 if (i
!= register_bytes_found
)
2756 register_bytes_found
= i
;
2757 #ifdef REGISTER_BYTES_OK
2758 if (!REGISTER_BYTES_OK (i
))
2759 warning ("Remote reply is too short: %s", buf
);
2764 for (i
= 0; i
< NUM_REGS
; i
++)
2766 supply_register (i
, ®s
[REGISTER_BYTE (i
)]);
2767 if (buf
[REGISTER_BYTE (i
) * 2] == 'x')
2768 register_valid
[i
] = -1; /* register value not available */
2772 /* Prepare to store registers. Since we may send them all (using a
2773 'G' request), we have to read out the ones we don't want to change
2777 remote_prepare_to_store ()
2779 /* Make sure the entire registers array is valid. */
2780 switch (remote_protocol_P
.support
)
2782 case PACKET_DISABLE
:
2783 case PACKET_SUPPORT_UNKNOWN
:
2784 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
);
2791 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
2792 packet was not recognized. */
2795 store_register_using_P (regno
)
2798 /* Try storing a single register. */
2799 char *buf
= alloca (PBUFSIZ
);
2804 sprintf (buf
, "P%x=", regno
);
2805 p
= buf
+ strlen (buf
);
2806 regp
= ®isters
[REGISTER_BYTE (regno
)];
2807 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
2809 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
2810 *p
++ = tohex (regp
[i
] & 0xf);
2815 return buf
[0] != '\0';
2819 /* Store register REGNO, or all registers if REGNO == -1, from the contents
2820 of REGISTERS. FIXME: ignores errors. */
2823 remote_store_registers (regno
)
2826 char *buf
= alloca (PBUFSIZ
);
2830 set_thread (inferior_pid
, 1);
2834 switch (remote_protocol_P
.support
)
2836 case PACKET_DISABLE
:
2839 if (store_register_using_P (regno
))
2842 error ("Protocol error: P packet not recognized by stub");
2843 case PACKET_SUPPORT_UNKNOWN
:
2844 if (store_register_using_P (regno
))
2846 /* The stub recognized the 'P' packet. Remember this. */
2847 remote_protocol_P
.support
= PACKET_ENABLE
;
2852 /* The stub does not support the 'P' packet. Use 'G'
2853 instead, and don't try using 'P' in the future (it
2854 will just waste our time). */
2855 remote_protocol_P
.support
= PACKET_DISABLE
;
2863 /* Command describes registers byte by byte,
2864 each byte encoded as two hex characters. */
2867 /* remote_prepare_to_store insures that register_bytes_found gets set. */
2868 for (i
= 0; i
< register_bytes_found
; i
++)
2870 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
2871 *p
++ = tohex (registers
[i
] & 0xf);
2878 /* Use of the data cache *used* to be disabled because it loses for looking
2879 at and changing hardware I/O ports and the like. Accepting `volatile'
2880 would perhaps be one way to fix it. Another idea would be to use the
2881 executable file for the text segment (for all SEC_CODE sections?
2882 For all SEC_READONLY sections?). This has problems if you want to
2883 actually see what the memory contains (e.g. self-modifying code,
2884 clobbered memory, user downloaded the wrong thing).
2886 Because it speeds so much up, it's now enabled, if you're playing
2887 with registers you turn it of (set remotecache 0). */
2889 /* Read a word from remote address ADDR and return it.
2890 This goes through the data cache. */
2894 remote_fetch_word (addr
)
2897 return dcache_fetch (remote_dcache
, addr
);
2900 /* Write a word WORD into remote address ADDR.
2901 This goes through the data cache. */
2904 remote_store_word (addr
, word
)
2908 dcache_poke (remote_dcache
, addr
, word
);
2910 #endif /* 0 (unused?) */
2914 /* Return the number of hex digits in num. */
2922 for (i
= 0; num
!= 0; i
++)
2928 /* Set BUF to the hex digits representing NUM. */
2931 hexnumstr (buf
, num
)
2936 int len
= hexnumlen (num
);
2940 for (i
= len
- 1; i
>= 0; i
--)
2942 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
2949 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
2952 remote_address_masked (addr
)
2955 if (remote_address_size
> 0
2956 && remote_address_size
< (sizeof (ULONGEST
) * 8))
2958 /* Only create a mask when that mask can safely be constructed
2959 in a ULONGEST variable. */
2961 mask
= (mask
<< remote_address_size
) - 1;
2967 /* Determine whether the remote target supports binary downloading.
2968 This is accomplished by sending a no-op memory write of zero length
2969 to the target at the specified address. It does not suffice to send
2970 the whole packet, since many stubs strip the eighth bit and subsequently
2971 compute a wrong checksum, which causes real havoc with remote_write_bytes.
2973 NOTE: This can still lose if the serial line is not eight-bit
2974 clean. In cases like this, the user should clear "remote
2978 check_binary_download (addr
)
2981 switch (remote_protocol_binary_download
.support
)
2983 case PACKET_DISABLE
:
2987 case PACKET_SUPPORT_UNKNOWN
:
2989 char *buf
= alloca (PBUFSIZ
);
2994 p
+= hexnumstr (p
, (ULONGEST
) addr
);
2996 p
+= hexnumstr (p
, (ULONGEST
) 0);
3000 putpkt_binary (buf
, (int) (p
- buf
));
3006 fprintf_unfiltered (gdb_stdlog
,
3007 "binary downloading NOT suppported by target\n");
3008 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3013 fprintf_unfiltered (gdb_stdlog
,
3014 "binary downloading suppported by target\n");
3015 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3022 /* Write memory data directly to the remote machine.
3023 This does not inform the data cache; the data cache uses this.
3024 MEMADDR is the address in the remote memory space.
3025 MYADDR is the address of the buffer in our space.
3026 LEN is the number of bytes.
3028 Returns number of bytes transferred, or 0 for error. */
3031 remote_write_bytes (memaddr
, myaddr
, len
)
3036 unsigned char *buf
= alloca (PBUFSIZ
);
3037 int max_buf_size
; /* Max size of packet output buffer */
3040 /* Verify that the target can support a binary download */
3041 check_binary_download (memaddr
);
3043 /* Chop the transfer down if necessary */
3045 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
3046 if (remote_register_buf_size
!= 0)
3047 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
3049 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3050 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3055 unsigned char *p
, *plen
;
3059 /* construct "M"<memaddr>","<len>":" */
3060 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3061 memaddr
= remote_address_masked (memaddr
);
3063 switch (remote_protocol_binary_download
.support
)
3067 todo
= min (len
, max_buf_size
);
3069 case PACKET_DISABLE
:
3071 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3073 case PACKET_SUPPORT_UNKNOWN
:
3074 internal_error ("remote_write_bytes: bad switch");
3077 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3080 plen
= p
; /* remember where len field goes */
3081 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3085 /* We send target system values byte by byte, in increasing byte
3086 addresses, each byte encoded as two hex characters (or one
3087 binary character). */
3088 switch (remote_protocol_binary_download
.support
)
3094 (i
< todo
) && (i
+ escaped
) < (max_buf_size
- 2);
3097 switch (myaddr
[i
] & 0xff)
3102 /* These must be escaped */
3105 *p
++ = (myaddr
[i
] & 0xff) ^ 0x20;
3108 *p
++ = myaddr
[i
] & 0xff;
3115 /* Escape chars have filled up the buffer prematurely,
3116 and we have actually sent fewer bytes than planned.
3117 Fix-up the length field of the packet. */
3119 /* FIXME: will fail if new len is a shorter string than
3122 plen
+= hexnumstr (plen
, (ULONGEST
) i
);
3127 case PACKET_DISABLE
:
3129 for (i
= 0; i
< todo
; i
++)
3131 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
3132 *p
++ = tohex (myaddr
[i
] & 0xf);
3137 case PACKET_SUPPORT_UNKNOWN
:
3138 internal_error ("remote_write_bytes: bad switch");
3141 putpkt_binary (buf
, (int) (p
- buf
));
3146 /* There is no correspondance between what the remote protocol uses
3147 for errors and errno codes. We would like a cleaner way of
3148 representing errors (big enough to include errno codes, bfd_error
3149 codes, and others). But for now just return EIO. */
3154 /* Increment by i, not by todo, in case escape chars
3155 caused us to send fewer bytes than we'd planned. */
3163 /* Read memory data directly from the remote machine.
3164 This does not use the data cache; the data cache uses this.
3165 MEMADDR is the address in the remote memory space.
3166 MYADDR is the address of the buffer in our space.
3167 LEN is the number of bytes.
3169 Returns number of bytes transferred, or 0 for error. */
3172 remote_read_bytes (memaddr
, myaddr
, len
)
3177 char *buf
= alloca (PBUFSIZ
);
3178 int max_buf_size
; /* Max size of packet output buffer */
3181 /* Chop the transfer down if necessary */
3183 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
3184 if (remote_register_buf_size
!= 0)
3185 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
3194 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3196 /* construct "m"<memaddr>","<len>" */
3197 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3198 memaddr
= remote_address_masked (memaddr
);
3201 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3203 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3211 /* There is no correspondance between what the remote protocol uses
3212 for errors and errno codes. We would like a cleaner way of
3213 representing errors (big enough to include errno codes, bfd_error
3214 codes, and others). But for now just return EIO. */
3219 /* Reply describes memory byte by byte,
3220 each byte encoded as two hex characters. */
3223 for (i
= 0; i
< todo
; i
++)
3225 if (p
[0] == 0 || p
[1] == 0)
3226 /* Reply is short. This means that we were able to read
3227 only part of what we wanted to. */
3228 return i
+ (origlen
- len
);
3229 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3239 /* Read or write LEN bytes from inferior memory at MEMADDR,
3240 transferring to or from debugger address BUFFER. Write to inferior if
3241 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3244 #ifndef REMOTE_TRANSLATE_XFER_ADDRESS
3245 #define REMOTE_TRANSLATE_XFER_ADDRESS(MEM_ADDR, MEM_LEN, TARG_ADDR, TARG_LEN) \
3246 (*(TARG_ADDR) = (MEM_ADDR), *(TARG_LEN) = (MEM_LEN))
3251 remote_xfer_memory (mem_addr
, buffer
, mem_len
, should_write
, target
)
3256 struct target_ops
*target
; /* ignored */
3258 CORE_ADDR targ_addr
;
3260 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3264 return dcache_xfer_memory (remote_dcache
, targ_addr
, buffer
,
3265 targ_len
, should_write
);
3270 /* Enable after 4.12. */
3273 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
3274 addr_found
, data_found
)
3278 CORE_ADDR startaddr
;
3282 CORE_ADDR
*addr_found
;
3285 if (increment
== -4 && len
== 4)
3287 long mask_long
, data_long
;
3288 long data_found_long
;
3289 CORE_ADDR addr_we_found
;
3290 char *buf
= alloca (PBUFSIZ
);
3291 long returned_long
[2];
3294 mask_long
= extract_unsigned_integer (mask
, len
);
3295 data_long
= extract_unsigned_integer (data
, len
);
3296 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
3301 /* The stub doesn't support the 't' request. We might want to
3302 remember this fact, but on the other hand the stub could be
3303 switched on us. Maybe we should remember it only until
3304 the next "target remote". */
3305 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3306 hirange
, addr_found
, data_found
);
3311 /* There is no correspondance between what the remote protocol uses
3312 for errors and errno codes. We would like a cleaner way of
3313 representing errors (big enough to include errno codes, bfd_error
3314 codes, and others). But for now just use EIO. */
3315 memory_error (EIO
, startaddr
);
3318 while (*p
!= '\0' && *p
!= ',')
3319 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
3321 error ("Protocol error: short return for search");
3323 data_found_long
= 0;
3324 while (*p
!= '\0' && *p
!= ',')
3325 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
3326 /* Ignore anything after this comma, for future extensions. */
3328 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
3334 *addr_found
= addr_we_found
;
3335 *data_found
= store_unsigned_integer (data_we_found
, len
);
3338 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3339 hirange
, addr_found
, data_found
);
3344 remote_files_info (ignore
)
3345 struct target_ops
*ignore
;
3347 puts_filtered ("Debugging a target over a serial line.\n");
3350 /* Stuff for dealing with the packets which are part of this protocol.
3351 See comment at top of file for details. */
3353 /* Read a single character from the remote end, masking it down to 7 bits. */
3361 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
3366 error ("Remote connection closed");
3368 perror_with_name ("Remote communication error");
3369 case SERIAL_TIMEOUT
:
3376 /* Send the command in BUF to the remote machine, and read the reply
3377 into BUF. Report an error if we get an error reply. */
3387 error ("Remote failure reply: %s", buf
);
3390 /* Display a null-terminated packet on stdout, for debugging, using C
3397 puts_filtered ("\"");
3398 fputstr_filtered (buf
, '"', gdb_stdout
);
3399 puts_filtered ("\"");
3406 return putpkt_binary (buf
, strlen (buf
));
3409 /* Send a packet to the remote machine, with error checking. The data
3410 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3411 to account for the $, # and checksum, and for a possible /0 if we are
3412 debugging (remote_debug) and want to print the sent packet as a string */
3415 putpkt_binary (buf
, cnt
)
3420 unsigned char csum
= 0;
3421 char *buf2
= alloca (PBUFSIZ
);
3422 char *junkbuf
= alloca (PBUFSIZ
);
3428 /* Copy the packet into buffer BUF2, encapsulating it
3429 and giving it a checksum. */
3431 if (cnt
> BUFSIZ
- 5) /* Prosanity check */
3437 for (i
= 0; i
< cnt
; i
++)
3443 *p
++ = tohex ((csum
>> 4) & 0xf);
3444 *p
++ = tohex (csum
& 0xf);
3446 /* Send it over and over until we get a positive ack. */
3450 int started_error_output
= 0;
3455 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
3456 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
3457 fprintf_unfiltered (gdb_stdlog
, "...", buf2
);
3458 gdb_flush (gdb_stdlog
);
3460 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
3461 perror_with_name ("putpkt: write failed");
3463 /* read until either a timeout occurs (-2) or '+' is read */
3466 ch
= readchar (remote_timeout
);
3473 case SERIAL_TIMEOUT
:
3475 if (started_error_output
)
3477 putchar_unfiltered ('\n');
3478 started_error_output
= 0;
3487 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
3489 case SERIAL_TIMEOUT
:
3493 break; /* Retransmit buffer */
3496 /* It's probably an old response, and we're out of sync.
3497 Just gobble up the packet and ignore it. */
3498 getpkt (junkbuf
, 0);
3499 continue; /* Now, go look for + */
3504 if (!started_error_output
)
3506 started_error_output
= 1;
3507 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
3509 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
3513 break; /* Here to retransmit */
3517 /* This is wrong. If doing a long backtrace, the user should be
3518 able to get out next time we call QUIT, without anything as
3519 violent as interrupt_query. If we want to provide a way out of
3520 here without getting to the next QUIT, it should be based on
3521 hitting ^C twice as in remote_wait. */
3531 static int remote_cisco_mode
;
3534 remote_cisco_expand (src
, dest
)
3545 repeat
= (fromhex (src
[1]) << 4) + fromhex (src
[2]);
3546 for (i
= 0; i
< repeat
; i
++)
3548 *dest
++ = *(src
- 1);
3560 /* Come here after finding the start of the frame. Collect the rest
3561 into BUF, verifying the checksum, length, and handling run-length
3562 compression. Returns 0 on any error, 1 on success. */
3577 c
= readchar (remote_timeout
);
3581 case SERIAL_TIMEOUT
:
3583 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
3587 fputs_filtered ("Saw new packet start in middle of old one\n",
3589 return 0; /* Start a new packet, count retries */
3592 unsigned char pktcsum
;
3596 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
3597 pktcsum
|= fromhex (readchar (remote_timeout
));
3599 if (csum
== pktcsum
)
3601 if (remote_cisco_mode
) /* variant run-length-encoding */
3603 char *tmp_buf
= alloca (PBUFSIZ
);
3605 remote_cisco_expand (buf
, tmp_buf
);
3606 strcpy (buf
, tmp_buf
);
3613 fprintf_filtered (gdb_stdlog
,
3614 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3616 fputs_filtered (buf
, gdb_stdlog
);
3617 fputs_filtered ("\n", gdb_stdlog
);
3621 case '*': /* Run length encoding */
3622 if (remote_cisco_mode
== 0) /* variant run-length-encoding */
3625 c
= readchar (remote_timeout
);
3627 c
= c
- ' ' + 3; /* Compute repeat count */
3629 if (c
> 0 && c
< 255 && bp
+ c
- 1 < buf
+ PBUFSIZ
- 1)
3631 memset (bp
, *(bp
- 1), c
);
3637 printf_filtered ("Repeat count %d too large for buffer: ", c
);
3638 puts_filtered (buf
);
3639 puts_filtered ("\n");
3642 /* else fall thru to treat like default */
3644 if (bp
< buf
+ PBUFSIZ
- 1)
3652 puts_filtered ("Remote packet too long: ");
3653 puts_filtered (buf
);
3654 puts_filtered ("\n");
3661 /* Read a packet from the remote machine, with error checking, and
3662 store it in BUF. BUF is expected to be of size PBUFSIZ. If
3663 FOREVER, wait forever rather than timing out; this is used while
3664 the target is executing user code. */
3667 getpkt (buf
, forever
)
3676 strcpy (buf
, "timeout");
3680 timeout
= watchdog
> 0 ? watchdog
: -1;
3684 timeout
= remote_timeout
;
3688 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
3690 /* This can loop forever if the remote side sends us characters
3691 continuously, but if it pauses, we'll get a zero from readchar
3692 because of timeout. Then we'll count that as a retry. */
3694 /* Note that we will only wait forever prior to the start of a packet.
3695 After that, we expect characters to arrive at a brisk pace. They
3696 should show up within remote_timeout intervals. */
3700 c
= readchar (timeout
);
3702 if (c
== SERIAL_TIMEOUT
)
3704 if (forever
) /* Watchdog went off. Kill the target. */
3706 target_mourn_inferior ();
3707 error ("Watchdog has expired. Target detached.\n");
3710 fputs_filtered ("Timed out.\n", gdb_stdlog
);
3716 /* We've found the start of a packet, now collect the data. */
3718 val
= read_frame (buf
);
3724 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
3725 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
3726 fprintf_unfiltered (gdb_stdlog
, "\n");
3728 SERIAL_WRITE (remote_desc
, "+", 1);
3732 /* Try the whole thing again. */
3734 SERIAL_WRITE (remote_desc
, "-", 1);
3737 /* We have tried hard enough, and just can't receive the packet. Give up. */
3739 printf_unfiltered ("Ignoring packet error, continuing...\n");
3740 SERIAL_WRITE (remote_desc
, "+", 1);
3746 /* For some mysterious reason, wait_for_inferior calls kill instead of
3747 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3751 target_mourn_inferior ();
3755 /* Use catch_errors so the user can quit from gdb even when we aren't on
3756 speaking terms with the remote system. */
3757 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
3759 /* Don't wait for it to die. I'm not really sure it matters whether
3760 we do or not. For the existing stubs, kill is a noop. */
3761 target_mourn_inferior ();
3764 /* Async version of remote_kill. */
3766 remote_async_kill ()
3768 /* Unregister the file descriptor from the event loop. */
3770 delete_file_handler (remote_desc
->fd
);
3772 /* For some mysterious reason, wait_for_inferior calls kill instead of
3773 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3777 target_mourn_inferior ();
3781 /* Use catch_errors so the user can quit from gdb even when we aren't on
3782 speaking terms with the remote system. */
3783 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
3785 /* Don't wait for it to die. I'm not really sure it matters whether
3786 we do or not. For the existing stubs, kill is a noop. */
3787 target_mourn_inferior ();
3793 remote_mourn_1 (&remote_ops
);
3797 extended_remote_mourn ()
3799 /* We do _not_ want to mourn the target like this; this will
3800 remove the extended remote target from the target stack,
3801 and the next time the user says "run" it'll fail.
3803 FIXME: What is the right thing to do here? */
3805 remote_mourn_1 (&extended_remote_ops
);
3809 /* Worker function for remote_mourn. */
3811 remote_mourn_1 (target
)
3812 struct target_ops
*target
;
3814 unpush_target (target
);
3815 generic_mourn_inferior ();
3818 /* In the extended protocol we want to be able to do things like
3819 "run" and have them basically work as expected. So we need
3820 a special create_inferior function.
3822 FIXME: One day add support for changing the exec file
3823 we're debugging, arguments and an environment. */
3826 extended_remote_create_inferior (exec_file
, args
, env
)
3831 /* Rip out the breakpoints; we'll reinsert them after restarting
3832 the remote server. */
3833 remove_breakpoints ();
3835 /* Now restart the remote server. */
3836 extended_remote_restart ();
3838 /* Now put the breakpoints back in. This way we're safe if the
3839 restart function works via a unix fork on the remote side. */
3840 insert_breakpoints ();
3842 /* Clean up from the last time we were running. */
3843 clear_proceed_status ();
3845 /* Let the remote process run. */
3846 proceed (-1, TARGET_SIGNAL_0
, 0);
3849 /* Async version of extended_remote_create_inferior. */
3851 extended_remote_async_create_inferior (exec_file
, args
, env
)
3856 /* Rip out the breakpoints; we'll reinsert them after restarting
3857 the remote server. */
3858 remove_breakpoints ();
3860 /* If running asynchronously, register the target file descriptor
3861 with the event loop. */
3863 add_file_handler (remote_desc
->fd
, fetch_inferior_event
, 0);
3865 /* Now restart the remote server. */
3866 extended_remote_restart ();
3868 /* Now put the breakpoints back in. This way we're safe if the
3869 restart function works via a unix fork on the remote side. */
3870 insert_breakpoints ();
3872 /* Clean up from the last time we were running. */
3873 clear_proceed_status ();
3875 /* Let the remote process run. */
3876 proceed (-1, TARGET_SIGNAL_0
, 0);
3880 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
3881 than other targets; in those use REMOTE_BREAKPOINT instead of just
3882 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
3883 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
3884 the standard routines that are in mem-break.c. */
3886 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
3887 the choice of breakpoint instruction affects target program design and
3888 vice versa, and by making it user-tweakable, the special code here
3889 goes away and we need fewer special GDB configurations. */
3891 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
3892 #define REMOTE_BREAKPOINT
3895 #ifdef REMOTE_BREAKPOINT
3897 /* If the target isn't bi-endian, just pretend it is. */
3898 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
3899 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3900 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3903 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
3904 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
3906 #endif /* REMOTE_BREAKPOINT */
3908 /* Insert a breakpoint on targets that don't have any better breakpoint
3909 support. We read the contents of the target location and stash it,
3910 then overwrite it with a breakpoint instruction. ADDR is the target
3911 location in the target machine. CONTENTS_CACHE is a pointer to
3912 memory allocated for saving the target contents. It is guaranteed
3913 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
3914 is accomplished via BREAKPOINT_MAX). */
3917 remote_insert_breakpoint (addr
, contents_cache
)
3919 char *contents_cache
;
3921 #ifdef REMOTE_BREAKPOINT
3926 /* Try the "Z" packet if it is not already disabled.
3927 If it succeeds, then set the support to PACKET_ENABLE.
3928 If it fails, and the user has explicitly requested the Z support
3929 then report an error, otherwise, mark it disabled and go on. */
3931 if ((remote_protocol_Z
.support
== PACKET_ENABLE
)
3932 || (remote_protocol_Z
.support
== PACKET_SUPPORT_UNKNOWN
))
3934 char buf
[PBUFSIZ
], *p
= buf
;
3936 addr
= remote_address_masked (addr
);
3940 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3941 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
3942 sprintf (p
, ",%d", bp_size
);
3949 remote_protocol_Z
.support
= PACKET_ENABLE
;
3950 return (buf
[0] == 'E');
3953 /* The stub does not support the 'Z' request. If the user has
3954 explicitly requested the Z support, or if the stub previously
3955 said it supported the packet, this is an error,
3956 otherwise, mark it disabled. */
3958 else if (remote_protocol_Z
.support
== PACKET_ENABLE
)
3960 error ("Protocol error: Z packet not recognized by stub");
3964 remote_protocol_Z
.support
= PACKET_DISABLE
;
3968 #ifdef REMOTE_BREAKPOINT
3969 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
3973 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
3974 val
= target_write_memory (addr
, (char *) big_break_insn
,
3975 sizeof big_break_insn
);
3977 val
= target_write_memory (addr
, (char *) little_break_insn
,
3978 sizeof little_break_insn
);
3983 return memory_insert_breakpoint (addr
, contents_cache
);
3984 #endif /* REMOTE_BREAKPOINT */
3988 remote_remove_breakpoint (addr
, contents_cache
)
3990 char *contents_cache
;
3995 if ((remote_protocol_Z
.support
== PACKET_ENABLE
)
3996 || (remote_protocol_Z
.support
== PACKET_SUPPORT_UNKNOWN
))
3998 char buf
[PBUFSIZ
], *p
= buf
;
4004 addr
= remote_address_masked (addr
);
4005 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4006 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4007 sprintf (p
, ",%d", bp_size
);
4012 return (buf
[0] == 'E');
4015 #ifdef REMOTE_BREAKPOINT
4016 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4018 return memory_remove_breakpoint (addr
, contents_cache
);
4019 #endif /* REMOTE_BREAKPOINT */
4022 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
4024 remote_insert_watchpoint (addr
, len
, type
)
4029 char buf
[PBUFSIZ
], *p
;
4031 if (remote_protocol_Z
.support
== PACKET_DISABLE
)
4032 error ("Can't set hardware watchpoints without the 'Z' packet\n");
4034 sprintf (buf
, "Z%x,", type
+ 2 );
4035 p
= strchr (buf
, '\0');
4036 addr
= remote_address_masked (addr
);
4037 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4038 sprintf (p
, ",%lx", len
);
4043 if (buf
[0] == '\0' || buf
[0] == 'E')
4050 remote_remove_watchpoint (addr
, len
, type
)
4055 char buf
[PBUFSIZ
], *p
;
4057 sprintf (buf
, "z%x,", type
+ 2 );
4058 p
= strchr (buf
, '\0');
4059 addr
= remote_address_masked (addr
);
4060 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4061 sprintf (p
, ",%lx", len
);
4065 if (buf
[0] == '\0' || buf
[0] == 'E')
4072 remote_insert_hw_breakpoint (addr
, len
)
4076 char buf
[PBUFSIZ
], *p
= buf
;
4078 if (remote_protocol_Z
.support
== PACKET_DISABLE
)
4079 error ("Can't set hardware breakpoints without the 'Z' packet\n");
4085 addr
= remote_address_masked (addr
);
4086 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4092 if (buf
[0] == '\0' || buf
[0] == 'E')
4099 remote_remove_hw_breakpoint (addr
, len
)
4103 char buf
[PBUFSIZ
], *p
= buf
;
4109 addr
= remote_address_masked (addr
);
4110 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4116 if (buf
[0] == '\0' || buf
[0] == 'E')
4123 /* Some targets are only capable of doing downloads, and afterwards
4124 they switch to the remote serial protocol. This function provides
4125 a clean way to get from the download target to the remote target.
4126 It's basically just a wrapper so that we don't have to expose any
4127 of the internal workings of remote.c.
4129 Prior to calling this routine, you should shutdown the current
4130 target code, else you will get the "A program is being debugged
4131 already..." message. Usually a call to pop_target() suffices. */
4134 push_remote_target (name
, from_tty
)
4138 printf_filtered ("Switching to remote protocol\n");
4139 remote_open (name
, from_tty
);
4142 /* Other targets want to use the entire remote serial module but with
4143 certain remote_ops overridden. */
4146 open_remote_target (name
, from_tty
, target
, extended_p
)
4149 struct target_ops
*target
;
4152 printf_filtered ("Selecting the %sremote protocol\n",
4153 (extended_p
? "extended-" : ""));
4154 remote_open_1 (name
, from_tty
, target
, extended_p
);
4157 /* Table used by the crc32 function to calcuate the checksum. */
4159 static unsigned long crc32_table
[256] =
4162 static unsigned long
4163 crc32 (buf
, len
, crc
)
4168 if (!crc32_table
[1])
4170 /* Initialize the CRC table and the decoding table. */
4174 for (i
= 0; i
< 256; i
++)
4176 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4177 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4184 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4190 /* compare-sections command
4192 With no arguments, compares each loadable section in the exec bfd
4193 with the same memory range on the target, and reports mismatches.
4194 Useful for verifying the image on the target against the exec file.
4195 Depends on the target understanding the new "qCRC:" request. */
4198 compare_sections_command (args
, from_tty
)
4203 unsigned long host_crc
, target_crc
;
4204 extern bfd
*exec_bfd
;
4205 struct cleanup
*old_chain
;
4209 char *buf
= alloca (PBUFSIZ
);
4216 error ("command cannot be used without an exec file");
4217 if (!current_target
.to_shortname
||
4218 strcmp (current_target
.to_shortname
, "remote") != 0)
4219 error ("command can only be used with remote target");
4221 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4223 if (!(s
->flags
& SEC_LOAD
))
4224 continue; /* skip non-loadable section */
4226 size
= bfd_get_section_size_before_reloc (s
);
4228 continue; /* skip zero-length section */
4230 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
4231 if (args
&& strcmp (args
, sectname
) != 0)
4232 continue; /* not the section selected by user */
4234 matched
= 1; /* do this section */
4236 /* FIXME: assumes lma can fit into long */
4237 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
4240 /* be clever; compute the host_crc before waiting for target reply */
4241 sectdata
= xmalloc (size
);
4242 old_chain
= make_cleanup (free
, sectdata
);
4243 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4244 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4248 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4249 sectname
, lma
, lma
+ size
);
4251 error ("remote target does not support this operation");
4253 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4254 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4256 printf_filtered ("Section %s, range 0x%08x -- 0x%08x: ",
4257 sectname
, lma
, lma
+ size
);
4258 if (host_crc
== target_crc
)
4259 printf_filtered ("matched.\n");
4262 printf_filtered ("MIS-MATCHED!\n");
4266 do_cleanups (old_chain
);
4269 warning ("One or more sections of the remote executable does not match\n\
4270 the loaded file\n");
4271 if (args
&& !matched
)
4272 printf_filtered ("No loaded section named '%s'.\n", args
);
4276 remote_query (query_type
, buf
, outbuf
, bufsiz
)
4283 char *buf2
= alloca (PBUFSIZ
);
4284 char *p2
= &buf2
[0];
4288 error ("null pointer to remote bufer size specified");
4290 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4291 the caller know and return what the minimum size is */
4292 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4293 if (*bufsiz
< PBUFSIZ
)
4299 /* except for querying the minimum buffer size, target must be open */
4301 error ("remote query is only available after target open");
4303 /* we only take uppercase letters as query types, at least for now */
4304 if ((query_type
< 'A') || (query_type
> 'Z'))
4305 error ("invalid remote query type");
4308 error ("null remote query specified");
4311 error ("remote query requires a buffer to receive data");
4318 /* we used one buffer char for the remote protocol q command and another
4319 for the query type. As the remote protocol encapsulation uses 4 chars
4320 plus one extra in case we are debugging (remote_debug),
4321 we have PBUFZIZ - 7 left to pack the query string */
4323 while (buf
[i
] && (i
< (PBUFSIZ
- 8)))
4325 /* bad caller may have sent forbidden characters */
4326 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
4327 error ("illegal characters in query string");
4335 error ("query larger than available buffer");
4347 remote_rcmd (char *command
,
4348 struct gdb_file
*outbuf
)
4351 char *buf
= alloca (PBUFSIZ
);
4355 error ("remote rcmd is only available after target open");
4357 /* Send a NULL command across as an empty command */
4358 if (command
== NULL
)
4361 /* The query prefix */
4362 strcpy (buf
, "qRcmd,");
4363 p
= strchr (buf
, '\0');
4365 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > PBUFSIZ
)
4366 error ("\"monitor\" command ``%s'' is too long\n", command
);
4368 /* Encode the actual command */
4369 for (i
= 0; command
[i
]; i
++)
4371 *p
++ = tohex ((command
[i
] >> 4) & 0xf);
4372 *p
++ = tohex (command
[i
] & 0xf);
4376 if (putpkt (buf
) < 0)
4377 error ("Communication problem with target\n");
4379 /* get/display the response */
4382 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4386 error ("Target does not support this command\n");
4387 if (buf
[0] == 'O' && buf
[1] != 'K')
4389 remote_console_output (buf
+ 1); /* 'O' message from stub */
4392 if (strcmp (buf
, "OK") == 0)
4394 if (strlen (buf
) == 3 && buf
[0] == 'E'
4395 && isdigit (buf
[1]) && isdigit (buf
[2]))
4397 error ("Protocol error with Rcmd");
4399 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
4401 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
4402 fputc_unfiltered (c
, outbuf
);
4409 packet_command (args
, from_tty
)
4413 char *buf
= alloca (PBUFSIZ
);
4416 error ("command can only be used with remote target");
4419 error ("remote-packet command requires packet text as argument");
4421 puts_filtered ("sending: ");
4422 print_packet (args
);
4423 puts_filtered ("\n");
4427 puts_filtered ("received: ");
4429 puts_filtered ("\n");
4433 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4435 static void display_thread_info
PARAMS ((struct gdb_ext_thread_info
* info
));
4437 static void threadset_test_cmd
PARAMS ((char *cmd
, int tty
));
4439 static void threadalive_test
PARAMS ((char *cmd
, int tty
));
4441 static void threadlist_test_cmd
PARAMS ((char *cmd
, int tty
));
4443 int get_and_display_threadinfo
PARAMS ((threadref
* ref
));
4445 static void threadinfo_test_cmd
PARAMS ((char *cmd
, int tty
));
4447 static int thread_display_step
PARAMS ((threadref
* ref
, void *context
));
4449 static void threadlist_update_test_cmd
PARAMS ((char *cmd
, int tty
));
4451 static void init_remote_threadtests
PARAMS ((void));
4453 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4456 threadset_test_cmd (cmd
, tty
)
4460 int sample_thread
= SAMPLE_THREAD
;
4462 printf_filtered ("Remote threadset test\n");
4463 set_thread (sample_thread
, 1);
4468 threadalive_test (cmd
, tty
)
4472 int sample_thread
= SAMPLE_THREAD
;
4474 if (remote_thread_alive (sample_thread
))
4475 printf_filtered ("PASS: Thread alive test\n");
4477 printf_filtered ("FAIL: Thread alive test\n");
4480 void output_threadid
PARAMS ((char *title
, threadref
* ref
));
4483 output_threadid (title
, ref
)
4489 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
4491 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
4495 threadlist_test_cmd (cmd
, tty
)
4500 threadref nextthread
;
4501 int done
, result_count
;
4502 threadref threadlist
[3];
4504 printf_filtered ("Remote Threadlist test\n");
4505 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
4506 &result_count
, &threadlist
[0]))
4507 printf_filtered ("FAIL: threadlist test\n");
4510 threadref
*scan
= threadlist
;
4511 threadref
*limit
= scan
+ result_count
;
4513 while (scan
< limit
)
4514 output_threadid (" thread ", scan
++);
4519 display_thread_info (info
)
4520 struct gdb_ext_thread_info
*info
;
4522 output_threadid ("Threadid: ", &info
->threadid
);
4523 printf_filtered ("Name: %s\n ", info
->shortname
);
4524 printf_filtered ("State: %s\n", info
->display
);
4525 printf_filtered ("other: %s\n\n", info
->more_display
);
4529 get_and_display_threadinfo (ref
)
4534 struct gdb_ext_thread_info threadinfo
;
4536 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
4537 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
4538 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
4539 display_thread_info (&threadinfo
);
4544 threadinfo_test_cmd (cmd
, tty
)
4548 int athread
= SAMPLE_THREAD
;
4552 int_to_threadref (&thread
, athread
);
4553 printf_filtered ("Remote Threadinfo test\n");
4554 if (!get_and_display_threadinfo (&thread
))
4555 printf_filtered ("FAIL cannot get thread info\n");
4559 thread_display_step (ref
, context
)
4563 /* output_threadid(" threadstep ",ref); *//* simple test */
4564 return get_and_display_threadinfo (ref
);
4568 threadlist_update_test_cmd (cmd
, tty
)
4572 printf_filtered ("Remote Threadlist update test\n");
4573 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
4577 init_remote_threadtests (void)
4579 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
4580 "Fetch and print the remote list of thread identifiers, one pkt only");
4581 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
4582 "Fetch and display info about one thread");
4583 add_com ("tset", class_obscure
, threadset_test_cmd
,
4584 "Test setting to a different thread");
4585 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
4586 "Iterate through updating all remote thread info");
4587 add_com ("talive", class_obscure
, threadalive_test
,
4588 " Remote thread alive test ");
4596 remote_ops
.to_shortname
= "remote";
4597 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
4599 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4600 Specify the serial device it is connected to (e.g. /dev/ttya).";
4601 remote_ops
.to_open
= remote_open
;
4602 remote_ops
.to_close
= remote_close
;
4603 remote_ops
.to_detach
= remote_detach
;
4604 remote_ops
.to_resume
= remote_resume
;
4605 remote_ops
.to_wait
= remote_wait
;
4606 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
4607 remote_ops
.to_store_registers
= remote_store_registers
;
4608 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
4609 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
4610 remote_ops
.to_files_info
= remote_files_info
;
4611 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
4612 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
4613 remote_ops
.to_kill
= remote_kill
;
4614 remote_ops
.to_load
= generic_load
;
4615 remote_ops
.to_mourn_inferior
= remote_mourn
;
4616 remote_ops
.to_thread_alive
= remote_thread_alive
;
4617 remote_ops
.to_find_new_threads
= remote_threads_info
;
4618 remote_ops
.to_stop
= remote_stop
;
4619 remote_ops
.to_query
= remote_query
;
4620 remote_ops
.to_rcmd
= remote_rcmd
;
4621 remote_ops
.to_stratum
= process_stratum
;
4622 remote_ops
.to_has_all_memory
= 1;
4623 remote_ops
.to_has_memory
= 1;
4624 remote_ops
.to_has_stack
= 1;
4625 remote_ops
.to_has_registers
= 1;
4626 remote_ops
.to_has_execution
= 1;
4627 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
4628 remote_ops
.to_magic
= OPS_MAGIC
;
4631 /* Set up the extended remote vector by making a copy of the standard
4632 remote vector and adding to it. */
4635 init_extended_remote_ops ()
4637 extended_remote_ops
= remote_ops
;
4639 extended_remote_ops
.to_shortname
= "extended-remote";
4640 extended_remote_ops
.to_longname
=
4641 "Extended remote serial target in gdb-specific protocol";
4642 extended_remote_ops
.to_doc
=
4643 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4644 Specify the serial device it is connected to (e.g. /dev/ttya).",
4645 extended_remote_ops
.to_open
= extended_remote_open
;
4646 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
4647 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
4651 * Command: info remote-process
4653 * This implements Cisco's version of the "info proc" command.
4655 * This query allows the target stub to return an arbitrary string
4656 * (or strings) giving arbitrary information about the target process.
4657 * This is optional; the target stub isn't required to implement it.
4659 * Syntax: qfProcessInfo request first string
4660 * qsProcessInfo request subsequent string
4661 * reply: 'O'<hex-encoded-string>
4662 * 'l' last reply (empty)
4666 remote_info_process (args
, from_tty
)
4670 char *buf
= alloca (PBUFSIZ
);
4672 if (remote_desc
== 0)
4673 error ("Command can only be used when connected to the remote target.");
4675 putpkt ("qfProcessInfo");
4678 return; /* Silently: target does not support this feature. */
4681 error ("info proc: target error.");
4683 while (buf
[0] == 'O') /* Capitol-O packet */
4685 remote_console_output (&buf
[1]);
4686 putpkt ("qsProcessInfo");
4696 remote_cisco_open (name
, from_tty
)
4702 "To open a remote debug connection, you need to specify what \n\
4703 device is attached to the remote system (e.g. host:port).");
4705 target_preopen (from_tty
);
4707 unpush_target (&remote_cisco_ops
);
4709 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
4711 remote_desc
= SERIAL_OPEN (name
);
4713 perror_with_name (name
);
4716 * If a baud rate was specified on the gdb command line it will
4717 * be greater than the initial value of -1. If it is, use it otherwise
4721 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
4722 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
4724 SERIAL_CLOSE (remote_desc
);
4725 perror_with_name (name
);
4728 SERIAL_RAW (remote_desc
);
4730 /* If there is something sitting in the buffer we might take it as a
4731 response to a command, which would be bad. */
4732 SERIAL_FLUSH_INPUT (remote_desc
);
4736 puts_filtered ("Remote debugging using ");
4737 puts_filtered (name
);
4738 puts_filtered ("\n");
4741 remote_cisco_mode
= 1;
4743 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
4745 init_packet_config (&remote_protocol_P
);
4746 init_packet_config (&remote_protocol_Z
);
4748 general_thread
= -2;
4749 continue_thread
= -2;
4751 /* Force remote_write_bytes to check whether target supports
4752 binary downloading. */
4753 init_packet_config (&remote_protocol_binary_download
);
4755 /* Without this, some commands which require an active target (such
4756 as kill) won't work. This variable serves (at least) double duty
4757 as both the pid of the target process (if it has such), and as a
4758 flag indicating that a target is active. These functions should
4759 be split out into seperate variables, especially since GDB will
4760 someday have a notion of debugging several processes. */
4761 inferior_pid
= MAGIC_NULL_PID
;
4763 /* Start the remote connection; if error (0), discard this target. */
4765 if (!catch_errors (remote_start_remote_dummy
, (char *) 0,
4766 "Couldn't establish connection to remote target\n",
4775 remote_cisco_close (quitting
)
4778 remote_cisco_mode
= 0;
4779 remote_close (quitting
);
4786 remote_mourn_1 (&remote_cisco_ops
);
4798 /* shared between readsocket() and readtty() */
4799 static char *tty_input
;
4801 static int escape_count
;
4802 static int echo_check
;
4803 extern int quit_flag
;
4810 /* Loop until the socket doesn't have any more data */
4812 while ((data
= readchar (0)) >= 0)
4814 /* Check for the escape sequence */
4817 /* If this is the fourth escape, get out */
4818 if (++escape_count
== 4)
4823 { /* This is a '|', but not the fourth in a row.
4824 Continue without echoing it. If it isn't actually
4825 one of four in a row, it'll be echoed later. */
4832 /* Ensure any pending '|'s are flushed. */
4834 for (; escape_count
> 0; escape_count
--)
4838 if (data
== '\r') /* If this is a return character, */
4839 continue; /* - just supress it. */
4841 if (echo_check
!= -1) /* Check for echo of user input. */
4843 if (tty_input
[echo_check
] == data
)
4845 echo_check
++; /* Character matched user input: */
4846 continue; /* Continue without echoing it. */
4848 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
4849 { /* End of the line (and of echo checking). */
4850 echo_check
= -1; /* No more echo supression */
4851 continue; /* Continue without echoing. */
4854 { /* Failed check for echo of user input.
4855 We now have some suppressed output to flush! */
4858 for (j
= 0; j
< echo_check
; j
++)
4859 putchar (tty_input
[j
]);
4863 putchar (data
); /* Default case: output the char. */
4866 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
4867 return READ_MORE
; /* Try to read some more */
4869 return FATAL_ERROR
; /* Trouble, bail out */
4878 /* First, read a buffer full from the terminal */
4879 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
4880 if (tty_bytecount
== -1)
4882 perror ("readtty: read failed");
4886 /* Remove a quoted newline. */
4887 if (tty_input
[tty_bytecount
- 1] == '\n' &&
4888 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
4890 tty_input
[--tty_bytecount
] = 0; /* remove newline */
4891 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
4894 /* Turn trailing newlines into returns */
4895 if (tty_input
[tty_bytecount
- 1] == '\n')
4896 tty_input
[tty_bytecount
- 1] = '\r';
4898 /* If the line consists of a ~, enter debugging mode. */
4899 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
4902 /* Make this a zero terminated string and write it out */
4903 tty_input
[tty_bytecount
] = 0;
4904 if (SERIAL_WRITE (remote_desc
, tty_input
, tty_bytecount
))
4906 perror_with_name ("readtty: write failed");
4916 fd_set input
; /* file descriptors for select */
4917 int tablesize
; /* max number of FDs for select */
4921 extern int escape_count
; /* global shared by readsocket */
4922 extern int echo_check
; /* ditto */
4927 tablesize
= 8 * sizeof (input
);
4931 /* Check for anything from our socket - doesn't block. Note that
4932 this must be done *before* the select as there may be
4933 buffered I/O waiting to be processed. */
4935 if ((status
= readsocket ()) == FATAL_ERROR
)
4937 error ("Debugging terminated by communications error");
4939 else if (status
!= READ_MORE
)
4944 fflush (stdout
); /* Flush output before blocking */
4946 /* Now block on more socket input or TTY input */
4949 FD_SET (fileno (stdin
), &input
);
4950 FD_SET (remote_desc
->fd
, &input
);
4952 status
= select (tablesize
, &input
, 0, 0, 0);
4953 if ((status
== -1) && (errno
!= EINTR
))
4955 error ("Communications error on select %d", errno
);
4958 /* Handle Control-C typed */
4962 if ((++quit_count
) == 2)
4964 if (query ("Interrupt GDB? "))
4966 printf_filtered ("Interrupted by user.\n");
4967 return_to_top_level (RETURN_QUIT
);
4974 SERIAL_SEND_BREAK (remote_desc
);
4976 SERIAL_WRITE (remote_desc
, "\003", 1);
4981 /* Handle console input */
4983 if (FD_ISSET (fileno (stdin
), &input
))
4987 status
= readtty ();
4988 if (status
== READ_MORE
)
4991 return status
; /* telnet session ended */
4997 remote_cisco_wait (pid
, status
)
4999 struct target_waitstatus
*status
;
5001 if (minitelnet () != ENTER_DEBUG
)
5003 error ("Debugging session terminated by protocol error");
5006 return remote_wait (pid
, status
);
5010 init_remote_cisco_ops ()
5012 remote_cisco_ops
.to_shortname
= "cisco";
5013 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5014 remote_cisco_ops
.to_doc
=
5015 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5016 Specify the serial device it is connected to (e.g. host:2020).";
5017 remote_cisco_ops
.to_open
= remote_cisco_open
;
5018 remote_cisco_ops
.to_close
= remote_cisco_close
;
5019 remote_cisco_ops
.to_detach
= remote_detach
;
5020 remote_cisco_ops
.to_resume
= remote_resume
;
5021 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5022 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5023 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5024 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5025 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5026 remote_cisco_ops
.to_files_info
= remote_files_info
;
5027 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5028 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5029 remote_cisco_ops
.to_kill
= remote_kill
;
5030 remote_cisco_ops
.to_load
= generic_load
;
5031 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5032 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5033 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5034 remote_cisco_ops
.to_stratum
= process_stratum
;
5035 remote_cisco_ops
.to_has_all_memory
= 1;
5036 remote_cisco_ops
.to_has_memory
= 1;
5037 remote_cisco_ops
.to_has_stack
= 1;
5038 remote_cisco_ops
.to_has_registers
= 1;
5039 remote_cisco_ops
.to_has_execution
= 1;
5040 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5043 /* Target async and target extended-async.
5045 This are temporary targets, until it is all tested. Eventually
5046 async support will be incorporated int the usual 'remote'
5050 init_remote_async_ops ()
5052 remote_async_ops
.to_shortname
= "async";
5053 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5054 remote_async_ops
.to_doc
=
5055 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5056 Specify the serial device it is connected to (e.g. /dev/ttya).";
5057 remote_async_ops
.to_open
= remote_async_open
;
5058 remote_async_ops
.to_close
= remote_close
;
5059 remote_async_ops
.to_detach
= remote_async_detach
;
5060 remote_async_ops
.to_resume
= remote_async_resume
;
5061 remote_async_ops
.to_wait
= remote_async_wait
;
5062 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5063 remote_async_ops
.to_store_registers
= remote_store_registers
;
5064 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5065 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5066 remote_async_ops
.to_files_info
= remote_files_info
;
5067 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5068 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5069 remote_async_ops
.to_kill
= remote_async_kill
;
5070 remote_async_ops
.to_load
= generic_load
;
5071 remote_async_ops
.to_mourn_inferior
= remote_mourn
;
5072 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5073 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5074 remote_async_ops
.to_stop
= remote_stop
;
5075 remote_async_ops
.to_query
= remote_query
;
5076 remote_async_ops
.to_rcmd
= remote_rcmd
;
5077 remote_async_ops
.to_stratum
= process_stratum
;
5078 remote_async_ops
.to_has_all_memory
= 1;
5079 remote_async_ops
.to_has_memory
= 1;
5080 remote_async_ops
.to_has_stack
= 1;
5081 remote_async_ops
.to_has_registers
= 1;
5082 remote_async_ops
.to_has_execution
= 1;
5083 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5084 remote_async_ops
.to_has_async_exec
= 1;
5085 remote_async_ops
.to_magic
= OPS_MAGIC
;
5088 /* Set up the async extended remote vector by making a copy of the standard
5089 remote vector and adding to it. */
5092 init_extended_async_remote_ops ()
5094 extended_async_remote_ops
= remote_async_ops
;
5096 extended_async_remote_ops
.to_shortname
= "extended-async";
5097 extended_async_remote_ops
.to_longname
=
5098 "Extended remote serial target in async gdb-specific protocol";
5099 extended_async_remote_ops
.to_doc
=
5100 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5101 Specify the serial device it is connected to (e.g. /dev/ttya).",
5102 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5103 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5104 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5108 set_remote_cmd (args
, from_tty
)
5117 build_remote_gdbarch_data ()
5119 tty_input
= xmalloc (PBUFSIZ
);
5123 _initialize_remote ()
5125 static struct cmd_list_element
*remote_set_cmdlist
;
5126 static struct cmd_list_element
*remote_show_cmdlist
;
5128 /* architecture specific data */
5129 build_remote_gdbarch_data ();
5130 register_gdbarch_swap (&tty_input
, sizeof (&tty_input
), NULL
);
5131 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5133 /* runtime constants - we retain the value of remote_write_size
5134 across architecture swaps. */
5135 remote_write_size
= PBUFSIZ
;
5138 add_target (&remote_ops
);
5140 init_extended_remote_ops ();
5141 add_target (&extended_remote_ops
);
5143 init_remote_async_ops ();
5144 add_target (&remote_async_ops
);
5146 init_extended_async_remote_ops ();
5147 add_target (&extended_async_remote_ops
);
5149 init_remote_cisco_ops ();
5150 add_target (&remote_cisco_ops
);
5153 init_remote_threadtests ();
5156 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5157 Remote protocol specific variables\n\
5158 Configure various remote-protocol specific variables such as\n\
5159 the packets being used",
5160 &remote_set_cmdlist
, "remote ",
5161 0/*allow-unknown*/, &setlist
);
5162 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5163 Remote protocol specific variables\n\
5164 Configure various remote-protocol specific variables such as\n\
5165 the packets being used",
5166 &remote_show_cmdlist
, "remote ",
5167 0/*allow-unknown*/, &showlist
);
5169 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
5170 "Compare section data on target to the exec file.\n\
5171 Argument is a single section name (default: all loaded sections).",
5174 add_cmd ("packet", class_maintenance
, packet_command
,
5175 "Send an arbitrary packet to a remote target.\n\
5176 maintenance packet TEXT\n\
5177 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5178 this command sends the string TEXT to the inferior, and displays the\n\
5179 response packet. GDB supplies the initial `$' character, and the\n\
5180 terminating `#' character and checksum.",
5184 (add_set_cmd ("remotetimeout", no_class
,
5185 var_integer
, (char *) &remote_timeout
,
5186 "Set timeout value for remote read.\n",
5191 (add_set_cmd ("remotebreak", no_class
,
5192 var_boolean
, (char *) &remote_break
,
5193 "Set whether to send break if interrupted.\n",
5198 (add_set_cmd ("remotewritesize", no_class
,
5199 var_integer
, (char *) &remote_write_size
,
5200 "Set the maximum number of bytes per memory write packet.\n",
5204 remote_address_size
= TARGET_PTR_BIT
;
5206 (add_set_cmd ("remoteaddresssize", class_obscure
,
5207 var_integer
, (char *) &remote_address_size
,
5208 "Set the maximum size of the address (in bits) \
5209 in a memory packet.\n",
5213 add_packet_config_cmd (&remote_protocol_binary_download
,
5214 "X", "binary-download",
5215 set_remote_protocol_binary_download_cmd
,
5216 show_remote_protocol_binary_download_cmd
,
5217 &remote_set_cmdlist
, &remote_show_cmdlist
);
5219 /* XXXX - should ``set remotebinarydownload'' be retained for
5222 (add_set_cmd ("remotebinarydownload", no_class
,
5223 var_boolean
, (char *) &remote_binary_download
,
5224 "Set binary downloads.\n", &setlist
),
5228 add_info ("remote-process", remote_info_process
,
5229 "Query the remote system for process info.");
5231 add_packet_config_cmd (&remote_protocol_P
, "P", "set-register",
5232 set_remote_protocol_P_packet_cmd
,
5233 show_remote_protocol_P_packet_cmd
,
5234 &remote_set_cmdlist
, &remote_show_cmdlist
);
5236 add_packet_config_cmd (&remote_protocol_Z
, "Z", "breakpoint",
5237 set_remote_protocol_Z_packet_cmd
,
5238 show_remote_protocol_Z_packet_cmd
,
5239 &remote_set_cmdlist
, &remote_show_cmdlist
);