1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 91, 92, 93, 94, 95, 96, 97, 1998
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, Boston, MA 02111-1307, USA. */
21 /* Remote communication protocol.
23 A debug packet whose contents are <data>
24 is encapsulated for transmission in the form:
26 $ <data> # CSUM1 CSUM2
28 <data> must be ASCII alphanumeric and cannot include characters
29 '$' or '#'. If <data> starts with two characters followed by
30 ':', then the existing stubs interpret this as a sequence number.
32 CSUM1 and CSUM2 are ascii hex representation of an 8-bit
33 checksum of <data>, the most significant nibble is sent first.
34 the hex digits 0-9,a-f are used.
36 Receiver responds with:
38 + - if CSUM is correct and ready for next packet
39 - - if CSUM is incorrect
42 Most values are encoded in ascii hex digits. Signal numbers are according
43 to the numbering in target.h.
47 set thread Hct... Set thread for subsequent operations.
48 c = 'c' for thread used in step and
49 continue; t... can be -1 for all
51 c = 'g' for thread used in other
52 operations. If zero, pick a thread,
58 reply XX....X Each byte of register data
59 is described by two hex digits.
60 Registers are in the internal order
61 for GDB, and the bytes in a register
62 are in the same order the machine uses.
65 write regs GXX..XX Each byte of register data
66 is described by two hex digits.
70 write reg Pn...=r... Write register n... with value r...,
71 which contains two hex digits for each
72 byte in the register (target byte
76 (not supported by all stubs).
78 read mem mAA..AA,LLLL AA..AA is address, LLLL is length.
79 reply XX..XX XX..XX is mem contents
80 Can be fewer bytes than requested
81 if able to read only part of the data.
84 write mem MAA..AA,LLLL:XX..XX
86 LLLL is number of bytes,
89 ENN for an error (this includes the case
90 where only part of the data was
93 write mem XAA..AA,LLLL:XX..XX
94 (binary) AA..AA is address,
95 LLLL is number of bytes,
100 continue cAA..AA AA..AA is address to resume
101 If AA..AA is omitted,
102 resume at same address.
104 step sAA..AA AA..AA is address to resume
105 If AA..AA is omitted,
106 resume at same address.
108 continue with Csig;AA..AA Continue with signal sig (hex signal
109 signal number). If ;AA..AA is omitted,
110 resume at same address.
112 step with Ssig;AA..AA Like 'C' but step not continue.
115 last signal ? Reply the current reason for stopping.
116 This is the same reply as is generated
117 for step or cont : SAA where AA is the
122 There is no immediate reply to step or cont.
123 The reply comes when the machine stops.
124 It is SAA AA is the signal number.
126 or... TAAn...:r...;n...:r...;n...:r...;
128 n... = register number (hex)
129 r... = register contents
131 r... = thread process ID. This is
133 n... = other string not starting
134 with valid hex digit.
135 gdb should ignore this n,r pair
136 and go on to the next. This way
137 we can extend the protocol.
138 or... WAA The process exited, and AA is
139 the exit status. This is only
140 applicable for certains sorts of
142 or... XAA The process terminated with signal
144 or (obsolete) NAA;tttttttt;dddddddd;bbbbbbbb
146 tttttttt = address of symbol "_start"
147 dddddddd = base of data section
148 bbbbbbbb = base of bss section.
149 Note: only used by Cisco Systems
150 targets. The difference between this
151 reply and the "qOffsets" query is that
152 the 'N' packet may arrive spontaneously
153 whereas the 'qOffsets' is a query
154 initiated by the host debugger.
155 or... OXX..XX XX..XX is hex encoding of ASCII data. This
156 can happen at any time while the
157 program is running and the debugger
158 should continue to wait for
161 thread alive TXX Find out if the thread XX is alive.
162 reply OK thread is still alive
165 remote restart RXX Restart the remote server
167 extended ops ! Use the extended remote protocol.
168 Sticky -- only needs to be set once.
172 toggle debug d toggle debug flag (see 386 & 68k stubs)
173 reset r reset -- see sparc stub.
174 reserved <other> On other requests, the stub should
175 ignore the request and send an empty
176 response ($#<checksum>). This way
177 we can extend the protocol and GDB
178 can tell whether the stub it is
179 talking to uses the old or the new.
180 search tAA:PP,MM Search backwards starting at address
181 AA for a match with pattern PP and
182 mask MM. PP and MM are 4 bytes.
183 Not supported by all stubs.
185 general query qXXXX Request info about XXXX.
186 general set QXXXX=yyyy Set value of XXXX to yyyy.
187 query sect offs qOffsets Get section offsets. Reply is
188 Text=xxx;Data=yyy;Bss=zzz
190 Responses can be run-length encoded to save space. A '*' means that
191 the next character is an ASCII encoding giving a repeat count which
192 stands for that many repititions of the character preceding the '*'.
193 The encoding is n+29, yielding a printable character where n >=3
194 (which is where rle starts to win). Don't use an n > 126.
197 "0* " means the same as "0000". */
200 #include "gdb_string.h"
204 #include "inferior.h"
209 /*#include "terminal.h"*/
211 #include "objfiles.h"
212 #include "gdb-stabs.h"
213 #include "gdbthread.h"
219 #include <sys/types.h>
225 /* Prototypes for local functions */
227 static void build_remote_gdbarch_data
PARAMS ((void));
229 static int remote_write_bytes
PARAMS ((CORE_ADDR memaddr
,
230 char *myaddr
, int len
));
232 static int remote_read_bytes
PARAMS ((CORE_ADDR memaddr
,
233 char *myaddr
, int len
));
235 static void remote_files_info
PARAMS ((struct target_ops
*ignore
));
237 static int remote_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char * myaddr
,
238 int len
, int should_write
,
239 struct target_ops
* target
));
241 static void remote_prepare_to_store
PARAMS ((void));
243 static void remote_fetch_registers
PARAMS ((int regno
));
245 static void remote_resume
PARAMS ((int pid
, int step
,
246 enum target_signal siggnal
));
248 static int remote_start_remote
PARAMS ((PTR
));
250 static void remote_open
PARAMS ((char *name
, int from_tty
));
252 static void extended_remote_open
PARAMS ((char *name
, int from_tty
));
254 static void remote_open_1
PARAMS ((char *, int, struct target_ops
*,
257 static void remote_close
PARAMS ((int quitting
));
259 static void remote_store_registers
PARAMS ((int regno
));
261 static void remote_mourn
PARAMS ((void));
263 static void extended_remote_restart
PARAMS ((void));
265 static void extended_remote_mourn
PARAMS ((void));
267 static void extended_remote_create_inferior
PARAMS ((char *, char *, char **));
269 static void remote_mourn_1
PARAMS ((struct target_ops
*));
271 static void remote_send
PARAMS ((char *buf
));
273 static int readchar
PARAMS ((int timeout
));
275 static int remote_wait
PARAMS ((int pid
, struct target_waitstatus
* status
));
277 static void remote_kill
PARAMS ((void));
279 static int tohex
PARAMS ((int nib
));
281 static void remote_detach
PARAMS ((char *args
, int from_tty
));
283 static void remote_interrupt
PARAMS ((int signo
));
285 static void remote_interrupt_twice
PARAMS ((int signo
));
287 static void interrupt_query
PARAMS ((void));
289 static void set_thread
PARAMS ((int, int));
291 static int remote_thread_alive
PARAMS ((int));
293 static void get_offsets
PARAMS ((void));
295 static int read_frame
PARAMS ((char *));
297 static int remote_insert_breakpoint
PARAMS ((CORE_ADDR
, char *));
299 static int remote_remove_breakpoint
PARAMS ((CORE_ADDR
, char *));
301 static int hexnumlen
PARAMS ((ULONGEST num
));
303 static void init_remote_ops
PARAMS ((void));
305 static void init_extended_remote_ops
PARAMS ((void));
307 static void init_remote_cisco_ops
PARAMS ((void));
309 static struct target_ops remote_cisco_ops
;
311 static void remote_stop
PARAMS ((void));
313 static int ishex
PARAMS ((int ch
, int *val
));
315 static int stubhex
PARAMS ((int ch
));
317 static int remote_query
PARAMS ((int/*char*/, char *, char *, int *));
319 static int hexnumstr
PARAMS ((char *, ULONGEST
));
321 static CORE_ADDR remote_address_masked
PARAMS ((CORE_ADDR
));
323 static void print_packet
PARAMS ((char *));
325 static unsigned long crc32
PARAMS ((unsigned char *, int, unsigned int));
327 static void compare_sections_command
PARAMS ((char *, int));
329 static void packet_command
PARAMS ((char *, int));
331 static int stub_unpack_int
PARAMS ((char *buff
, int fieldlength
));
333 static int remote_current_thread
PARAMS ((int oldpid
));
335 static void remote_find_new_threads
PARAMS ((void));
337 static void record_currthread
PARAMS ((int currthread
));
339 /* exported functions */
341 extern int fromhex
PARAMS ((int a
));
343 extern void getpkt
PARAMS ((char *buf
, int forever
));
345 extern int putpkt
PARAMS ((char *buf
));
347 static int putpkt_binary
PARAMS ((char *buf
, int cnt
));
349 void remote_console_output
PARAMS ((char *));
351 static void check_binary_download
PARAMS ((CORE_ADDR addr
));
353 /* Define the target subroutine names */
355 void open_remote_target
PARAMS ((char *, int, struct target_ops
*, int));
357 void _initialize_remote
PARAMS ((void));
361 static struct target_ops remote_ops
;
363 static struct target_ops extended_remote_ops
;
365 /* This was 5 seconds, which is a long time to sit and wait.
366 Unless this is going though some terminal server or multiplexer or
367 other form of hairy serial connection, I would think 2 seconds would
370 /* Changed to allow option to set timeout value.
371 was static int remote_timeout = 2; */
372 extern int remote_timeout
;
374 /* This variable chooses whether to send a ^C or a break when the user
375 requests program interruption. Although ^C is usually what remote
376 systems expect, and that is the default here, sometimes a break is
377 preferable instead. */
379 static int remote_break
;
381 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
382 remote_open knows that we don't have a file open when the program
384 static serial_t remote_desc
= NULL
;
386 /* This is set by the target (thru the 'S' message)
387 to denote that the target is in kernel mode. */
388 static int cisco_kernel_mode
= 0;
390 /* This variable (available to the user via "set remotebinarydownload")
391 dictates whether downloads are sent in binary (via the 'X' packet).
392 We assume that the stub can, and attempt to do it. This will be cleared if
393 the stub does not understand it. This switch is still needed, though
394 in cases when the packet is supported in the stub, but the connection
395 does not allow it (i.e., 7-bit serial connection only). */
396 static int remote_binary_download
= 1;
398 /* Have we already checked whether binary downloads work? */
399 static int remote_binary_checked
;
401 /* Maximum number of bytes to read/write at once. The value here
402 is chosen to fill up a packet (the headers account for the 32). */
403 #define MAXBUFBYTES(N) (((N)-32)/2)
405 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
406 and i386-stub.c. Normally, no one would notice because it only matters
407 for writing large chunks of memory (e.g. in downloads). Also, this needs
408 to be more than 400 if required to hold the registers (see below, where
409 we round it up based on REGISTER_BYTES). */
410 /* Round up PBUFSIZ to hold all the registers, at least. */
411 #define PBUFSIZ ((REGISTER_BYTES > MAXBUFBYTES (400)) \
412 ? (REGISTER_BYTES * 2 + 32) \
416 /* This variable sets the number of bytes to be written to the target
417 in a single packet. Normally PBUFSIZ is satisfactory, but some
418 targets need smaller values (perhaps because the receiving end
421 static int remote_write_size
;
423 /* This variable sets the number of bits in an address that are to be
424 sent in a memory ("M" or "m") packet. Normally, after stripping
425 leading zeros, the entire address would be sent. This variable
426 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
427 initial implementation of remote.c restricted the address sent in
428 memory packets to ``host::sizeof long'' bytes - (typically 32
429 bits). Consequently, for 64 bit targets, the upper 32 bits of an
430 address was never sent. Since fixing this bug may cause a break in
431 some remote targets this variable is principly provided to
432 facilitate backward compatibility. */
434 static int remote_address_size
;
436 /* This is the size (in chars) of the first response to the `g' command. This
437 is used to limit the size of the memory read and write commands to prevent
438 stub buffers from overflowing. The size does not include headers and
439 trailers, it is only the payload size. */
441 static int remote_register_buf_size
= 0;
443 /* Should we try the 'P' request? If this is set to one when the stub
444 doesn't support 'P', the only consequence is some unnecessary traffic. */
445 static int stub_supports_P
= 1;
447 /* These are pointers to hook functions that may be set in order to
448 modify resume/wait behavior for a particular architecture. */
450 void (*target_resume_hook
) PARAMS ((void));
451 void (*target_wait_loop_hook
) PARAMS ((void));
455 /* These are the threads which we last sent to the remote system.
456 -1 for all or -2 for not sent yet. */
457 static int general_thread
;
458 static int continue_thread
;
460 /* Call this function as a result of
461 1) A halt indication (T packet) containing a thread id
462 2) A direct query of currthread
463 3) Successful execution of set thread
467 record_currthread (currthread
)
470 general_thread
= currthread
;
472 /* If this is a new thread, add it to GDB's thread list.
473 If we leave it up to WFI to do this, bad things will happen. */
474 if (!in_thread_list (currthread
))
476 add_thread (currthread
);
477 printf_filtered ("[New %s]\n", target_pid_to_str (currthread
));
481 #define MAGIC_NULL_PID 42000
489 int state
= gen
? general_thread
: continue_thread
;
495 buf
[1] = gen
? 'g' : 'c';
496 if (th
== MAGIC_NULL_PID
)
502 sprintf (&buf
[2], "-%x", -th
);
504 sprintf (&buf
[2], "%x", th
);
510 continue_thread
= th
;
513 /* Return nonzero if the thread TH is still alive on the remote system. */
516 remote_thread_alive (tid
)
522 sprintf (buf
, "T-%08x", -tid
);
524 sprintf (buf
, "T%08x", tid
);
527 return (buf
[0] == 'O' && buf
[1] == 'K');
530 /* About these extended threadlist and threadinfo packets. They are
531 variable length packets but, the fields within them are often fixed
532 length. They are redundent enough to send over UDP as is the
533 remote protocol in general. There is a matching unit test module
536 #define OPAQUETHREADBYTES 8
538 /* a 64 bit opaque identifier */
539 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
541 /* WARNING: This threadref data structure comes from the remote O.S., libstub
542 protocol encoding, and remote.c. it is not particularly changable */
544 /* Right now, the internal structure is int. We want it to be bigger.
548 typedef int gdb_threadref
; /* internal GDB thread reference */
550 /* gdb_ext_thread_info is an internal GDB data structure which is
551 equivalint to the reply of the remote threadinfo packet */
553 struct gdb_ext_thread_info
555 threadref threadid
; /* External form of thread reference */
556 int active
; /* Has state interesting to GDB? , regs, stack */
557 char display
[256]; /* Brief state display, name, blocked/syspended */
558 char shortname
[32]; /* To be used to name threads */
559 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
562 /* The volume of remote transfers can be limited by submitting
563 a mask containing bits specifying the desired information.
564 Use a union of these values as the 'selection' parameter to
565 get_thread_info. FIXME: Make these TAG names more thread specific.
568 #define TAG_THREADID 1
570 #define TAG_DISPLAY 4
571 #define TAG_THREADNAME 8
572 #define TAG_MOREDISPLAY 16
574 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
576 char *unpack_varlen_hex
PARAMS ((char *buff
, int *result
));
578 static char *unpack_nibble
PARAMS ((char *buf
, int *val
));
580 static char *pack_nibble
PARAMS ((char *buf
, int nibble
));
582 static char *pack_hex_byte
PARAMS ((char *pkt
, int/*unsigned char*/ byte
));
584 static char *unpack_byte
PARAMS ((char *buf
, int *value
));
586 static char *pack_int
PARAMS ((char *buf
, int value
));
588 static char *unpack_int
PARAMS ((char *buf
, int *value
));
590 static char *unpack_string
PARAMS ((char *src
, char *dest
, int length
));
592 static char *pack_threadid
PARAMS ((char *pkt
, threadref
*id
));
594 static char *unpack_threadid
PARAMS ((char *inbuf
, threadref
*id
));
596 void int_to_threadref
PARAMS ((threadref
*id
, int value
));
598 static int threadref_to_int
PARAMS ((threadref
*ref
));
600 static void copy_threadref
PARAMS ((threadref
*dest
, threadref
*src
));
602 static int threadmatch
PARAMS ((threadref
*dest
, threadref
*src
));
604 static char *pack_threadinfo_request
PARAMS ((char *pkt
, int mode
,
607 static int remote_unpack_thread_info_response
PARAMS ((char *pkt
,
608 threadref
*expectedref
,
609 struct gdb_ext_thread_info
*info
));
612 static int remote_get_threadinfo
PARAMS ((threadref
*threadid
,
613 int fieldset
, /*TAG mask */
614 struct gdb_ext_thread_info
*info
));
616 static int adapt_remote_get_threadinfo
PARAMS ((gdb_threadref
*ref
,
618 struct gdb_ext_thread_info
*info
));
620 static char *pack_threadlist_request
PARAMS ((char *pkt
, int startflag
,
622 threadref
*nextthread
));
624 static int parse_threadlist_response
PARAMS ((char *pkt
,
626 threadref
*original_echo
,
627 threadref
*resultlist
,
630 static int remote_get_threadlist
PARAMS ((int startflag
,
631 threadref
*nextthread
,
635 threadref
*threadlist
));
637 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
639 static int remote_threadlist_iterator
PARAMS ((rmt_thread_action stepfunction
,
640 void *context
, int looplimit
));
642 static int remote_newthread_step
PARAMS ((threadref
*ref
, void *context
));
644 /* encode 64 bits in 16 chars of hex */
646 static const char hexchars
[] = "0123456789abcdef";
653 if ((ch
>= 'a') && (ch
<= 'f'))
655 *val
= ch
- 'a' + 10;
658 if ((ch
>= 'A') && (ch
<= 'F'))
660 *val
= ch
- 'A' + 10;
663 if ((ch
>= '0') && (ch
<= '9'))
675 if (ch
>= 'a' && ch
<= 'f')
676 return ch
- 'a' + 10;
677 if (ch
>= '0' && ch
<= '9')
679 if (ch
>= 'A' && ch
<= 'F')
680 return ch
- 'A' + 10;
685 stub_unpack_int (buff
, fieldlength
)
694 nibble
= stubhex (*buff
++);
698 retval
= retval
<< 4;
704 unpack_varlen_hex (buff
, result
)
705 char *buff
; /* packet to parse */
711 while (ishex (*buff
, &nibble
))
714 retval
= retval
<< 4;
715 retval
|= nibble
& 0x0f;
722 unpack_nibble (buf
, val
)
731 pack_nibble (buf
, nibble
)
735 *buf
++ = hexchars
[(nibble
& 0x0f)];
740 pack_hex_byte (pkt
, byte
)
744 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
745 *pkt
++ = hexchars
[(byte
& 0xf)];
750 unpack_byte (buf
, value
)
754 *value
= stub_unpack_int (buf
, 2);
759 pack_int (buf
, value
)
763 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
764 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
765 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
766 buf
= pack_hex_byte (buf
, (value
& 0xff));
771 unpack_int (buf
, value
)
775 *value
= stub_unpack_int (buf
, 8);
779 #if 0 /* currently unused, uncomment when needed */
780 static char *pack_string
PARAMS ((char *pkt
, char *string
));
783 pack_string (pkt
, string
)
790 len
= strlen (string
);
792 len
= 200; /* Bigger than most GDB packets, junk??? */
793 pkt
= pack_hex_byte (pkt
, len
);
797 if ((ch
== '\0') || (ch
== '#'))
798 ch
= '*'; /* Protect encapsulation */
803 #endif /* 0 (unused) */
806 unpack_string (src
, dest
, length
)
818 pack_threadid (pkt
, id
)
823 unsigned char *altid
;
825 altid
= (unsigned char *) id
;
826 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
828 pkt
= pack_hex_byte (pkt
, *altid
++);
834 unpack_threadid (inbuf
, id
)
839 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
842 altref
= (char *) id
;
844 while (inbuf
< limit
)
846 x
= stubhex (*inbuf
++);
847 y
= stubhex (*inbuf
++);
848 *altref
++ = (x
<< 4) | y
;
853 /* Externally, threadrefs are 64 bits but internally, they are still
854 ints. This is due to a mismatch of specifications. We would like
855 to use 64bit thread references internally. This is an adapter
859 int_to_threadref (id
, value
)
865 scan
= (unsigned char *) id
;
871 *scan
++ = (value
>> 24) & 0xff;
872 *scan
++ = (value
>> 16) & 0xff;
873 *scan
++ = (value
>> 8) & 0xff;
874 *scan
++ = (value
& 0xff);
878 threadref_to_int (ref
)
888 value
= (value
<< 8) | ((*scan
++) & 0xff);
893 copy_threadref (dest
, src
)
898 unsigned char *csrc
, *cdest
;
900 csrc
= (unsigned char *) src
;
901 cdest
= (unsigned char *) dest
;
908 threadmatch (dest
, src
)
912 /* things are broken right now, so just assume we got a match */
914 unsigned char *srcp
, *destp
;
917 destp
= (char *) dest
;
921 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
928 threadid:1, # always request threadid
935 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
938 pack_threadinfo_request (pkt
, mode
, id
)
943 *pkt
++ = 'q'; /* Info Query */
944 *pkt
++ = 'P'; /* process or thread info */
945 pkt
= pack_int (pkt
, mode
); /* mode */
946 pkt
= pack_threadid (pkt
, id
); /* threadid */
947 *pkt
= '\0'; /* terminate */
951 /* These values tag the fields in a thread info response packet */
952 /* Tagging the fields allows us to request specific fields and to
953 add more fields as time goes by */
955 #define TAG_THREADID 1 /* Echo the thread identifier */
956 #define TAG_EXISTS 2 /* Is this process defined enough to
957 fetch registers and its stack */
958 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
959 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
960 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
964 remote_unpack_thread_info_response (pkt
, expectedref
, info
)
966 threadref
*expectedref
;
967 struct gdb_ext_thread_info
*info
;
972 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
975 /* info->threadid = 0; FIXME: implement zero_threadref */
977 info
->display
[0] = '\0';
978 info
->shortname
[0] = '\0';
979 info
->more_display
[0] = '\0';
981 /* Assume the characters indicating the packet type have been stripped */
982 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
983 pkt
= unpack_threadid (pkt
, &ref
);
986 warning ("Incomplete response to threadinfo request\n");
987 if (!threadmatch (&ref
, expectedref
))
988 { /* This is an answer to a different request */
989 warning ("ERROR RMT Thread info mismatch\n");
992 copy_threadref (&info
->threadid
, &ref
);
994 /* Loop on tagged fields , try to bail if somthing goes wrong */
996 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
998 pkt
= unpack_int (pkt
, &tag
); /* tag */
999 pkt
= unpack_byte (pkt
, &length
); /* length */
1000 if (!(tag
& mask
)) /* tags out of synch with mask */
1002 warning ("ERROR RMT: threadinfo tag mismatch\n");
1006 if (tag
== TAG_THREADID
)
1010 warning ("ERROR RMT: length of threadid is not 16\n");
1014 pkt
= unpack_threadid (pkt
, &ref
);
1015 mask
= mask
& ~TAG_THREADID
;
1018 if (tag
== TAG_EXISTS
)
1020 info
->active
= stub_unpack_int (pkt
, length
);
1022 mask
= mask
& ~(TAG_EXISTS
);
1025 warning ("ERROR RMT: 'exists' length too long\n");
1031 if (tag
== TAG_THREADNAME
)
1033 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1034 mask
= mask
& ~TAG_THREADNAME
;
1037 if (tag
== TAG_DISPLAY
)
1039 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1040 mask
= mask
& ~TAG_DISPLAY
;
1043 if (tag
== TAG_MOREDISPLAY
)
1045 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1046 mask
= mask
& ~TAG_MOREDISPLAY
;
1049 warning ("ERROR RMT: unknown thread info tag\n");
1050 break; /* Not a tag we know about */
1056 remote_get_threadinfo (threadid
, fieldset
, info
)
1057 threadref
*threadid
;
1058 int fieldset
; /* TAG mask */
1059 struct gdb_ext_thread_info
*info
;
1062 char threadinfo_pkt
[PBUFSIZ
];
1064 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1065 putpkt (threadinfo_pkt
);
1066 getpkt (threadinfo_pkt
, 0);
1067 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1072 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1073 representation of a threadid. */
1076 adapt_remote_get_threadinfo (ref
, selection
, info
)
1079 struct gdb_ext_thread_info
*info
;
1083 int_to_threadref (&lclref
, *ref
);
1084 return remote_get_threadinfo (&lclref
, selection
, info
);
1087 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1090 pack_threadlist_request (pkt
, startflag
, threadcount
, nextthread
)
1094 threadref
*nextthread
;
1096 *pkt
++ = 'q'; /* info query packet */
1097 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1098 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1099 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1100 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1105 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1108 parse_threadlist_response (pkt
, result_limit
, original_echo
, resultlist
,
1112 threadref
*original_echo
;
1113 threadref
*resultlist
;
1117 int count
, resultcount
, done
;
1120 /* Assume the 'q' and 'M chars have been stripped. */
1121 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1122 pkt
= unpack_byte (pkt
, &count
); /* count field */
1123 pkt
= unpack_nibble (pkt
, &done
);
1124 /* The first threadid is the argument threadid. */
1125 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1126 while ((count
-- > 0) && (pkt
< limit
))
1128 pkt
= unpack_threadid (pkt
, resultlist
++);
1129 if (resultcount
++ >= result_limit
)
1138 remote_get_threadlist (startflag
, nextthread
, result_limit
,
1139 done
, result_count
, threadlist
)
1141 threadref
*nextthread
;
1145 threadref
*threadlist
;
1148 static threadref echo_nextthread
;
1149 char threadlist_packet
[PBUFSIZ
];
1150 char t_response
[PBUFSIZ
];
1153 /* Trancate result limit to be smaller than the packet size */
1154 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1155 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1157 pack_threadlist_request (threadlist_packet
,
1158 startflag
, result_limit
, nextthread
);
1159 putpkt (threadlist_packet
);
1160 getpkt (t_response
, 0);
1163 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1166 if (!threadmatch (&echo_nextthread
, nextthread
))
1168 /* FIXME: This is a good reason to drop the packet */
1169 /* Possably, there is a duplicate response */
1171 retransmit immediatly - race conditions
1172 retransmit after timeout - yes
1174 wait for packet, then exit
1176 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1177 return 0; /* I choose simply exiting */
1179 if (*result_count
<= 0)
1183 warning ("RMT ERROR : failed to get remote thread list\n");
1186 return result
; /* break; */
1188 if (*result_count
> result_limit
)
1191 warning ("RMT ERROR: threadlist response longer than requested\n");
1197 /* This is the interface between remote and threads, remotes upper interface */
1199 /* remote_find_new_threads retrieves the thread list and for each
1200 thread in the list, looks up the thread in GDB's internal list,
1201 ading the thread if it does not already exist. This involves
1202 getting partial thread lists from the remote target so, polling the
1203 quit_flag is required. */
1206 /* About this many threadisds fit in a packet. */
1208 #define MAXTHREADLISTRESULTS 32
1211 remote_threadlist_iterator (stepfunction
, context
, looplimit
)
1212 rmt_thread_action stepfunction
;
1216 int done
, i
, result_count
;
1220 static threadref nextthread
;
1221 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1226 if (loopcount
++ > looplimit
)
1229 warning ("Remote fetch threadlist -infinite loop-\n");
1232 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1233 &done
, &result_count
, resultthreadlist
))
1238 /* clear for later iterations */
1240 /* Setup to resume next batch of thread references, set nextthread. */
1241 if (result_count
>= 1)
1242 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1244 while (result_count
--)
1245 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1252 remote_newthread_step (ref
, context
)
1258 pid
= threadref_to_int (ref
);
1259 if (!in_thread_list (pid
))
1261 return 1; /* continue iterator */
1264 #define CRAZY_MAX_THREADS 1000
1267 remote_current_thread (oldpid
)
1274 if (buf
[0] == 'Q' && buf
[1] == 'C')
1275 return strtol (&buf
[2], NULL
, 16);
1280 /* Find new threads for info threads command. */
1283 remote_find_new_threads ()
1285 remote_threadlist_iterator (remote_newthread_step
, 0,
1287 if (inferior_pid
== MAGIC_NULL_PID
) /* ack ack ack */
1288 inferior_pid
= remote_current_thread (inferior_pid
);
1292 remote_threads_info (void)
1294 char buf
[PBUFSIZ
], *bufp
;
1297 if (remote_desc
== 0) /* paranoia */
1298 error ("Command can only be used when connected to the remote target.");
1300 putpkt ("qfThreadInfo");
1301 getpkt (bufp
= buf
, 0);
1302 if (bufp
[0] == '\0') /* q packet not recognized! */
1303 { /* try old jmetzler method */
1304 remote_find_new_threads ();
1307 else /* try new 'q' method */
1308 while (*bufp
++ == 'm') /* reply contains one or more TID */
1311 tid
= strtol(bufp
, &bufp
, 16);
1312 if (tid
!= 0 && !in_thread_list (tid
))
1314 } while (*bufp
++ == ','); /* comma-separated list */
1315 putpkt ("qsThreadInfo");
1316 getpkt (bufp
= buf
, 0);
1321 /* Restart the remote side; this is an extended protocol operation. */
1324 extended_remote_restart ()
1328 /* Send the restart command; for reasons I don't understand the
1329 remote side really expects a number after the "R". */
1331 sprintf (&buf
[1], "%x", 0);
1334 /* Now query for status so this looks just like we restarted
1335 gdbserver from scratch. */
1340 /* Clean up connection to a remote debugger. */
1344 remote_close (quitting
)
1348 SERIAL_CLOSE (remote_desc
);
1352 /* Query the remote side for the text, data and bss offsets. */
1357 char buf
[PBUFSIZ
], *ptr
;
1359 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1360 struct section_offsets
*offs
;
1362 putpkt ("qOffsets");
1366 if (buf
[0] == '\000')
1367 return; /* Return silently. Stub doesn't support
1371 warning ("Remote failure reply: %s", buf
);
1375 /* Pick up each field in turn. This used to be done with scanf, but
1376 scanf will make trouble if CORE_ADDR size doesn't match
1377 conversion directives correctly. The following code will work
1378 with any size of CORE_ADDR. */
1379 text_addr
= data_addr
= bss_addr
= 0;
1383 if (strncmp (ptr
, "Text=", 5) == 0)
1386 /* Don't use strtol, could lose on big values. */
1387 while (*ptr
&& *ptr
!= ';')
1388 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1393 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1396 while (*ptr
&& *ptr
!= ';')
1397 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1402 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1405 while (*ptr
&& *ptr
!= ';')
1406 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1412 error ("Malformed response to offset query, %s", buf
);
1414 if (symfile_objfile
== NULL
)
1417 offs
= (struct section_offsets
*) alloca (sizeof (struct section_offsets
)
1418 + symfile_objfile
->num_sections
1419 * sizeof (offs
->offsets
));
1420 memcpy (offs
, symfile_objfile
->section_offsets
,
1421 sizeof (struct section_offsets
)
1422 + symfile_objfile
->num_sections
1423 * sizeof (offs
->offsets
));
1425 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
1427 /* This is a temporary kludge to force data and bss to use the same offsets
1428 because that's what nlmconv does now. The real solution requires changes
1429 to the stub and remote.c that I don't have time to do right now. */
1431 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
1432 ANOFFSET (offs
, SECT_OFF_BSS
) = data_addr
;
1434 objfile_relocate (symfile_objfile
, offs
);
1438 * Cisco version of section offsets:
1440 * Instead of having GDB query the target for the section offsets,
1441 * Cisco lets the target volunteer the information! It's also in
1442 * a different format, so here are the functions that will decode
1443 * a section offset packet from a Cisco target.
1447 * Function: remote_cisco_section_offsets
1449 * Returns: zero for success, non-zero for failure
1453 remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
1454 text_offs
, data_offs
, bss_offs
)
1458 bfd_signed_vma
* text_offs
;
1459 bfd_signed_vma
* data_offs
;
1460 bfd_signed_vma
* bss_offs
;
1462 bfd_vma text_base
, data_base
, bss_base
;
1463 struct minimal_symbol
*start
;
1469 if (symfile_objfile
== NULL
)
1470 return -1; /* no can do nothin' */
1472 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
1474 return -1; /* Can't find "_start" symbol */
1476 data_base
= bss_base
= 0;
1477 text_base
= SYMBOL_VALUE_ADDRESS (start
);
1479 abfd
= symfile_objfile
->obfd
;
1480 for (sect
= abfd
->sections
;
1484 p
= (unsigned char *) bfd_get_section_name (abfd
, sect
);
1486 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
1487 if (data_base
== 0 ||
1488 data_base
> bfd_get_section_vma (abfd
, sect
))
1489 data_base
= bfd_get_section_vma (abfd
, sect
);
1490 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
1491 if (bss_base
== 0 ||
1492 bss_base
> bfd_get_section_vma (abfd
, sect
))
1493 bss_base
= bfd_get_section_vma (abfd
, sect
);
1495 *text_offs
= text_addr
- text_base
;
1496 *data_offs
= data_addr
- data_base
;
1497 *bss_offs
= bss_addr
- bss_base
;
1502 sprintf (tmp
, "VMA: text = 0x");
1503 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
1504 sprintf (tmp
+ strlen (tmp
), " data = 0x");
1505 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
1506 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
1507 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
1508 fprintf_filtered (gdb_stdlog
, tmp
);
1509 fprintf_filtered (gdb_stdlog
,
1510 "Reloc offset: text = 0x%x data = 0x%x bss = 0x%x\n",
1511 (long) *text_offs
, (long) *data_offs
, (long) *bss_offs
);
1518 * Function: remote_cisco_objfile_relocate
1520 * Relocate the symbol file for a remote target.
1524 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
)
1525 bfd_signed_vma text_off
;
1526 bfd_signed_vma data_off
;
1527 bfd_signed_vma bss_off
;
1529 struct section_offsets
*offs
;
1531 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
1533 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1534 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1535 simple canonical representation for this stuff. */
1537 offs
= ((struct section_offsets
*)
1538 alloca (sizeof (struct section_offsets
)
1539 + (symfile_objfile
->num_sections
1540 * sizeof (offs
->offsets
))));
1542 memcpy (offs
, symfile_objfile
->section_offsets
,
1543 (sizeof (struct section_offsets
)
1544 + (symfile_objfile
->num_sections
1545 * sizeof (offs
->offsets
))));
1547 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_off
;
1548 ANOFFSET (offs
, SECT_OFF_DATA
) = data_off
;
1549 ANOFFSET (offs
, SECT_OFF_BSS
) = bss_off
;
1551 /* First call the standard objfile_relocate. */
1552 objfile_relocate (symfile_objfile
, offs
);
1554 /* Now we need to fix up the section entries already attached to
1555 the exec target. These entries will control memory transfers
1556 from the exec file. */
1558 exec_set_section_offsets (text_off
, data_off
, bss_off
);
1562 /* Stub for catch_errors. */
1565 remote_start_remote_dummy (dummy
)
1568 start_remote (); /* Initialize gdb process mechanisms */
1573 remote_start_remote (dummy
)
1576 immediate_quit
= 1; /* Allow user to interrupt it */
1578 /* Ack any packet which the remote side has already sent. */
1579 SERIAL_WRITE (remote_desc
, "+", 1);
1581 /* Let the stub know that we want it to return the thread. */
1584 inferior_pid
= remote_current_thread (inferior_pid
);
1586 get_offsets (); /* Get text, data & bss offsets */
1588 putpkt ("?"); /* initiate a query from remote machine */
1591 return remote_start_remote_dummy (dummy
);
1594 /* Open a connection to a remote debugger.
1595 NAME is the filename used for communication. */
1598 remote_open (name
, from_tty
)
1602 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
1605 /* Open a connection to a remote debugger using the extended
1606 remote gdb protocol. NAME is the filename used for communication. */
1609 extended_remote_open (name
, from_tty
)
1613 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1/*extended_p*/);
1616 /* Generic code for opening a connection to a remote target. */
1618 static DCACHE
*remote_dcache
;
1621 remote_open_1 (name
, from_tty
, target
, extended_p
)
1624 struct target_ops
*target
;
1628 error ("To open a remote debug connection, you need to specify what\n\
1629 serial device is attached to the remote system (e.g. /dev/ttya).");
1631 target_preopen (from_tty
);
1633 unpush_target (target
);
1635 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1637 remote_desc
= SERIAL_OPEN (name
);
1639 perror_with_name (name
);
1641 if (baud_rate
!= -1)
1643 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1645 SERIAL_CLOSE (remote_desc
);
1646 perror_with_name (name
);
1651 SERIAL_RAW (remote_desc
);
1653 /* If there is something sitting in the buffer we might take it as a
1654 response to a command, which would be bad. */
1655 SERIAL_FLUSH_INPUT (remote_desc
);
1659 puts_filtered ("Remote debugging using ");
1660 puts_filtered (name
);
1661 puts_filtered ("\n");
1663 push_target (target
); /* Switch to using remote target now */
1665 /* Start out by trying the 'P' request to set registers. We set
1666 this each time that we open a new target so that if the user
1667 switches from one stub to another, we can (if the target is
1668 closed and reopened) cope. */
1669 stub_supports_P
= 1;
1671 general_thread
= -2;
1672 continue_thread
= -2;
1674 /* Force remote_write_bytes to check whether target supports
1675 binary downloading. */
1676 remote_binary_checked
= 0;
1678 /* Without this, some commands which require an active target (such
1679 as kill) won't work. This variable serves (at least) double duty
1680 as both the pid of the target process (if it has such), and as a
1681 flag indicating that a target is active. These functions should
1682 be split out into seperate variables, especially since GDB will
1683 someday have a notion of debugging several processes. */
1685 inferior_pid
= MAGIC_NULL_PID
;
1686 /* Start the remote connection; if error (0), discard this target.
1687 In particular, if the user quits, be sure to discard it
1688 (we'd be in an inconsistent state otherwise). */
1689 if (!catch_errors (remote_start_remote
, NULL
,
1690 "Couldn't establish connection to remote target\n",
1699 /* tell the remote that we're using the extended protocol. */
1706 /* This takes a program previously attached to and detaches it. After
1707 this is done, GDB can be used to debug some other program. We
1708 better not have left any breakpoints in the target program or it'll
1709 die when it hits one. */
1712 remote_detach (args
, from_tty
)
1719 error ("Argument given to \"detach\" when remotely debugging.");
1721 /* Tell the remote target to detach. */
1727 puts_filtered ("Ending remote debugging.\n");
1730 /* Convert hex digit A to a number. */
1736 if (a
>= '0' && a
<= '9')
1738 else if (a
>= 'a' && a
<= 'f')
1739 return a
- 'a' + 10;
1740 else if (a
>= 'A' && a
<= 'F')
1741 return a
- 'A' + 10;
1743 error ("Reply contains invalid hex digit %d", a
);
1746 /* Convert number NIB to a hex digit. */
1758 /* Tell the remote machine to resume. */
1760 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
1762 static int last_sent_step
;
1765 remote_resume (pid
, step
, siggnal
)
1767 enum target_signal siggnal
;
1772 set_thread (0, 0); /* run any thread */
1774 set_thread (pid
, 0); /* run this thread */
1776 dcache_flush (remote_dcache
);
1778 last_sent_signal
= siggnal
;
1779 last_sent_step
= step
;
1781 /* A hook for when we need to do something at the last moment before
1783 if (target_resume_hook
)
1784 (*target_resume_hook
) ();
1786 if (siggnal
!= TARGET_SIGNAL_0
)
1788 buf
[0] = step
? 'S' : 'C';
1789 buf
[1] = tohex (((int)siggnal
>> 4) & 0xf);
1790 buf
[2] = tohex ((int)siggnal
& 0xf);
1794 strcpy (buf
, step
? "s": "c");
1799 /* Send ^C to target to halt it. Target will respond, and send us a
1802 static void (*ofunc
) PARAMS ((int));
1804 /* The command line interface's stop routine. This function is installed
1805 as a signal handler for SIGINT. The first time a user requests a
1806 stop, we call remote_stop to send a break or ^C. If there is no
1807 response from the target (it didn't stop when the user requested it),
1808 we ask the user if he'd like to detach from the target. */
1810 remote_interrupt (signo
)
1813 /* If this doesn't work, try more severe steps. */
1814 signal (signo
, remote_interrupt_twice
);
1817 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
1822 /* The user typed ^C twice. */
1825 remote_interrupt_twice (signo
)
1828 signal (signo
, ofunc
);
1830 signal (signo
, remote_interrupt
);
1833 /* This is the generic stop called via the target vector. When a target
1834 interrupt is requested, either by the command line or the GUI, we
1835 will eventually end up here. */
1839 /* Send a break or a ^C, depending on user preference. */
1841 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
1844 SERIAL_SEND_BREAK (remote_desc
);
1846 SERIAL_WRITE (remote_desc
, "\003", 1);
1849 /* Ask the user what to do when an interrupt is received. */
1854 target_terminal_ours ();
1856 if (query ("Interrupted while waiting for the program.\n\
1857 Give up (and stop debugging it)? "))
1859 target_mourn_inferior ();
1860 return_to_top_level (RETURN_QUIT
);
1863 target_terminal_inferior ();
1866 /* If nonzero, ignore the next kill. */
1871 remote_console_output (msg
)
1876 for (p
= msg
; *p
; p
+=2)
1879 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
1882 if (target_output_hook
)
1883 target_output_hook (tb
);
1885 fputs_filtered (tb
, gdb_stdout
);
1889 /* Wait until the remote machine stops, then return,
1890 storing status in STATUS just as `wait' would.
1891 Returns "pid", which in the case of a multi-threaded
1892 remote OS, is the thread-id. */
1895 remote_wait (pid
, status
)
1897 struct target_waitstatus
*status
;
1899 unsigned char buf
[PBUFSIZ
];
1900 int thread_num
= -1;
1902 status
->kind
= TARGET_WAITKIND_EXITED
;
1903 status
->value
.integer
= 0;
1909 ofunc
= signal (SIGINT
, remote_interrupt
);
1910 getpkt ((char *) buf
, 1);
1911 signal (SIGINT
, ofunc
);
1913 /* This is a hook for when we need to do something (perhaps the
1914 collection of trace data) every time the target stops. */
1915 if (target_wait_loop_hook
)
1916 (*target_wait_loop_hook
) ();
1920 case 'E': /* Error of some sort */
1921 warning ("Remote failure reply: %s", buf
);
1923 case 'T': /* Status with PC, SP, FP, ... */
1927 char regs
[MAX_REGISTER_RAW_SIZE
];
1929 /* Expedited reply, containing Signal, {regno, reg} repeat */
1930 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
1932 n... = register number
1933 r... = register contents
1935 p
= &buf
[3]; /* after Txx */
1942 /* Read the register number */
1943 regno
= strtol ((const char *) p
, &p_temp
, 16);
1944 p1
= (unsigned char *)p_temp
;
1946 if (p1
== p
) /* No register number present here */
1948 p1
= (unsigned char *) strchr ((const char *) p
, ':');
1950 warning ("Malformed packet(a) (missing colon): %s\n\
1953 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
1955 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
1956 record_currthread (thread_num
);
1957 p
= (unsigned char *) p_temp
;
1965 warning ("Malformed packet(b) (missing colon): %s\n\
1969 if (regno
>= NUM_REGS
)
1970 warning ("Remote sent bad register number %ld: %s\n\
1974 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
1976 if (p
[0] == 0 || p
[1] == 0)
1977 warning ("Remote reply is too short: %s", buf
);
1978 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
1981 supply_register (regno
, regs
);
1986 warning ("Remote register badly formatted: %s", buf
);
1987 warning (" here: %s",p
);
1992 case 'S': /* Old style status, just signal only */
1993 status
->kind
= TARGET_WAITKIND_STOPPED
;
1994 status
->value
.sig
= (enum target_signal
)
1995 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
1999 /* Export Cisco kernel mode as a convenience variable
2000 (so that it can be used in the GDB prompt if desired). */
2002 if (cisco_kernel_mode
== 1)
2003 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2004 value_from_string ("PDEBUG-"));
2005 cisco_kernel_mode
= 0;
2006 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2007 record_currthread (thread_num
);
2009 else if (buf
[3] == 'k')
2011 /* Export Cisco kernel mode as a convenience variable
2012 (so that it can be used in the GDB prompt if desired). */
2014 if (cisco_kernel_mode
== 1)
2015 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2016 value_from_string ("KDEBUG-"));
2017 cisco_kernel_mode
= 1;
2020 case 'N': /* Cisco special: status and offsets */
2022 bfd_vma text_addr
, data_addr
, bss_addr
;
2023 bfd_signed_vma text_off
, data_off
, bss_off
;
2026 status
->kind
= TARGET_WAITKIND_STOPPED
;
2027 status
->value
.sig
= (enum target_signal
)
2028 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2030 if (symfile_objfile
== NULL
)
2032 warning ("Relocation packet recieved with no symbol file. \
2037 /* Relocate object file. Buffer format is NAATT;DD;BB
2038 * where AA is the signal number, TT is the new text
2039 * address, DD * is the new data address, and BB is the
2040 * new bss address. */
2043 text_addr
= strtoul (p
, (char **) &p1
, 16);
2044 if (p1
== p
|| *p1
!= ';')
2045 warning ("Malformed relocation packet: Packet '%s'", buf
);
2047 data_addr
= strtoul (p
, (char **) &p1
, 16);
2048 if (p1
== p
|| *p1
!= ';')
2049 warning ("Malformed relocation packet: Packet '%s'", buf
);
2051 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2053 warning ("Malformed relocation packet: Packet '%s'", buf
);
2055 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2056 &text_off
, &data_off
, &bss_off
)
2058 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2059 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2063 case 'W': /* Target exited */
2065 /* The remote process exited. */
2066 status
->kind
= TARGET_WAITKIND_EXITED
;
2067 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2071 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2072 status
->value
.sig
= (enum target_signal
)
2073 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2077 case 'O': /* Console output */
2078 remote_console_output (buf
+ 1);
2081 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2083 /* Zero length reply means that we tried 'S' or 'C' and
2084 the remote system doesn't support it. */
2085 target_terminal_ours_for_output ();
2087 ("Can't send signals to this remote system. %s not sent.\n",
2088 target_signal_to_name (last_sent_signal
));
2089 last_sent_signal
= TARGET_SIGNAL_0
;
2090 target_terminal_inferior ();
2092 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2093 putpkt ((char *) buf
);
2096 /* else fallthrough */
2098 warning ("Invalid remote reply: %s", buf
);
2103 if (thread_num
!= -1)
2107 return inferior_pid
;
2110 /* Number of bytes of registers this stub implements. */
2112 static int register_bytes_found
;
2114 /* Read the remote registers into the block REGS. */
2115 /* Currently we just read all the registers, so we don't use regno. */
2119 remote_fetch_registers (regno
)
2125 char regs
[REGISTER_BYTES
];
2127 set_thread (inferior_pid
, 1);
2132 if (remote_register_buf_size
== 0)
2133 remote_register_buf_size
= strlen (buf
);
2135 /* Unimplemented registers read as all bits zero. */
2136 memset (regs
, 0, REGISTER_BYTES
);
2138 /* We can get out of synch in various cases. If the first character
2139 in the buffer is not a hex character, assume that has happened
2140 and try to fetch another packet to read. */
2141 while ((buf
[0] < '0' || buf
[0] > '9')
2142 && (buf
[0] < 'a' || buf
[0] > 'f')
2143 && buf
[0] != 'x') /* New: unavailable register value */
2146 fprintf_unfiltered (gdb_stdlog
,
2147 "Bad register packet; fetching a new packet\n");
2151 /* Reply describes registers byte by byte, each byte encoded as two
2152 hex characters. Suck them all up, then supply them to the
2153 register cacheing/storage mechanism. */
2156 for (i
= 0; i
< REGISTER_BYTES
; i
++)
2162 warning ("Remote reply is of odd length: %s", buf
);
2163 /* Don't change register_bytes_found in this case, and don't
2164 print a second warning. */
2167 if (p
[0] == 'x' && p
[1] == 'x')
2168 regs
[i
] = 0; /* 'x' */
2170 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2174 if (i
!= register_bytes_found
)
2176 register_bytes_found
= i
;
2177 #ifdef REGISTER_BYTES_OK
2178 if (!REGISTER_BYTES_OK (i
))
2179 warning ("Remote reply is too short: %s", buf
);
2184 for (i
= 0; i
< NUM_REGS
; i
++)
2186 supply_register (i
, ®s
[REGISTER_BYTE(i
)]);
2187 if (buf
[REGISTER_BYTE(i
) * 2] == 'x')
2188 register_valid
[i
] = -1; /* register value not available */
2192 /* Prepare to store registers. Since we may send them all (using a
2193 'G' request), we have to read out the ones we don't want to change
2197 remote_prepare_to_store ()
2199 /* Make sure the entire registers array is valid. */
2200 read_register_bytes (0, (char *)NULL
, REGISTER_BYTES
);
2203 /* Store register REGNO, or all registers if REGNO == -1, from the contents
2204 of REGISTERS. FIXME: ignores errors. */
2207 remote_store_registers (regno
)
2214 set_thread (inferior_pid
, 1);
2216 if (regno
>= 0 && stub_supports_P
)
2218 /* Try storing a single register. */
2221 sprintf (buf
, "P%x=", regno
);
2222 p
= buf
+ strlen (buf
);
2223 regp
= ®isters
[REGISTER_BYTE (regno
)];
2224 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
2226 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
2227 *p
++ = tohex (regp
[i
] & 0xf);
2233 /* The stub understands the 'P' request. We are done. */
2237 /* The stub does not support the 'P' request. Use 'G' instead,
2238 and don't try using 'P' in the future (it will just waste our
2240 stub_supports_P
= 0;
2245 /* Command describes registers byte by byte,
2246 each byte encoded as two hex characters. */
2249 /* remote_prepare_to_store insures that register_bytes_found gets set. */
2250 for (i
= 0; i
< register_bytes_found
; i
++)
2252 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
2253 *p
++ = tohex (registers
[i
] & 0xf);
2260 /* Use of the data cache *used* to be disabled because it loses for looking
2261 at and changing hardware I/O ports and the like. Accepting `volatile'
2262 would perhaps be one way to fix it. Another idea would be to use the
2263 executable file for the text segment (for all SEC_CODE sections?
2264 For all SEC_READONLY sections?). This has problems if you want to
2265 actually see what the memory contains (e.g. self-modifying code,
2266 clobbered memory, user downloaded the wrong thing).
2268 Because it speeds so much up, it's now enabled, if you're playing
2269 with registers you turn it of (set remotecache 0). */
2271 /* Read a word from remote address ADDR and return it.
2272 This goes through the data cache. */
2276 remote_fetch_word (addr
)
2279 return dcache_fetch (remote_dcache
, addr
);
2282 /* Write a word WORD into remote address ADDR.
2283 This goes through the data cache. */
2286 remote_store_word (addr
, word
)
2290 dcache_poke (remote_dcache
, addr
, word
);
2292 #endif /* 0 (unused?) */
2296 /* Return the number of hex digits in num. */
2304 for (i
= 0; num
!= 0; i
++)
2310 /* Set BUF to the hex digits representing NUM. */
2313 hexnumstr (buf
, num
)
2318 int len
= hexnumlen (num
);
2322 for (i
= len
- 1; i
>= 0; i
--)
2324 buf
[i
] = "0123456789abcdef" [(num
& 0xf)];
2331 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
2334 remote_address_masked (addr
)
2337 if (remote_address_size
> 0
2338 && remote_address_size
< (sizeof (ULONGEST
) * 8))
2340 /* Only create a mask when that mask can safely be constructed
2341 in a ULONGEST variable. */
2343 mask
= (mask
<< remote_address_size
) - 1;
2349 /* Determine whether the remote target supports binary downloading.
2350 This is accomplished by sending a no-op memory write of zero length
2351 to the target at the specified address. It does not suffice to send
2352 the whole packet, since many stubs strip the eighth bit and subsequently
2353 compute a wrong checksum, which causes real havoc with remote_write_bytes.
2355 NOTE: This can still lose if the serial line is not eight-bit clean. In
2356 cases like this, the user should clear "remotebinarydownload". */
2358 check_binary_download (addr
)
2361 if (remote_binary_download
&& !remote_binary_checked
)
2363 char buf
[PBUFSIZ
], *p
;
2364 remote_binary_checked
= 1;
2368 p
+= hexnumstr (p
, (ULONGEST
) addr
);
2370 p
+= hexnumstr (p
, (ULONGEST
) 0);
2374 putpkt_binary (buf
, (int) (p
- buf
));
2378 remote_binary_download
= 0;
2383 if (remote_binary_download
)
2384 fprintf_unfiltered (gdb_stdlog
,
2385 "binary downloading suppported by target\n");
2387 fprintf_unfiltered (gdb_stdlog
,
2388 "binary downloading NOT suppported by target\n");
2392 /* Write memory data directly to the remote machine.
2393 This does not inform the data cache; the data cache uses this.
2394 MEMADDR is the address in the remote memory space.
2395 MYADDR is the address of the buffer in our space.
2396 LEN is the number of bytes.
2398 Returns number of bytes transferred, or 0 for error. */
2401 remote_write_bytes (memaddr
, myaddr
, len
)
2406 int max_buf_size
; /* Max size of packet output buffer */
2409 /* Verify that the target can support a binary download */
2410 check_binary_download (memaddr
);
2412 /* Chop the transfer down if necessary */
2414 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
2415 if (remote_register_buf_size
!= 0)
2416 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
2418 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
2419 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
2424 unsigned char buf
[PBUFSIZ
];
2425 unsigned char *p
, *plen
;
2429 /* construct "M"<memaddr>","<len>":" */
2430 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
2431 memaddr
= remote_address_masked (memaddr
);
2433 if (remote_binary_download
)
2436 todo
= min (len
, max_buf_size
);
2441 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
2444 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
2447 plen
= p
; /* remember where len field goes */
2448 p
+= hexnumstr (p
, (ULONGEST
) todo
);
2452 /* We send target system values byte by byte, in increasing byte
2453 addresses, each byte encoded as two hex characters (or one
2454 binary character). */
2455 if (remote_binary_download
)
2459 (i
< todo
) && (i
+ escaped
) < (max_buf_size
- 2);
2462 switch (myaddr
[i
] & 0xff)
2467 /* These must be escaped */
2470 *p
++ = (myaddr
[i
] & 0xff) ^ 0x20;
2473 *p
++ = myaddr
[i
] & 0xff;
2480 /* Escape chars have filled up the buffer prematurely,
2481 and we have actually sent fewer bytes than planned.
2482 Fix-up the length field of the packet. */
2484 /* FIXME: will fail if new len is a shorter string than
2487 plen
+= hexnumstr (plen
, (ULONGEST
) i
);
2493 for (i
= 0; i
< todo
; i
++)
2495 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
2496 *p
++ = tohex (myaddr
[i
] & 0xf);
2501 putpkt_binary (buf
, (int) (p
- buf
));
2506 /* There is no correspondance between what the remote protocol uses
2507 for errors and errno codes. We would like a cleaner way of
2508 representing errors (big enough to include errno codes, bfd_error
2509 codes, and others). But for now just return EIO. */
2514 /* Increment by i, not by todo, in case escape chars
2515 caused us to send fewer bytes than we'd planned. */
2523 /* Read memory data directly from the remote machine.
2524 This does not use the data cache; the data cache uses this.
2525 MEMADDR is the address in the remote memory space.
2526 MYADDR is the address of the buffer in our space.
2527 LEN is the number of bytes.
2529 Returns number of bytes transferred, or 0 for error. */
2532 remote_read_bytes (memaddr
, myaddr
, len
)
2537 int max_buf_size
; /* Max size of packet output buffer */
2540 /* Chop the transfer down if necessary */
2542 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
2543 if (remote_register_buf_size
!= 0)
2544 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
2554 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
2556 /* construct "m"<memaddr>","<len>" */
2557 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
2558 memaddr
= remote_address_masked (memaddr
);
2561 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
2563 p
+= hexnumstr (p
, (ULONGEST
) todo
);
2571 /* There is no correspondance between what the remote protocol uses
2572 for errors and errno codes. We would like a cleaner way of
2573 representing errors (big enough to include errno codes, bfd_error
2574 codes, and others). But for now just return EIO. */
2579 /* Reply describes memory byte by byte,
2580 each byte encoded as two hex characters. */
2583 for (i
= 0; i
< todo
; i
++)
2585 if (p
[0] == 0 || p
[1] == 0)
2586 /* Reply is short. This means that we were able to read
2587 only part of what we wanted to. */
2588 return i
+ (origlen
- len
);
2589 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2599 /* Read or write LEN bytes from inferior memory at MEMADDR,
2600 transferring to or from debugger address BUFFER. Write to inferior if
2601 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
2604 #ifndef REMOTE_TRANSLATE_XFER_ADDRESS
2605 #define REMOTE_TRANSLATE_XFER_ADDRESS(MEM_ADDR, MEM_LEN, TARG_ADDR, TARG_LEN) \
2606 (*(TARG_ADDR) = (MEM_ADDR), *(TARG_LEN) = (MEM_LEN))
2611 remote_xfer_memory (mem_addr
, buffer
, mem_len
, should_write
, target
)
2616 struct target_ops
*target
; /* ignored */
2618 CORE_ADDR targ_addr
;
2620 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
2624 return dcache_xfer_memory (remote_dcache
, targ_addr
, buffer
,
2625 targ_len
, should_write
);
2630 /* Enable after 4.12. */
2633 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
2634 addr_found
, data_found
)
2638 CORE_ADDR startaddr
;
2642 CORE_ADDR
*addr_found
;
2645 if (increment
== -4 && len
== 4)
2647 long mask_long
, data_long
;
2648 long data_found_long
;
2649 CORE_ADDR addr_we_found
;
2651 long returned_long
[2];
2654 mask_long
= extract_unsigned_integer (mask
, len
);
2655 data_long
= extract_unsigned_integer (data
, len
);
2656 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
2661 /* The stub doesn't support the 't' request. We might want to
2662 remember this fact, but on the other hand the stub could be
2663 switched on us. Maybe we should remember it only until
2664 the next "target remote". */
2665 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
2666 hirange
, addr_found
, data_found
);
2671 /* There is no correspondance between what the remote protocol uses
2672 for errors and errno codes. We would like a cleaner way of
2673 representing errors (big enough to include errno codes, bfd_error
2674 codes, and others). But for now just use EIO. */
2675 memory_error (EIO
, startaddr
);
2678 while (*p
!= '\0' && *p
!= ',')
2679 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
2681 error ("Protocol error: short return for search");
2683 data_found_long
= 0;
2684 while (*p
!= '\0' && *p
!= ',')
2685 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
2686 /* Ignore anything after this comma, for future extensions. */
2688 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
2694 *addr_found
= addr_we_found
;
2695 *data_found
= store_unsigned_integer (data_we_found
, len
);
2698 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
2699 hirange
, addr_found
, data_found
);
2704 remote_files_info (ignore
)
2705 struct target_ops
*ignore
;
2707 puts_filtered ("Debugging a target over a serial line.\n");
2710 /* Stuff for dealing with the packets which are part of this protocol.
2711 See comment at top of file for details. */
2713 /* Read a single character from the remote end, masking it down to 7 bits. */
2721 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
2726 error ("Remote connection closed");
2728 perror_with_name ("Remote communication error");
2729 case SERIAL_TIMEOUT
:
2736 /* Send the command in BUF to the remote machine, and read the reply
2737 into BUF. Report an error if we get an error reply. */
2747 error ("Remote failure reply: %s", buf
);
2750 /* Display a null-terminated packet on stdout, for debugging, using C
2757 puts_filtered ("\"");
2759 gdb_printchar (*buf
++, gdb_stdout
, '"');
2760 puts_filtered ("\"");
2767 return putpkt_binary (buf
, strlen (buf
));
2770 /* Send a packet to the remote machine, with error checking. The data
2771 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
2772 to account for the $, # and checksum, and for a possible /0 if we are
2773 debugging (remote_debug) and want to print the sent packet as a string */
2776 putpkt_binary (buf
, cnt
)
2781 unsigned char csum
= 0;
2787 /* Copy the packet into buffer BUF2, encapsulating it
2788 and giving it a checksum. */
2790 if (cnt
> (int) sizeof (buf2
) - 5) /* Prosanity check */
2796 for (i
= 0; i
< cnt
; i
++)
2802 *p
++ = tohex ((csum
>> 4) & 0xf);
2803 *p
++ = tohex (csum
& 0xf);
2805 /* Send it over and over until we get a positive ack. */
2809 int started_error_output
= 0;
2814 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", buf2
);
2815 gdb_flush (gdb_stdlog
);
2817 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
2818 perror_with_name ("putpkt: write failed");
2820 /* read until either a timeout occurs (-2) or '+' is read */
2823 ch
= readchar (remote_timeout
);
2830 case SERIAL_TIMEOUT
:
2832 if (started_error_output
)
2834 putchar_unfiltered ('\n');
2835 started_error_output
= 0;
2844 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
2846 case SERIAL_TIMEOUT
:
2850 break; /* Retransmit buffer */
2853 char junkbuf
[PBUFSIZ
];
2855 /* It's probably an old response, and we're out of sync.
2856 Just gobble up the packet and ignore it. */
2857 getpkt (junkbuf
, 0);
2858 continue; /* Now, go look for + */
2863 if (!started_error_output
)
2865 started_error_output
= 1;
2866 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
2868 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
2872 break; /* Here to retransmit */
2876 /* This is wrong. If doing a long backtrace, the user should be
2877 able to get out next time we call QUIT, without anything as
2878 violent as interrupt_query. If we want to provide a way out of
2879 here without getting to the next QUIT, it should be based on
2880 hitting ^C twice as in remote_wait. */
2890 static int remote_cisco_mode
;
2892 static void remote_cisco_expand (src
, dest
)
2902 repeat
= (fromhex (src
[1]) << 4) + fromhex (src
[2]);
2903 for (i
= 0; i
< repeat
; i
++)
2916 /* Come here after finding the start of the frame. Collect the rest
2917 into BUF, verifying the checksum, length, and handling run-length
2918 compression. Returns 0 on any error, 1 on success. */
2933 c
= readchar (remote_timeout
);
2937 case SERIAL_TIMEOUT
:
2939 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
2943 fputs_filtered ("Saw new packet start in middle of old one\n",
2945 return 0; /* Start a new packet, count retries */
2948 unsigned char pktcsum
;
2952 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
2953 pktcsum
|= fromhex (readchar (remote_timeout
));
2955 if (csum
== pktcsum
)
2957 if (remote_cisco_mode
) /* variant run-length-encoding */
2959 char tmp_buf
[PBUFSIZ
];
2961 remote_cisco_expand (buf
, tmp_buf
);
2962 strcpy (buf
, tmp_buf
);
2969 fprintf_filtered (gdb_stdlog
,
2970 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
2972 fputs_filtered (buf
, gdb_stdlog
);
2973 fputs_filtered ("\n", gdb_stdlog
);
2977 case '*': /* Run length encoding */
2978 if (remote_cisco_mode
== 0) /* variant run-length-encoding */
2981 c
= readchar (remote_timeout
);
2983 c
= c
- ' ' + 3; /* Compute repeat count */
2985 if (c
> 0 && c
< 255 && bp
+ c
- 1 < buf
+ PBUFSIZ
- 1)
2987 memset (bp
, *(bp
- 1), c
);
2993 printf_filtered ("Repeat count %d too large for buffer: ", c
);
2994 puts_filtered (buf
);
2995 puts_filtered ("\n");
2998 /* else fall thru to treat like default */
3000 if (bp
< buf
+ PBUFSIZ
- 1)
3008 puts_filtered ("Remote packet too long: ");
3009 puts_filtered (buf
);
3010 puts_filtered ("\n");
3017 /* Read a packet from the remote machine, with error checking, and
3018 store it in BUF. BUF is expected to be of size PBUFSIZ. If
3019 FOREVER, wait forever rather than timing out; this is used while
3020 the target is executing user code. */
3023 getpkt (buf
, forever
)
3032 strcpy (buf
,"timeout");
3036 timeout
= watchdog
> 0 ? watchdog
: -1;
3040 timeout
= remote_timeout
;
3044 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
3046 /* This can loop forever if the remote side sends us characters
3047 continuously, but if it pauses, we'll get a zero from readchar
3048 because of timeout. Then we'll count that as a retry. */
3050 /* Note that we will only wait forever prior to the start of a packet.
3051 After that, we expect characters to arrive at a brisk pace. They
3052 should show up within remote_timeout intervals. */
3056 c
= readchar (timeout
);
3058 if (c
== SERIAL_TIMEOUT
)
3060 if (forever
) /* Watchdog went off. Kill the target. */
3062 target_mourn_inferior ();
3063 error ("Watchdog has expired. Target detached.\n");
3066 fputs_filtered ("Timed out.\n", gdb_stdlog
);
3072 /* We've found the start of a packet, now collect the data. */
3074 val
= read_frame (buf
);
3079 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", buf
);
3080 SERIAL_WRITE (remote_desc
, "+", 1);
3084 /* Try the whole thing again. */
3086 SERIAL_WRITE (remote_desc
, "-", 1);
3089 /* We have tried hard enough, and just can't receive the packet. Give up. */
3091 printf_unfiltered ("Ignoring packet error, continuing...\n");
3092 SERIAL_WRITE (remote_desc
, "+", 1);
3098 /* For some mysterious reason, wait_for_inferior calls kill instead of
3099 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3103 target_mourn_inferior ();
3107 /* Use catch_errors so the user can quit from gdb even when we aren't on
3108 speaking terms with the remote system. */
3109 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
3111 /* Don't wait for it to die. I'm not really sure it matters whether
3112 we do or not. For the existing stubs, kill is a noop. */
3113 target_mourn_inferior ();
3119 remote_mourn_1 (&remote_ops
);
3123 extended_remote_mourn ()
3125 /* We do _not_ want to mourn the target like this; this will
3126 remove the extended remote target from the target stack,
3127 and the next time the user says "run" it'll fail.
3129 FIXME: What is the right thing to do here? */
3131 remote_mourn_1 (&extended_remote_ops
);
3135 /* Worker function for remote_mourn. */
3137 remote_mourn_1 (target
)
3138 struct target_ops
*target
;
3140 unpush_target (target
);
3141 generic_mourn_inferior ();
3144 /* In the extended protocol we want to be able to do things like
3145 "run" and have them basically work as expected. So we need
3146 a special create_inferior function.
3148 FIXME: One day add support for changing the exec file
3149 we're debugging, arguments and an environment. */
3152 extended_remote_create_inferior (exec_file
, args
, env
)
3157 /* Rip out the breakpoints; we'll reinsert them after restarting
3158 the remote server. */
3159 remove_breakpoints ();
3161 /* Now restart the remote server. */
3162 extended_remote_restart ();
3164 /* Now put the breakpoints back in. This way we're safe if the
3165 restart function works via a unix fork on the remote side. */
3166 insert_breakpoints ();
3168 /* Clean up from the last time we were running. */
3169 clear_proceed_status ();
3171 /* Let the remote process run. */
3172 proceed (-1, TARGET_SIGNAL_0
, 0);
3176 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
3177 than other targets; in those use REMOTE_BREAKPOINT instead of just
3178 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
3179 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
3180 the standard routines that are in mem-break.c. */
3182 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
3183 the choice of breakpoint instruction affects target program design and
3184 vice versa, and by making it user-tweakable, the special code here
3185 goes away and we need fewer special GDB configurations. */
3187 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
3188 #define REMOTE_BREAKPOINT
3191 #ifdef REMOTE_BREAKPOINT
3193 /* If the target isn't bi-endian, just pretend it is. */
3194 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
3195 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3196 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3199 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
3200 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
3202 #endif /* REMOTE_BREAKPOINT */
3204 /* Insert a breakpoint on targets that don't have any better breakpoint
3205 support. We read the contents of the target location and stash it,
3206 then overwrite it with a breakpoint instruction. ADDR is the target
3207 location in the target machine. CONTENTS_CACHE is a pointer to
3208 memory allocated for saving the target contents. It is guaranteed
3209 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
3210 is accomplished via BREAKPOINT_MAX). */
3213 remote_insert_breakpoint (addr
, contents_cache
)
3215 char *contents_cache
;
3217 #ifdef REMOTE_BREAKPOINT
3220 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
3224 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
3225 val
= target_write_memory (addr
, (char *) big_break_insn
,
3226 sizeof big_break_insn
);
3228 val
= target_write_memory (addr
, (char *) little_break_insn
,
3229 sizeof little_break_insn
);
3234 return memory_insert_breakpoint (addr
, contents_cache
);
3235 #endif /* REMOTE_BREAKPOINT */
3239 remote_remove_breakpoint (addr
, contents_cache
)
3241 char *contents_cache
;
3243 #ifdef REMOTE_BREAKPOINT
3244 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
3246 return memory_remove_breakpoint (addr
, contents_cache
);
3247 #endif /* REMOTE_BREAKPOINT */
3250 /* Some targets are only capable of doing downloads, and afterwards
3251 they switch to the remote serial protocol. This function provides
3252 a clean way to get from the download target to the remote target.
3253 It's basically just a wrapper so that we don't have to expose any
3254 of the internal workings of remote.c.
3256 Prior to calling this routine, you should shutdown the current
3257 target code, else you will get the "A program is being debugged
3258 already..." message. Usually a call to pop_target() suffices. */
3261 push_remote_target (name
, from_tty
)
3265 printf_filtered ("Switching to remote protocol\n");
3266 remote_open (name
, from_tty
);
3269 /* Other targets want to use the entire remote serial module but with
3270 certain remote_ops overridden. */
3273 open_remote_target (name
, from_tty
, target
, extended_p
)
3276 struct target_ops
*target
;
3279 printf_filtered ("Selecting the %sremote protocol\n",
3280 (extended_p
? "extended-" : ""));
3281 remote_open_1 (name
, from_tty
, target
, extended_p
);
3284 /* Table used by the crc32 function to calcuate the checksum. */
3286 static unsigned long crc32_table
[256] = {0, 0};
3288 static unsigned long
3289 crc32 (buf
, len
, crc
)
3294 if (! crc32_table
[1])
3296 /* Initialize the CRC table and the decoding table. */
3300 for (i
= 0; i
< 256; i
++)
3302 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
3303 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
3310 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
3316 /* compare-sections command
3318 With no arguments, compares each loadable section in the exec bfd
3319 with the same memory range on the target, and reports mismatches.
3320 Useful for verifying the image on the target against the exec file.
3321 Depends on the target understanding the new "qCRC:" request. */
3324 compare_sections_command (args
, from_tty
)
3329 unsigned long host_crc
, target_crc
;
3330 extern bfd
*exec_bfd
;
3331 struct cleanup
*old_chain
;
3332 char *tmp
, *sectdata
, *sectname
, buf
[PBUFSIZ
];
3339 error ("command cannot be used without an exec file");
3340 if (!current_target
.to_shortname
||
3341 strcmp (current_target
.to_shortname
, "remote") != 0)
3342 error ("command can only be used with remote target");
3344 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
3346 if (!(s
->flags
& SEC_LOAD
))
3347 continue; /* skip non-loadable section */
3349 size
= bfd_get_section_size_before_reloc (s
);
3351 continue; /* skip zero-length section */
3353 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
3354 if (args
&& strcmp (args
, sectname
) != 0)
3355 continue; /* not the section selected by user */
3357 matched
= 1; /* do this section */
3359 /* FIXME: assumes lma can fit into long */
3360 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
3363 /* be clever; compute the host_crc before waiting for target reply */
3364 sectdata
= xmalloc (size
);
3365 old_chain
= make_cleanup (free
, sectdata
);
3366 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
3367 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
3371 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
3372 sectname
, lma
, lma
+ size
);
3374 error ("remote target does not support this operation");
3376 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
3377 target_crc
= target_crc
* 16 + fromhex (*tmp
);
3379 printf_filtered ("Section %s, range 0x%08x -- 0x%08x: ",
3380 sectname
, lma
, lma
+ size
);
3381 if (host_crc
== target_crc
)
3382 printf_filtered ("matched.\n");
3385 printf_filtered ("MIS-MATCHED!\n");
3389 do_cleanups (old_chain
);
3392 warning ("One or more sections of the remote executable does not match\n\
3393 the loaded file\n");
3394 if (args
&& !matched
)
3395 printf_filtered ("No loaded section named '%s'.\n", args
);
3399 remote_query (query_type
, buf
, outbuf
, bufsiz
)
3407 char *p2
= &buf2
[0];
3411 error ("null pointer to remote bufer size specified");
3413 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
3414 the caller know and return what the minimum size is */
3415 /* Note: a zero bufsiz can be used to query the minimum buffer size */
3416 if ( *bufsiz
< PBUFSIZ
)
3422 /* except for querying the minimum buffer size, target must be open */
3424 error ("remote query is only available after target open");
3426 /* we only take uppercase letters as query types, at least for now */
3427 if ( (query_type
< 'A') || (query_type
> 'Z') )
3428 error ("invalid remote query type");
3431 error ("null remote query specified");
3434 error ("remote query requires a buffer to receive data");
3441 /* we used one buffer char for the remote protocol q command and another
3442 for the query type. As the remote protocol encapsulation uses 4 chars
3443 plus one extra in case we are debugging (remote_debug),
3444 we have PBUFZIZ - 7 left to pack the query string */
3446 while ( buf
[i
] && (i
< (PBUFSIZ
- 8)) )
3448 /* bad caller may have sent forbidden characters */
3449 if ( (!isprint(buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#') )
3450 error ("illegal characters in query string");
3458 error ("query larger than available buffer");
3461 if ( i
< 0 ) return i
;
3469 packet_command (args
, from_tty
)
3476 error ("command can only be used with remote target");
3479 error ("remote-packet command requires packet text as argument");
3481 puts_filtered ("sending: ");
3482 print_packet (args
);
3483 puts_filtered ("\n");
3487 puts_filtered ("received: ");
3489 puts_filtered ("\n");
3493 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
3495 static void display_thread_info
PARAMS ((struct gdb_ext_thread_info
*info
));
3497 static void threadset_test_cmd
PARAMS ((char *cmd
, int tty
));
3499 static void threadalive_test
PARAMS ((char *cmd
, int tty
));
3501 static void threadlist_test_cmd
PARAMS ((char *cmd
, int tty
));
3503 int get_and_display_threadinfo
PARAMS ((threadref
*ref
));
3505 static void threadinfo_test_cmd
PARAMS ((char *cmd
, int tty
));
3507 static int thread_display_step
PARAMS ((threadref
*ref
, void *context
));
3509 static void threadlist_update_test_cmd
PARAMS ((char *cmd
, int tty
));
3511 static void init_remote_threadtests
PARAMS ((void));
3513 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
3516 threadset_test_cmd (cmd
, tty
)
3520 int sample_thread
= SAMPLE_THREAD
;
3522 printf_filtered ("Remote threadset test\n");
3523 set_thread (sample_thread
, 1);
3528 threadalive_test (cmd
, tty
)
3532 int sample_thread
= SAMPLE_THREAD
;
3534 if (remote_thread_alive (sample_thread
))
3535 printf_filtered ("PASS: Thread alive test\n");
3537 printf_filtered ("FAIL: Thread alive test\n");
3540 void output_threadid
PARAMS ((char *title
, threadref
* ref
));
3543 output_threadid (title
, ref
)
3549 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
3551 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
3555 threadlist_test_cmd (cmd
, tty
)
3560 threadref nextthread
;
3561 int done
, result_count
;
3562 threadref threadlist
[3];
3564 printf_filtered ("Remote Threadlist test\n");
3565 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
3566 &result_count
, &threadlist
[0]))
3567 printf_filtered ("FAIL: threadlist test\n");
3570 threadref
*scan
= threadlist
;
3571 threadref
*limit
= scan
+ result_count
;
3573 while (scan
< limit
)
3574 output_threadid (" thread ", scan
++);
3579 display_thread_info (info
)
3580 struct gdb_ext_thread_info
*info
;
3582 output_threadid ("Threadid: ", &info
->threadid
);
3583 printf_filtered ("Name: %s\n ", info
->shortname
);
3584 printf_filtered ("State: %s\n", info
->display
);
3585 printf_filtered ("other: %s\n\n", info
->more_display
);
3589 get_and_display_threadinfo (ref
)
3594 struct gdb_ext_thread_info threadinfo
;
3596 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3597 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3598 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
3599 display_thread_info (&threadinfo
);
3604 threadinfo_test_cmd (cmd
, tty
)
3608 int athread
= SAMPLE_THREAD
;
3612 int_to_threadref (&thread
, athread
);
3613 printf_filtered ("Remote Threadinfo test\n");
3614 if (!get_and_display_threadinfo (&thread
))
3615 printf_filtered ("FAIL cannot get thread info\n");
3619 thread_display_step (ref
, context
)
3623 /* output_threadid(" threadstep ",ref); *//* simple test */
3624 return get_and_display_threadinfo (ref
);
3628 threadlist_update_test_cmd (cmd
, tty
)
3632 printf_filtered ("Remote Threadlist update test\n");
3633 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
3637 init_remote_threadtests (void)
3639 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
3640 "Fetch and print the remote list of thread identifiers, one pkt only");
3641 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
3642 "Fetch and display info about one thread");
3643 add_com ("tset", class_obscure
, threadset_test_cmd
,
3644 "Test setting to a different thread");
3645 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
3646 "Iterate through updating all remote thread info");
3647 add_com ("talive", class_obscure
, threadalive_test
,
3648 " Remote thread alive test ");
3656 remote_ops
.to_shortname
= "remote";
3657 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
3659 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
3660 Specify the serial device it is connected to (e.g. /dev/ttya).";
3661 remote_ops
.to_open
= remote_open
;
3662 remote_ops
.to_close
= remote_close
;
3663 remote_ops
.to_detach
= remote_detach
;
3664 remote_ops
.to_resume
= remote_resume
;
3665 remote_ops
.to_wait
= remote_wait
;
3666 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
3667 remote_ops
.to_store_registers
= remote_store_registers
;
3668 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
3669 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
3670 remote_ops
.to_files_info
= remote_files_info
;
3671 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
3672 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
3673 remote_ops
.to_kill
= remote_kill
;
3674 remote_ops
.to_load
= generic_load
;
3675 remote_ops
.to_mourn_inferior
= remote_mourn
;
3676 remote_ops
.to_thread_alive
= remote_thread_alive
;
3677 remote_ops
.to_find_new_threads
= remote_threads_info
;
3678 remote_ops
.to_stop
= remote_stop
;
3679 remote_ops
.to_query
= remote_query
;
3680 remote_ops
.to_stratum
= process_stratum
;
3681 remote_ops
.to_has_all_memory
= 1;
3682 remote_ops
.to_has_memory
= 1;
3683 remote_ops
.to_has_stack
= 1;
3684 remote_ops
.to_has_registers
= 1;
3685 remote_ops
.to_has_execution
= 1;
3686 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
3687 remote_ops
.to_magic
= OPS_MAGIC
;
3690 /* Set up the extended remote vector by making a copy of the standard
3691 remote vector and adding to it. */
3694 init_extended_remote_ops ()
3696 extended_remote_ops
= remote_ops
;
3698 extended_remote_ops
.to_shortname
= "extended-remote";
3699 extended_remote_ops
.to_longname
=
3700 "Extended remote serial target in gdb-specific protocol";
3701 extended_remote_ops
.to_doc
=
3702 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
3703 Specify the serial device it is connected to (e.g. /dev/ttya).",
3704 extended_remote_ops
.to_open
= extended_remote_open
;
3705 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
3706 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
3710 * Command: info remote-process
3712 * This implements Cisco's version of the "info proc" command.
3714 * This query allows the target stub to return an arbitrary string
3715 * (or strings) giving arbitrary information about the target process.
3716 * This is optional; the target stub isn't required to implement it.
3718 * Syntax: qfProcessInfo request first string
3719 * qsProcessInfo request subsequent string
3720 * reply: 'O'<hex-encoded-string>
3721 * 'l' last reply (empty)
3725 remote_info_process (args
, from_tty
)
3731 if (remote_desc
== 0)
3732 error ("Command can only be used when connected to the remote target.");
3734 putpkt ("qfProcessInfo");
3737 return; /* Silently: target does not support this feature. */
3740 error ("info proc: target error.");
3742 while (buf
[0] == 'O') /* Capitol-O packet */
3744 remote_console_output (&buf
[1]);
3745 putpkt ("qsProcessInfo");
3755 remote_cisco_open (name
, from_tty
)
3761 "To open a remote debug connection, you need to specify what \n\
3762 device is attached to the remote system (e.g. host:port).");
3764 target_preopen (from_tty
);
3766 unpush_target (&remote_cisco_ops
);
3768 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
3770 remote_desc
= SERIAL_OPEN (name
);
3772 perror_with_name (name
);
3775 * If a baud rate was specified on the gdb command line it will
3776 * be greater than the initial value of -1. If it is, use it otherwise
3780 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
3781 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
3783 SERIAL_CLOSE (remote_desc
);
3784 perror_with_name (name
);
3787 SERIAL_RAW (remote_desc
);
3789 /* If there is something sitting in the buffer we might take it as a
3790 response to a command, which would be bad. */
3791 SERIAL_FLUSH_INPUT (remote_desc
);
3795 puts_filtered ("Remote debugging using ");
3796 puts_filtered (name
);
3797 puts_filtered ("\n");
3800 remote_cisco_mode
= 1;
3802 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
3804 /* Start out by trying the 'P' request to set registers. We set this each
3805 time that we open a new target so that if the user switches from one
3806 stub to another, we can (if the target is closed and reopened) cope. */
3807 stub_supports_P
= 1;
3809 general_thread
= -2;
3810 continue_thread
= -2;
3812 /* Force remote_write_bytes to check whether target supports
3813 binary downloading. */
3814 remote_binary_checked
= 0;
3816 /* Without this, some commands which require an active target (such
3817 as kill) won't work. This variable serves (at least) double duty
3818 as both the pid of the target process (if it has such), and as a
3819 flag indicating that a target is active. These functions should
3820 be split out into seperate variables, especially since GDB will
3821 someday have a notion of debugging several processes. */
3822 inferior_pid
= MAGIC_NULL_PID
;
3824 /* Start the remote connection; if error (0), discard this target. */
3826 if (!catch_errors (remote_start_remote_dummy
, (char *) 0,
3827 "Couldn't establish connection to remote target\n",
3836 remote_cisco_close (quitting
)
3839 remote_cisco_mode
= 0;
3840 remote_close (quitting
);
3844 remote_cisco_mourn
PARAMS ((void))
3846 remote_mourn_1 (&remote_cisco_ops
);
3854 } minitelnet_return
;
3856 /* shared between readsocket() and readtty() */
3857 static char *tty_input
;
3859 static int escape_count
;
3860 static int echo_check
;
3861 extern int quit_flag
;
3868 /* Loop until the socket doesn't have any more data */
3870 while ((data
= readchar (0)) >= 0)
3872 /* Check for the escape sequence */
3875 /* If this is the fourth escape, get out */
3876 if (++escape_count
== 4)
3881 { /* This is a '|', but not the fourth in a row.
3882 Continue without echoing it. If it isn't actually
3883 one of four in a row, it'll be echoed later. */
3887 else /* Not a '|' */
3889 /* Ensure any pending '|'s are flushed. */
3891 for ( ; escape_count
> 0; escape_count
--)
3895 if (data
== '\r') /* If this is a return character, */
3896 continue; /* - just supress it. */
3898 if (echo_check
!= -1) /* Check for echo of user input. */
3900 if (tty_input
[echo_check
] == data
)
3902 echo_check
++; /* Character matched user input: */
3903 continue; /* Continue without echoing it. */
3905 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
3906 { /* End of the line (and of echo checking). */
3907 echo_check
= -1; /* No more echo supression */
3908 continue; /* Continue without echoing. */
3911 { /* Failed check for echo of user input.
3912 We now have some suppressed output to flush! */
3915 for (j
= 0; j
< echo_check
; j
++)
3916 putchar (tty_input
[j
]);
3920 putchar (data
); /* Default case: output the char. */
3923 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
3924 return READ_MORE
; /* Try to read some more */
3926 return FATAL_ERROR
; /* Trouble, bail out */
3935 /* First, read a buffer full from the terminal */
3936 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
3937 if (tty_bytecount
== -1)
3939 perror ("readtty: read failed");
3943 /* Remove a quoted newline. */
3944 if (tty_input
[tty_bytecount
- 1] == '\n' &&
3945 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
3947 tty_input
[--tty_bytecount
] = 0; /* remove newline */
3948 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
3951 /* Turn trailing newlines into returns */
3952 if (tty_input
[tty_bytecount
- 1] == '\n')
3953 tty_input
[tty_bytecount
- 1] = '\r';
3955 /* If the line consists of a ~, enter debugging mode. */
3956 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
3959 /* Make this a zero terminated string and write it out */
3960 tty_input
[tty_bytecount
] = 0;
3961 if (SERIAL_WRITE (remote_desc
, tty_input
, tty_bytecount
))
3963 perror_with_name ("readtty: write failed");
3973 fd_set input
; /* file descriptors for select */
3974 int tablesize
; /* max number of FDs for select */
3978 extern int escape_count
; /* global shared by readsocket */
3979 extern int echo_check
; /* ditto */
3984 tablesize
= 8 * sizeof (input
);
3988 /* Check for anything from our socket - doesn't block. Note that
3989 this must be done *before* the select as there may be
3990 buffered I/O waiting to be processed. */
3992 if ((status
= readsocket ()) == FATAL_ERROR
)
3994 error ("Debugging terminated by communications error");
3996 else if (status
!= READ_MORE
)
4001 fflush(stdout
); /* Flush output before blocking */
4003 /* Now block on more socket input or TTY input */
4006 FD_SET (fileno(stdin
), &input
);
4007 FD_SET (remote_desc
->fd
, &input
);
4009 status
= select (tablesize
, &input
, 0, 0, 0);
4010 if ((status
== -1) && (errno
!= EINTR
))
4012 error ("Communications error on select %d", errno
);
4015 /* Handle Control-C typed */
4019 if ((++quit_count
) == 2)
4021 if (query ("Interrupt GDB? "))
4023 printf_filtered ("Interrupted by user.\n");
4024 return_to_top_level (RETURN_QUIT
);
4031 SERIAL_SEND_BREAK (remote_desc
);
4033 SERIAL_WRITE (remote_desc
, "\003", 1);
4038 /* Handle console input */
4040 if (FD_ISSET (fileno (stdin
), &input
))
4044 status
= readtty ();
4045 if (status
== READ_MORE
)
4048 return status
; /* telnet session ended */
4054 remote_cisco_wait (pid
, status
)
4056 struct target_waitstatus
*status
;
4058 if (minitelnet() != ENTER_DEBUG
)
4060 error ("Debugging session terminated by protocol error");
4063 return remote_wait (pid
, status
);
4067 init_remote_cisco_ops ()
4069 remote_cisco_ops
.to_shortname
= "cisco";
4070 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
4071 remote_cisco_ops
.to_doc
=
4072 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
4073 Specify the serial device it is connected to (e.g. host:2020).";
4074 remote_cisco_ops
.to_open
= remote_cisco_open
;
4075 remote_cisco_ops
.to_close
= remote_cisco_close
;
4076 remote_cisco_ops
.to_detach
= remote_detach
;
4077 remote_cisco_ops
.to_resume
= remote_resume
;
4078 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
4079 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
4080 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
4081 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
4082 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
4083 remote_cisco_ops
.to_files_info
= remote_files_info
;
4084 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
4085 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
4086 remote_cisco_ops
.to_kill
= remote_kill
;
4087 remote_cisco_ops
.to_load
= generic_load
;
4088 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
4089 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
4090 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
4091 remote_cisco_ops
.to_stratum
= process_stratum
;
4092 remote_cisco_ops
.to_has_all_memory
= 1;
4093 remote_cisco_ops
.to_has_memory
= 1;
4094 remote_cisco_ops
.to_has_stack
= 1;
4095 remote_cisco_ops
.to_has_registers
= 1;
4096 remote_cisco_ops
.to_has_execution
= 1;
4097 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
4101 build_remote_gdbarch_data ()
4103 tty_input
= xmalloc (PBUFSIZ
);
4108 _initialize_remote ()
4110 /* architecture specific data */
4111 build_remote_gdbarch_data ();
4112 register_gdbarch_swap (&tty_input
, sizeof (&tty_input
), NULL
);
4113 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
4115 /* runtime constants - we retain the value of remote_write_size
4116 across architecture swaps. */
4117 remote_write_size
= PBUFSIZ
;
4120 add_target (&remote_ops
);
4122 init_extended_remote_ops ();
4123 add_target (&extended_remote_ops
);
4125 init_remote_cisco_ops ();
4126 add_target (&remote_cisco_ops
);
4129 init_remote_threadtests ();
4132 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
4133 "Compare section data on target to the exec file.\n\
4134 Argument is a single section name (default: all loaded sections).",
4137 add_cmd ("packet", class_maintenance
, packet_command
,
4138 "Send an arbitrary packet to a remote target.\n\
4139 maintenance packet TEXT\n\
4140 If GDB is talking to an inferior via the GDB serial protocol, then\n\
4141 this command sends the string TEXT to the inferior, and displays the\n\
4142 response packet. GDB supplies the initial `$' character, and the\n\
4143 terminating `#' character and checksum.",
4147 (add_set_cmd ("remotetimeout", no_class
,
4148 var_integer
, (char *)&remote_timeout
,
4149 "Set timeout value for remote read.\n",
4154 (add_set_cmd ("remotebreak", no_class
,
4155 var_integer
, (char *)&remote_break
,
4156 "Set whether to send break if interrupted.\n",
4161 (add_set_cmd ("remotewritesize", no_class
,
4162 var_integer
, (char *)&remote_write_size
,
4163 "Set the maximum number of bytes per memory write packet.\n",
4167 remote_address_size
= TARGET_PTR_BIT
;
4169 (add_set_cmd ("remoteaddresssize", class_obscure
,
4170 var_integer
, (char *)&remote_address_size
,
4171 "Set the maximum size of the address (in bits) \
4172 in a memory packet.\n",
4177 (add_set_cmd ("remotebinarydownload", no_class
,
4178 var_boolean
, (char *) &remote_binary_download
,
4179 "Set binary downloads.\n", &setlist
),
4182 add_info ("remote-process", remote_info_process
,
4183 "Query the remote system for process info.");