1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Remote communication protocol.
24 A debug packet whose contents are <data>
25 is encapsulated for transmission in the form:
27 $ <data> # CSUM1 CSUM2
29 <data> must be ASCII alphanumeric and cannot include characters
30 '$' or '#'. If <data> starts with two characters followed by
31 ':', then the existing stubs interpret this as a sequence number.
33 CSUM1 and CSUM2 are ascii hex representation of an 8-bit
34 checksum of <data>, the most significant nibble is sent first.
35 the hex digits 0-9,a-f are used.
37 Receiver responds with:
39 + - if CSUM is correct and ready for next packet
40 - - if CSUM is incorrect
43 Most values are encoded in ascii hex digits. Signal numbers are according
44 to the numbering in target.h.
48 set thread Hct... Set thread for subsequent operations.
49 c = 'c' for thread used in step and
50 continue; t... can be -1 for all
52 c = 'g' for thread used in other
53 operations. If zero, pick a thread,
59 reply XX....X Each byte of register data
60 is described by two hex digits.
61 Registers are in the internal order
62 for GDB, and the bytes in a register
63 are in the same order the machine uses.
66 write regs GXX..XX Each byte of register data
67 is described by two hex digits.
71 write reg Pn...=r... Write register n... with value r...,
72 which contains two hex digits for each
73 byte in the register (target byte
77 (not supported by all stubs).
79 read mem mAA..AA,LLLL AA..AA is address, LLLL is length.
80 reply XX..XX XX..XX is mem contents
81 Can be fewer bytes than requested
82 if able to read only part of the data.
85 write mem MAA..AA,LLLL:XX..XX
87 LLLL is number of bytes,
90 ENN for an error (this includes the case
91 where only part of the data was
94 write mem XAA..AA,LLLL:XX..XX
95 (binary) AA..AA is address,
96 LLLL is number of bytes,
101 continue cAA..AA AA..AA is address to resume
102 If AA..AA is omitted,
103 resume at same address.
105 step sAA..AA AA..AA is address to resume
106 If AA..AA is omitted,
107 resume at same address.
109 continue with Csig;AA..AA Continue with signal sig (hex signal
110 signal number). If ;AA..AA is omitted,
111 resume at same address.
113 step with Ssig;AA..AA Like 'C' but step not continue.
116 last signal ? Reply the current reason for stopping.
117 This is the same reply as is generated
118 for step or cont : SAA where AA is the
123 There is no immediate reply to step or cont.
124 The reply comes when the machine stops.
125 It is SAA AA is the signal number.
127 or... TAAn...:r...;n...:r...;n...:r...;
129 n... = register number (hex)
130 r... = register contents
132 r... = thread process ID. This is
134 n... = other string not starting
135 with valid hex digit.
136 gdb should ignore this n,r pair
137 and go on to the next. This way
138 we can extend the protocol.
139 or... WAA The process exited, and AA is
140 the exit status. This is only
141 applicable for certains sorts of
143 or... XAA The process terminated with signal
145 or (obsolete) NAA;tttttttt;dddddddd;bbbbbbbb
147 tttttttt = address of symbol "_start"
148 dddddddd = base of data section
149 bbbbbbbb = base of bss section.
150 Note: only used by Cisco Systems
151 targets. The difference between this
152 reply and the "qOffsets" query is that
153 the 'N' packet may arrive spontaneously
154 whereas the 'qOffsets' is a query
155 initiated by the host debugger.
156 or... OXX..XX XX..XX is hex encoding of ASCII data. This
157 can happen at any time while the
158 program is running and the debugger
159 should continue to wait for
162 thread alive TXX Find out if the thread XX is alive.
163 reply OK thread is still alive
166 remote restart RXX Restart the remote server
168 extended ops ! Use the extended remote protocol.
169 Sticky -- only needs to be set once.
173 toggle debug d toggle debug flag (see 386 & 68k stubs)
174 reset r reset -- see sparc stub.
175 reserved <other> On other requests, the stub should
176 ignore the request and send an empty
177 response ($#<checksum>). This way
178 we can extend the protocol and GDB
179 can tell whether the stub it is
180 talking to uses the old or the new.
181 search tAA:PP,MM Search backwards starting at address
182 AA for a match with pattern PP and
183 mask MM. PP and MM are 4 bytes.
184 Not supported by all stubs.
186 general query qXXXX Request info about XXXX.
187 general set QXXXX=yyyy Set value of XXXX to yyyy.
188 query sect offs qOffsets Get section offsets. Reply is
189 Text=xxx;Data=yyy;Bss=zzz
191 Responses can be run-length encoded to save space. A '*' means that
192 the next character is an ASCII encoding giving a repeat count which
193 stands for that many repititions of the character preceding the '*'.
194 The encoding is n+29, yielding a printable character where n >=3
195 (which is where rle starts to win). Don't use an n > 126.
198 "0* " means the same as "0000". */
205 #include "gdb_string.h"
209 #include "inferior.h"
214 /*#include "terminal.h" */
216 #include "objfiles.h"
217 #include "gdb-stabs.h"
218 #include "gdbthread.h"
223 #include <sys/time.h>
225 #include <sys/types.h>
228 #include "event-loop.h"
233 /* Prototypes for local functions */
234 static void initialize_sigint_signal_handler
PARAMS ((void));
235 static void handle_remote_sigint
PARAMS ((int));
236 static void handle_remote_sigint_twice
PARAMS ((int));
237 static void async_remote_interrupt
PARAMS ((gdb_client_data
));
238 static void async_remote_interrupt_twice
PARAMS ((gdb_client_data
));
240 static void set_extended_protocol
PARAMS ((struct continuation_arg
*));
242 static void build_remote_gdbarch_data
PARAMS ((void));
244 static int remote_write_bytes
PARAMS ((CORE_ADDR memaddr
,
245 char *myaddr
, int len
));
247 static int remote_read_bytes
PARAMS ((CORE_ADDR memaddr
,
248 char *myaddr
, int len
));
250 static void remote_files_info
PARAMS ((struct target_ops
* ignore
));
252 static int remote_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
,
253 int len
, int should_write
,
254 struct target_ops
* target
));
256 static void remote_prepare_to_store
PARAMS ((void));
258 static void remote_fetch_registers
PARAMS ((int regno
));
260 static void remote_resume
PARAMS ((int pid
, int step
,
261 enum target_signal siggnal
));
262 static void remote_async_resume
PARAMS ((int pid
, int step
,
263 enum target_signal siggnal
));
265 static int remote_start_remote
PARAMS ((PTR
));
267 static void remote_open
PARAMS ((char *name
, int from_tty
));
268 static void remote_async_open
PARAMS ((char *name
, int from_tty
));
270 static void extended_remote_open
PARAMS ((char *name
, int from_tty
));
271 static void extended_remote_async_open
PARAMS ((char *name
, int from_tty
));
273 static void remote_open_1
PARAMS ((char *, int, struct target_ops
*,
275 static void remote_async_open_1
PARAMS ((char *, int, struct target_ops
*,
278 static void remote_close
PARAMS ((int quitting
));
280 static void remote_store_registers
PARAMS ((int regno
));
282 static void remote_mourn
PARAMS ((void));
284 static void extended_remote_restart
PARAMS ((void));
286 static void extended_remote_mourn
PARAMS ((void));
288 static void extended_remote_create_inferior
PARAMS ((char *, char *, char **));
289 static void extended_remote_async_create_inferior
PARAMS ((char *, char *, char **));
291 static void remote_mourn_1
PARAMS ((struct target_ops
*));
293 static void remote_send
PARAMS ((char *buf
));
295 static int readchar
PARAMS ((int timeout
));
297 static int remote_wait
PARAMS ((int pid
, struct target_waitstatus
* status
));
298 static int remote_async_wait
PARAMS ((int pid
, struct target_waitstatus
* status
));
300 static void remote_kill
PARAMS ((void));
301 static void remote_async_kill
PARAMS ((void));
303 static int tohex
PARAMS ((int nib
));
305 static void remote_detach
PARAMS ((char *args
, int from_tty
));
306 static void remote_async_detach
PARAMS ((char *args
, int from_tty
));
308 static void remote_interrupt
PARAMS ((int signo
));
310 static void remote_interrupt_twice
PARAMS ((int signo
));
312 static void interrupt_query
PARAMS ((void));
314 static void set_thread
PARAMS ((int, int));
316 static int remote_thread_alive
PARAMS ((int));
318 static void get_offsets
PARAMS ((void));
320 static int read_frame
PARAMS ((char *));
322 static int remote_insert_breakpoint
PARAMS ((CORE_ADDR
, char *));
324 static int remote_remove_breakpoint
PARAMS ((CORE_ADDR
, char *));
326 static int hexnumlen
PARAMS ((ULONGEST num
));
328 static void init_remote_ops
PARAMS ((void));
330 static void init_extended_remote_ops
PARAMS ((void));
332 static void init_remote_cisco_ops
PARAMS ((void));
334 static struct target_ops remote_cisco_ops
;
336 static void remote_stop
PARAMS ((void));
338 static int ishex
PARAMS ((int ch
, int *val
));
340 static int stubhex
PARAMS ((int ch
));
342 static int remote_query
PARAMS ((int /*char */ , char *, char *, int *));
344 static int hexnumstr
PARAMS ((char *, ULONGEST
));
346 static CORE_ADDR remote_address_masked
PARAMS ((CORE_ADDR
));
348 static void print_packet
PARAMS ((char *));
350 static unsigned long crc32
PARAMS ((unsigned char *, int, unsigned int));
352 static void compare_sections_command
PARAMS ((char *, int));
354 static void packet_command
PARAMS ((char *, int));
356 static int stub_unpack_int
PARAMS ((char *buff
, int fieldlength
));
358 static int remote_current_thread
PARAMS ((int oldpid
));
360 static void remote_find_new_threads
PARAMS ((void));
362 static void record_currthread
PARAMS ((int currthread
));
364 /* exported functions */
366 extern int fromhex
PARAMS ((int a
));
368 extern void getpkt
PARAMS ((char *buf
, int forever
));
370 extern int putpkt
PARAMS ((char *buf
));
372 static int putpkt_binary
PARAMS ((char *buf
, int cnt
));
374 void remote_console_output
PARAMS ((char *));
376 static void check_binary_download
PARAMS ((CORE_ADDR addr
));
378 /* Define the target subroutine names */
380 void open_remote_target
PARAMS ((char *, int, struct target_ops
*, int));
382 void _initialize_remote
PARAMS ((void));
386 static struct target_ops remote_ops
;
388 static struct target_ops extended_remote_ops
;
390 /* Temporary target ops. Just like the remote_ops and
391 extended_remote_ops, but with asynchronous support. */
392 static struct target_ops remote_async_ops
;
394 static struct target_ops extended_async_remote_ops
;
396 /* This was 5 seconds, which is a long time to sit and wait.
397 Unless this is going though some terminal server or multiplexer or
398 other form of hairy serial connection, I would think 2 seconds would
401 /* Changed to allow option to set timeout value.
402 was static int remote_timeout = 2; */
403 extern int remote_timeout
;
405 /* This variable chooses whether to send a ^C or a break when the user
406 requests program interruption. Although ^C is usually what remote
407 systems expect, and that is the default here, sometimes a break is
408 preferable instead. */
410 static int remote_break
;
412 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
413 remote_open knows that we don't have a file open when the program
415 static serial_t remote_desc
= NULL
;
417 /* This is set by the target (thru the 'S' message)
418 to denote that the target is in kernel mode. */
419 static int cisco_kernel_mode
= 0;
421 /* This variable (available to the user via "set remotebinarydownload")
422 dictates whether downloads are sent in binary (via the 'X' packet).
423 We assume that the stub can, and attempt to do it. This will be cleared if
424 the stub does not understand it. This switch is still needed, though
425 in cases when the packet is supported in the stub, but the connection
426 does not allow it (i.e., 7-bit serial connection only). */
427 static int remote_binary_download
= 1;
429 /* Have we already checked whether binary downloads work? */
430 static int remote_binary_checked
;
432 /* Maximum number of bytes to read/write at once. The value here
433 is chosen to fill up a packet (the headers account for the 32). */
434 #define MAXBUFBYTES(N) (((N)-32)/2)
436 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
437 and i386-stub.c. Normally, no one would notice because it only matters
438 for writing large chunks of memory (e.g. in downloads). Also, this needs
439 to be more than 400 if required to hold the registers (see below, where
440 we round it up based on REGISTER_BYTES). */
441 /* Round up PBUFSIZ to hold all the registers, at least. */
442 #define PBUFSIZ ((REGISTER_BYTES > MAXBUFBYTES (400)) \
443 ? (REGISTER_BYTES * 2 + 32) \
447 /* This variable sets the number of bytes to be written to the target
448 in a single packet. Normally PBUFSIZ is satisfactory, but some
449 targets need smaller values (perhaps because the receiving end
452 static int remote_write_size
;
454 /* This variable sets the number of bits in an address that are to be
455 sent in a memory ("M" or "m") packet. Normally, after stripping
456 leading zeros, the entire address would be sent. This variable
457 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
458 initial implementation of remote.c restricted the address sent in
459 memory packets to ``host::sizeof long'' bytes - (typically 32
460 bits). Consequently, for 64 bit targets, the upper 32 bits of an
461 address was never sent. Since fixing this bug may cause a break in
462 some remote targets this variable is principly provided to
463 facilitate backward compatibility. */
465 static int remote_address_size
;
467 /* This is the size (in chars) of the first response to the `g' command. This
468 is used to limit the size of the memory read and write commands to prevent
469 stub buffers from overflowing. The size does not include headers and
470 trailers, it is only the payload size. */
472 static int remote_register_buf_size
= 0;
474 /* Should we try the 'P' request? If this is set to one when the stub
475 doesn't support 'P', the only consequence is some unnecessary traffic. */
476 static int stub_supports_P
= 1;
478 /* Tokens for use by the asynchronous signal handlers for SIGINT */
479 PTR sigint_remote_twice_token
;
480 PTR sigint_remote_token
;
482 /* These are pointers to hook functions that may be set in order to
483 modify resume/wait behavior for a particular architecture. */
485 void (*target_resume_hook
) PARAMS ((void));
486 void (*target_wait_loop_hook
) PARAMS ((void));
490 /* These are the threads which we last sent to the remote system.
491 -1 for all or -2 for not sent yet. */
492 static int general_thread
;
493 static int continue_thread
;
495 /* Call this function as a result of
496 1) A halt indication (T packet) containing a thread id
497 2) A direct query of currthread
498 3) Successful execution of set thread
502 record_currthread (currthread
)
505 general_thread
= currthread
;
507 /* If this is a new thread, add it to GDB's thread list.
508 If we leave it up to WFI to do this, bad things will happen. */
509 if (!in_thread_list (currthread
))
511 add_thread (currthread
);
512 printf_filtered ("[New %s]\n", target_pid_to_str (currthread
));
516 #define MAGIC_NULL_PID 42000
523 char *buf
= alloca (PBUFSIZ
);
524 int state
= gen
? general_thread
: continue_thread
;
530 buf
[1] = gen
? 'g' : 'c';
531 if (th
== MAGIC_NULL_PID
)
537 sprintf (&buf
[2], "-%x", -th
);
539 sprintf (&buf
[2], "%x", th
);
545 continue_thread
= th
;
548 /* Return nonzero if the thread TH is still alive on the remote system. */
551 remote_thread_alive (tid
)
557 sprintf (buf
, "T-%08x", -tid
);
559 sprintf (buf
, "T%08x", tid
);
562 return (buf
[0] == 'O' && buf
[1] == 'K');
565 /* About these extended threadlist and threadinfo packets. They are
566 variable length packets but, the fields within them are often fixed
567 length. They are redundent enough to send over UDP as is the
568 remote protocol in general. There is a matching unit test module
571 #define OPAQUETHREADBYTES 8
573 /* a 64 bit opaque identifier */
574 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
576 /* WARNING: This threadref data structure comes from the remote O.S., libstub
577 protocol encoding, and remote.c. it is not particularly changable */
579 /* Right now, the internal structure is int. We want it to be bigger.
583 typedef int gdb_threadref
; /* internal GDB thread reference */
585 /* gdb_ext_thread_info is an internal GDB data structure which is
586 equivalint to the reply of the remote threadinfo packet */
588 struct gdb_ext_thread_info
590 threadref threadid
; /* External form of thread reference */
591 int active
; /* Has state interesting to GDB? , regs, stack */
592 char display
[256]; /* Brief state display, name, blocked/syspended */
593 char shortname
[32]; /* To be used to name threads */
594 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
597 /* The volume of remote transfers can be limited by submitting
598 a mask containing bits specifying the desired information.
599 Use a union of these values as the 'selection' parameter to
600 get_thread_info. FIXME: Make these TAG names more thread specific.
603 #define TAG_THREADID 1
605 #define TAG_DISPLAY 4
606 #define TAG_THREADNAME 8
607 #define TAG_MOREDISPLAY 16
609 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
611 char *unpack_varlen_hex
PARAMS ((char *buff
, int *result
));
613 static char *unpack_nibble
PARAMS ((char *buf
, int *val
));
615 static char *pack_nibble
PARAMS ((char *buf
, int nibble
));
617 static char *pack_hex_byte
PARAMS ((char *pkt
, int /*unsigned char */ byte
));
619 static char *unpack_byte
PARAMS ((char *buf
, int *value
));
621 static char *pack_int
PARAMS ((char *buf
, int value
));
623 static char *unpack_int
PARAMS ((char *buf
, int *value
));
625 static char *unpack_string
PARAMS ((char *src
, char *dest
, int length
));
627 static char *pack_threadid
PARAMS ((char *pkt
, threadref
* id
));
629 static char *unpack_threadid
PARAMS ((char *inbuf
, threadref
* id
));
631 void int_to_threadref
PARAMS ((threadref
* id
, int value
));
633 static int threadref_to_int
PARAMS ((threadref
* ref
));
635 static void copy_threadref
PARAMS ((threadref
* dest
, threadref
* src
));
637 static int threadmatch
PARAMS ((threadref
* dest
, threadref
* src
));
639 static char *pack_threadinfo_request
PARAMS ((char *pkt
, int mode
,
642 static int remote_unpack_thread_info_response
PARAMS ((char *pkt
,
643 threadref
* expectedref
,
644 struct gdb_ext_thread_info
* info
));
647 static int remote_get_threadinfo
PARAMS ((threadref
* threadid
,
648 int fieldset
, /*TAG mask */
649 struct gdb_ext_thread_info
* info
));
651 static int adapt_remote_get_threadinfo
PARAMS ((gdb_threadref
* ref
,
653 struct gdb_ext_thread_info
* info
));
655 static char *pack_threadlist_request
PARAMS ((char *pkt
, int startflag
,
657 threadref
* nextthread
));
659 static int parse_threadlist_response
PARAMS ((char *pkt
,
661 threadref
* original_echo
,
662 threadref
* resultlist
,
665 static int remote_get_threadlist
PARAMS ((int startflag
,
666 threadref
* nextthread
,
670 threadref
* threadlist
));
672 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
674 static int remote_threadlist_iterator
PARAMS ((rmt_thread_action stepfunction
,
675 void *context
, int looplimit
));
677 static int remote_newthread_step
PARAMS ((threadref
* ref
, void *context
));
679 /* encode 64 bits in 16 chars of hex */
681 static const char hexchars
[] = "0123456789abcdef";
688 if ((ch
>= 'a') && (ch
<= 'f'))
690 *val
= ch
- 'a' + 10;
693 if ((ch
>= 'A') && (ch
<= 'F'))
695 *val
= ch
- 'A' + 10;
698 if ((ch
>= '0') && (ch
<= '9'))
710 if (ch
>= 'a' && ch
<= 'f')
711 return ch
- 'a' + 10;
712 if (ch
>= '0' && ch
<= '9')
714 if (ch
>= 'A' && ch
<= 'F')
715 return ch
- 'A' + 10;
720 stub_unpack_int (buff
, fieldlength
)
729 nibble
= stubhex (*buff
++);
733 retval
= retval
<< 4;
739 unpack_varlen_hex (buff
, result
)
740 char *buff
; /* packet to parse */
746 while (ishex (*buff
, &nibble
))
749 retval
= retval
<< 4;
750 retval
|= nibble
& 0x0f;
757 unpack_nibble (buf
, val
)
766 pack_nibble (buf
, nibble
)
770 *buf
++ = hexchars
[(nibble
& 0x0f)];
775 pack_hex_byte (pkt
, byte
)
779 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
780 *pkt
++ = hexchars
[(byte
& 0xf)];
785 unpack_byte (buf
, value
)
789 *value
= stub_unpack_int (buf
, 2);
794 pack_int (buf
, value
)
798 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
799 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
800 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
801 buf
= pack_hex_byte (buf
, (value
& 0xff));
806 unpack_int (buf
, value
)
810 *value
= stub_unpack_int (buf
, 8);
814 #if 0 /* currently unused, uncomment when needed */
815 static char *pack_string
PARAMS ((char *pkt
, char *string
));
818 pack_string (pkt
, string
)
825 len
= strlen (string
);
827 len
= 200; /* Bigger than most GDB packets, junk??? */
828 pkt
= pack_hex_byte (pkt
, len
);
832 if ((ch
== '\0') || (ch
== '#'))
833 ch
= '*'; /* Protect encapsulation */
838 #endif /* 0 (unused) */
841 unpack_string (src
, dest
, length
)
853 pack_threadid (pkt
, id
)
858 unsigned char *altid
;
860 altid
= (unsigned char *) id
;
861 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
863 pkt
= pack_hex_byte (pkt
, *altid
++);
869 unpack_threadid (inbuf
, id
)
874 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
877 altref
= (char *) id
;
879 while (inbuf
< limit
)
881 x
= stubhex (*inbuf
++);
882 y
= stubhex (*inbuf
++);
883 *altref
++ = (x
<< 4) | y
;
888 /* Externally, threadrefs are 64 bits but internally, they are still
889 ints. This is due to a mismatch of specifications. We would like
890 to use 64bit thread references internally. This is an adapter
894 int_to_threadref (id
, value
)
900 scan
= (unsigned char *) id
;
906 *scan
++ = (value
>> 24) & 0xff;
907 *scan
++ = (value
>> 16) & 0xff;
908 *scan
++ = (value
>> 8) & 0xff;
909 *scan
++ = (value
& 0xff);
913 threadref_to_int (ref
)
923 value
= (value
<< 8) | ((*scan
++) & 0xff);
928 copy_threadref (dest
, src
)
933 unsigned char *csrc
, *cdest
;
935 csrc
= (unsigned char *) src
;
936 cdest
= (unsigned char *) dest
;
943 threadmatch (dest
, src
)
947 /* things are broken right now, so just assume we got a match */
949 unsigned char *srcp
, *destp
;
952 destp
= (char *) dest
;
956 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
963 threadid:1, # always request threadid
970 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
973 pack_threadinfo_request (pkt
, mode
, id
)
978 *pkt
++ = 'q'; /* Info Query */
979 *pkt
++ = 'P'; /* process or thread info */
980 pkt
= pack_int (pkt
, mode
); /* mode */
981 pkt
= pack_threadid (pkt
, id
); /* threadid */
982 *pkt
= '\0'; /* terminate */
986 /* These values tag the fields in a thread info response packet */
987 /* Tagging the fields allows us to request specific fields and to
988 add more fields as time goes by */
990 #define TAG_THREADID 1 /* Echo the thread identifier */
991 #define TAG_EXISTS 2 /* Is this process defined enough to
992 fetch registers and its stack */
993 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
994 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
995 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
999 remote_unpack_thread_info_response (pkt
, expectedref
, info
)
1001 threadref
*expectedref
;
1002 struct gdb_ext_thread_info
*info
;
1007 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
1010 /* info->threadid = 0; FIXME: implement zero_threadref */
1012 info
->display
[0] = '\0';
1013 info
->shortname
[0] = '\0';
1014 info
->more_display
[0] = '\0';
1016 /* Assume the characters indicating the packet type have been stripped */
1017 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1018 pkt
= unpack_threadid (pkt
, &ref
);
1021 warning ("Incomplete response to threadinfo request\n");
1022 if (!threadmatch (&ref
, expectedref
))
1023 { /* This is an answer to a different request */
1024 warning ("ERROR RMT Thread info mismatch\n");
1027 copy_threadref (&info
->threadid
, &ref
);
1029 /* Loop on tagged fields , try to bail if somthing goes wrong */
1031 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1033 pkt
= unpack_int (pkt
, &tag
); /* tag */
1034 pkt
= unpack_byte (pkt
, &length
); /* length */
1035 if (!(tag
& mask
)) /* tags out of synch with mask */
1037 warning ("ERROR RMT: threadinfo tag mismatch\n");
1041 if (tag
== TAG_THREADID
)
1045 warning ("ERROR RMT: length of threadid is not 16\n");
1049 pkt
= unpack_threadid (pkt
, &ref
);
1050 mask
= mask
& ~TAG_THREADID
;
1053 if (tag
== TAG_EXISTS
)
1055 info
->active
= stub_unpack_int (pkt
, length
);
1057 mask
= mask
& ~(TAG_EXISTS
);
1060 warning ("ERROR RMT: 'exists' length too long\n");
1066 if (tag
== TAG_THREADNAME
)
1068 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1069 mask
= mask
& ~TAG_THREADNAME
;
1072 if (tag
== TAG_DISPLAY
)
1074 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1075 mask
= mask
& ~TAG_DISPLAY
;
1078 if (tag
== TAG_MOREDISPLAY
)
1080 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1081 mask
= mask
& ~TAG_MOREDISPLAY
;
1084 warning ("ERROR RMT: unknown thread info tag\n");
1085 break; /* Not a tag we know about */
1091 remote_get_threadinfo (threadid
, fieldset
, info
)
1092 threadref
*threadid
;
1093 int fieldset
; /* TAG mask */
1094 struct gdb_ext_thread_info
*info
;
1097 char *threadinfo_pkt
= alloca (PBUFSIZ
);
1099 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1100 putpkt (threadinfo_pkt
);
1101 getpkt (threadinfo_pkt
, 0);
1102 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1107 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1108 representation of a threadid. */
1111 adapt_remote_get_threadinfo (ref
, selection
, info
)
1114 struct gdb_ext_thread_info
*info
;
1118 int_to_threadref (&lclref
, *ref
);
1119 return remote_get_threadinfo (&lclref
, selection
, info
);
1122 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1125 pack_threadlist_request (pkt
, startflag
, threadcount
, nextthread
)
1129 threadref
*nextthread
;
1131 *pkt
++ = 'q'; /* info query packet */
1132 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1133 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1134 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1135 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1140 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1143 parse_threadlist_response (pkt
, result_limit
, original_echo
, resultlist
,
1147 threadref
*original_echo
;
1148 threadref
*resultlist
;
1152 int count
, resultcount
, done
;
1155 /* Assume the 'q' and 'M chars have been stripped. */
1156 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1157 pkt
= unpack_byte (pkt
, &count
); /* count field */
1158 pkt
= unpack_nibble (pkt
, &done
);
1159 /* The first threadid is the argument threadid. */
1160 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1161 while ((count
-- > 0) && (pkt
< limit
))
1163 pkt
= unpack_threadid (pkt
, resultlist
++);
1164 if (resultcount
++ >= result_limit
)
1173 remote_get_threadlist (startflag
, nextthread
, result_limit
,
1174 done
, result_count
, threadlist
)
1176 threadref
*nextthread
;
1180 threadref
*threadlist
;
1183 static threadref echo_nextthread
;
1184 char *threadlist_packet
= alloca (PBUFSIZ
);
1185 char *t_response
= alloca (PBUFSIZ
);
1188 /* Trancate result limit to be smaller than the packet size */
1189 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1190 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1192 pack_threadlist_request (threadlist_packet
,
1193 startflag
, result_limit
, nextthread
);
1194 putpkt (threadlist_packet
);
1195 getpkt (t_response
, 0);
1198 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1201 if (!threadmatch (&echo_nextthread
, nextthread
))
1203 /* FIXME: This is a good reason to drop the packet */
1204 /* Possably, there is a duplicate response */
1206 retransmit immediatly - race conditions
1207 retransmit after timeout - yes
1209 wait for packet, then exit
1211 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1212 return 0; /* I choose simply exiting */
1214 if (*result_count
<= 0)
1218 warning ("RMT ERROR : failed to get remote thread list\n");
1221 return result
; /* break; */
1223 if (*result_count
> result_limit
)
1226 warning ("RMT ERROR: threadlist response longer than requested\n");
1232 /* This is the interface between remote and threads, remotes upper interface */
1234 /* remote_find_new_threads retrieves the thread list and for each
1235 thread in the list, looks up the thread in GDB's internal list,
1236 ading the thread if it does not already exist. This involves
1237 getting partial thread lists from the remote target so, polling the
1238 quit_flag is required. */
1241 /* About this many threadisds fit in a packet. */
1243 #define MAXTHREADLISTRESULTS 32
1246 remote_threadlist_iterator (stepfunction
, context
, looplimit
)
1247 rmt_thread_action stepfunction
;
1251 int done
, i
, result_count
;
1255 static threadref nextthread
;
1256 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1261 if (loopcount
++ > looplimit
)
1264 warning ("Remote fetch threadlist -infinite loop-\n");
1267 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1268 &done
, &result_count
, resultthreadlist
))
1273 /* clear for later iterations */
1275 /* Setup to resume next batch of thread references, set nextthread. */
1276 if (result_count
>= 1)
1277 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1279 while (result_count
--)
1280 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1287 remote_newthread_step (ref
, context
)
1293 pid
= threadref_to_int (ref
);
1294 if (!in_thread_list (pid
))
1296 return 1; /* continue iterator */
1299 #define CRAZY_MAX_THREADS 1000
1302 remote_current_thread (oldpid
)
1305 char *buf
= alloca (PBUFSIZ
);
1309 if (buf
[0] == 'Q' && buf
[1] == 'C')
1310 return strtol (&buf
[2], NULL
, 16);
1315 /* Find new threads for info threads command. */
1318 remote_find_new_threads ()
1320 remote_threadlist_iterator (remote_newthread_step
, 0,
1322 if (inferior_pid
== MAGIC_NULL_PID
) /* ack ack ack */
1323 inferior_pid
= remote_current_thread (inferior_pid
);
1327 remote_threads_info (void)
1329 char *buf
= alloca (PBUFSIZ
);
1333 if (remote_desc
== 0) /* paranoia */
1334 error ("Command can only be used when connected to the remote target.");
1336 putpkt ("qfThreadInfo");
1337 getpkt (bufp
= buf
, 0);
1338 if (bufp
[0] == '\0') /* q packet not recognized! */
1339 { /* try old jmetzler method */
1340 remote_find_new_threads ();
1343 else /* try new 'q' method */
1344 while (*bufp
++ == 'm') /* reply contains one or more TID */
1348 tid
= strtol (bufp
, &bufp
, 16);
1349 if (tid
!= 0 && !in_thread_list (tid
))
1352 while (*bufp
++ == ','); /* comma-separated list */
1353 putpkt ("qsThreadInfo");
1354 getpkt (bufp
= buf
, 0);
1359 /* Restart the remote side; this is an extended protocol operation. */
1362 extended_remote_restart ()
1364 char *buf
= alloca (PBUFSIZ
);
1366 /* Send the restart command; for reasons I don't understand the
1367 remote side really expects a number after the "R". */
1369 sprintf (&buf
[1], "%x", 0);
1372 /* Now query for status so this looks just like we restarted
1373 gdbserver from scratch. */
1378 /* Clean up connection to a remote debugger. */
1382 remote_close (quitting
)
1386 SERIAL_CLOSE (remote_desc
);
1390 /* Query the remote side for the text, data and bss offsets. */
1395 char *buf
= alloca (PBUFSIZ
);
1398 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1399 struct section_offsets
*offs
;
1401 putpkt ("qOffsets");
1405 if (buf
[0] == '\000')
1406 return; /* Return silently. Stub doesn't support
1410 warning ("Remote failure reply: %s", buf
);
1414 /* Pick up each field in turn. This used to be done with scanf, but
1415 scanf will make trouble if CORE_ADDR size doesn't match
1416 conversion directives correctly. The following code will work
1417 with any size of CORE_ADDR. */
1418 text_addr
= data_addr
= bss_addr
= 0;
1422 if (strncmp (ptr
, "Text=", 5) == 0)
1425 /* Don't use strtol, could lose on big values. */
1426 while (*ptr
&& *ptr
!= ';')
1427 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1432 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1435 while (*ptr
&& *ptr
!= ';')
1436 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1441 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1444 while (*ptr
&& *ptr
!= ';')
1445 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1451 error ("Malformed response to offset query, %s", buf
);
1453 if (symfile_objfile
== NULL
)
1456 offs
= alloca (sizeof (struct section_offsets
)
1457 + symfile_objfile
->num_sections
1458 * sizeof (offs
->offsets
));
1459 memcpy (offs
, symfile_objfile
->section_offsets
,
1460 sizeof (struct section_offsets
)
1461 + symfile_objfile
->num_sections
1462 * sizeof (offs
->offsets
));
1464 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
1466 /* This is a temporary kludge to force data and bss to use the same offsets
1467 because that's what nlmconv does now. The real solution requires changes
1468 to the stub and remote.c that I don't have time to do right now. */
1470 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
1471 ANOFFSET (offs
, SECT_OFF_BSS
) = data_addr
;
1473 objfile_relocate (symfile_objfile
, offs
);
1477 * Cisco version of section offsets:
1479 * Instead of having GDB query the target for the section offsets,
1480 * Cisco lets the target volunteer the information! It's also in
1481 * a different format, so here are the functions that will decode
1482 * a section offset packet from a Cisco target.
1486 * Function: remote_cisco_section_offsets
1488 * Returns: zero for success, non-zero for failure
1492 remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
1493 text_offs
, data_offs
, bss_offs
)
1497 bfd_signed_vma
*text_offs
;
1498 bfd_signed_vma
*data_offs
;
1499 bfd_signed_vma
*bss_offs
;
1501 bfd_vma text_base
, data_base
, bss_base
;
1502 struct minimal_symbol
*start
;
1508 if (symfile_objfile
== NULL
)
1509 return -1; /* no can do nothin' */
1511 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
1513 return -1; /* Can't find "_start" symbol */
1515 data_base
= bss_base
= 0;
1516 text_base
= SYMBOL_VALUE_ADDRESS (start
);
1518 abfd
= symfile_objfile
->obfd
;
1519 for (sect
= abfd
->sections
;
1523 p
= (unsigned char *) bfd_get_section_name (abfd
, sect
);
1525 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
1526 if (data_base
== 0 ||
1527 data_base
> bfd_get_section_vma (abfd
, sect
))
1528 data_base
= bfd_get_section_vma (abfd
, sect
);
1529 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
1530 if (bss_base
== 0 ||
1531 bss_base
> bfd_get_section_vma (abfd
, sect
))
1532 bss_base
= bfd_get_section_vma (abfd
, sect
);
1534 *text_offs
= text_addr
- text_base
;
1535 *data_offs
= data_addr
- data_base
;
1536 *bss_offs
= bss_addr
- bss_base
;
1541 sprintf (tmp
, "VMA: text = 0x");
1542 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
1543 sprintf (tmp
+ strlen (tmp
), " data = 0x");
1544 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
1545 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
1546 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
1547 fprintf_filtered (gdb_stdlog
, tmp
);
1548 fprintf_filtered (gdb_stdlog
,
1549 "Reloc offset: text = 0x%x data = 0x%x bss = 0x%x\n",
1550 (long) *text_offs
, (long) *data_offs
, (long) *bss_offs
);
1557 * Function: remote_cisco_objfile_relocate
1559 * Relocate the symbol file for a remote target.
1563 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
)
1564 bfd_signed_vma text_off
;
1565 bfd_signed_vma data_off
;
1566 bfd_signed_vma bss_off
;
1568 struct section_offsets
*offs
;
1570 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
1572 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1573 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1574 simple canonical representation for this stuff. */
1576 offs
= ((struct section_offsets
*)
1577 alloca (sizeof (struct section_offsets
)
1578 + (symfile_objfile
->num_sections
1579 * sizeof (offs
->offsets
))));
1581 memcpy (offs
, symfile_objfile
->section_offsets
,
1582 (sizeof (struct section_offsets
)
1583 + (symfile_objfile
->num_sections
1584 * sizeof (offs
->offsets
))));
1586 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_off
;
1587 ANOFFSET (offs
, SECT_OFF_DATA
) = data_off
;
1588 ANOFFSET (offs
, SECT_OFF_BSS
) = bss_off
;
1590 /* First call the standard objfile_relocate. */
1591 objfile_relocate (symfile_objfile
, offs
);
1593 /* Now we need to fix up the section entries already attached to
1594 the exec target. These entries will control memory transfers
1595 from the exec file. */
1597 exec_set_section_offsets (text_off
, data_off
, bss_off
);
1601 /* Stub for catch_errors. */
1604 remote_start_remote_dummy (dummy
)
1607 start_remote (); /* Initialize gdb process mechanisms */
1612 remote_start_remote (dummy
)
1615 immediate_quit
= 1; /* Allow user to interrupt it */
1617 /* Ack any packet which the remote side has already sent. */
1618 SERIAL_WRITE (remote_desc
, "+", 1);
1620 /* Let the stub know that we want it to return the thread. */
1623 inferior_pid
= remote_current_thread (inferior_pid
);
1625 get_offsets (); /* Get text, data & bss offsets */
1627 putpkt ("?"); /* initiate a query from remote machine */
1630 return remote_start_remote_dummy (dummy
);
1633 /* Open a connection to a remote debugger.
1634 NAME is the filename used for communication. */
1637 remote_open (name
, from_tty
)
1641 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
1644 /* Just like remote_open, but with asynchronous support. */
1646 remote_async_open (name
, from_tty
)
1650 remote_async_open_1 (name
, from_tty
, &remote_async_ops
, 0);
1653 /* Open a connection to a remote debugger using the extended
1654 remote gdb protocol. NAME is the filename used for communication. */
1657 extended_remote_open (name
, from_tty
)
1661 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */ );
1664 /* Just like extended_remote_open, but with asynchronous support. */
1666 extended_remote_async_open (name
, from_tty
)
1670 remote_async_open_1 (name
, from_tty
, &extended_async_remote_ops
, 1 /*extended_p */ );
1673 /* Generic code for opening a connection to a remote target. */
1675 static DCACHE
*remote_dcache
;
1678 remote_open_1 (name
, from_tty
, target
, extended_p
)
1681 struct target_ops
*target
;
1685 error ("To open a remote debug connection, you need to specify what\n\
1686 serial device is attached to the remote system (e.g. /dev/ttya).");
1688 target_preopen (from_tty
);
1690 unpush_target (target
);
1692 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1694 remote_desc
= SERIAL_OPEN (name
);
1696 perror_with_name (name
);
1698 if (baud_rate
!= -1)
1700 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1702 SERIAL_CLOSE (remote_desc
);
1703 perror_with_name (name
);
1707 SERIAL_RAW (remote_desc
);
1709 /* If there is something sitting in the buffer we might take it as a
1710 response to a command, which would be bad. */
1711 SERIAL_FLUSH_INPUT (remote_desc
);
1715 puts_filtered ("Remote debugging using ");
1716 puts_filtered (name
);
1717 puts_filtered ("\n");
1719 push_target (target
); /* Switch to using remote target now */
1721 /* Start out by trying the 'P' request to set registers. We set
1722 this each time that we open a new target so that if the user
1723 switches from one stub to another, we can (if the target is
1724 closed and reopened) cope. */
1725 stub_supports_P
= 1;
1727 general_thread
= -2;
1728 continue_thread
= -2;
1730 /* Force remote_write_bytes to check whether target supports
1731 binary downloading. */
1732 remote_binary_checked
= 0;
1734 /* Without this, some commands which require an active target (such
1735 as kill) won't work. This variable serves (at least) double duty
1736 as both the pid of the target process (if it has such), and as a
1737 flag indicating that a target is active. These functions should
1738 be split out into seperate variables, especially since GDB will
1739 someday have a notion of debugging several processes. */
1741 inferior_pid
= MAGIC_NULL_PID
;
1742 /* Start the remote connection; if error (0), discard this target.
1743 In particular, if the user quits, be sure to discard it
1744 (we'd be in an inconsistent state otherwise). */
1745 if (!catch_errors (remote_start_remote
, NULL
,
1746 "Couldn't establish connection to remote target\n",
1755 /* tell the remote that we're using the extended protocol. */
1756 char *buf
= alloca (PBUFSIZ
);
1762 /* Just like remote_open but with asynchronous support. */
1764 remote_async_open_1 (name
, from_tty
, target
, extended_p
)
1767 struct target_ops
*target
;
1771 error ("To open a remote debug connection, you need to specify what\n\
1772 serial device is attached to the remote system (e.g. /dev/ttya).");
1774 target_preopen (from_tty
);
1776 unpush_target (target
);
1778 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1780 remote_desc
= SERIAL_OPEN (name
);
1782 perror_with_name (name
);
1784 if (baud_rate
!= -1)
1786 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1788 SERIAL_CLOSE (remote_desc
);
1789 perror_with_name (name
);
1793 SERIAL_RAW (remote_desc
);
1795 /* If there is something sitting in the buffer we might take it as a
1796 response to a command, which would be bad. */
1797 SERIAL_FLUSH_INPUT (remote_desc
);
1801 puts_filtered ("Remote debugging using ");
1802 puts_filtered (name
);
1803 puts_filtered ("\n");
1806 /* If running in asynchronous mode, register the target with the
1807 event loop. Set things up so that when there is an event on the
1808 file descriptor, the event loop will call fetch_inferior_event,
1809 which will do the proper analysis to determine what happened. */
1811 add_file_handler (remote_desc
->fd
, (file_handler_func
*) fetch_inferior_event
, 0);
1813 push_target (target
); /* Switch to using remote target now */
1815 /* Start out by trying the 'P' request to set registers. We set
1816 this each time that we open a new target so that if the user
1817 switches from one stub to another, we can (if the target is
1818 closed and reopened) cope. */
1819 stub_supports_P
= 1;
1821 general_thread
= -2;
1822 continue_thread
= -2;
1824 /* Force remote_write_bytes to check whether target supports
1825 binary downloading. */
1826 remote_binary_checked
= 0;
1828 /* If running asynchronously, set things up for telling the target
1829 to use the extended protocol. This will happen only after the
1830 target has been connected to, in fetch_inferior_event. */
1831 if (extended_p
&& async_p
)
1832 add_continuation (set_extended_protocol
, NULL
);
1834 /* Without this, some commands which require an active target (such
1835 as kill) won't work. This variable serves (at least) double duty
1836 as both the pid of the target process (if it has such), and as a
1837 flag indicating that a target is active. These functions should
1838 be split out into seperate variables, especially since GDB will
1839 someday have a notion of debugging several processes. */
1841 inferior_pid
= MAGIC_NULL_PID
;
1842 /* Start the remote connection; if error (0), discard this target.
1843 In particular, if the user quits, be sure to discard it
1844 (we'd be in an inconsistent state otherwise). */
1845 if (!catch_errors (remote_start_remote
, NULL
,
1846 "Couldn't establish connection to remote target\n",
1849 /* Unregister the file descriptor from the event loop. */
1851 delete_file_handler (remote_desc
->fd
);
1860 /* tell the remote that we're using the extended protocol. */
1861 char *buf
= alloca (PBUFSIZ
);
1868 /* This will be called by fetch_inferior_event, via the
1869 cmd_continuation pointer, only after the target has stopped. */
1871 set_extended_protocol (arg
)
1872 struct continuation_arg
*arg
;
1874 /* tell the remote that we're using the extended protocol. */
1875 char *buf
= alloca (PBUFSIZ
);
1880 /* This takes a program previously attached to and detaches it. After
1881 this is done, GDB can be used to debug some other program. We
1882 better not have left any breakpoints in the target program or it'll
1883 die when it hits one. */
1886 remote_detach (args
, from_tty
)
1890 char *buf
= alloca (PBUFSIZ
);
1893 error ("Argument given to \"detach\" when remotely debugging.");
1895 /* Tell the remote target to detach. */
1901 puts_filtered ("Ending remote debugging.\n");
1904 /* Same as remote_detach, but with async support. */
1906 remote_async_detach (args
, from_tty
)
1910 char *buf
= alloca (PBUFSIZ
);
1913 error ("Argument given to \"detach\" when remotely debugging.");
1915 /* Tell the remote target to detach. */
1919 /* Unregister the file descriptor from the event loop. */
1921 delete_file_handler (remote_desc
->fd
);
1925 puts_filtered ("Ending remote debugging.\n");
1928 /* Convert hex digit A to a number. */
1934 if (a
>= '0' && a
<= '9')
1936 else if (a
>= 'a' && a
<= 'f')
1937 return a
- 'a' + 10;
1938 else if (a
>= 'A' && a
<= 'F')
1939 return a
- 'A' + 10;
1941 error ("Reply contains invalid hex digit %d", a
);
1944 /* Convert number NIB to a hex digit. */
1953 return 'a' + nib
- 10;
1956 /* Tell the remote machine to resume. */
1958 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
1960 static int last_sent_step
;
1963 remote_resume (pid
, step
, siggnal
)
1965 enum target_signal siggnal
;
1967 char *buf
= alloca (PBUFSIZ
);
1970 set_thread (0, 0); /* run any thread */
1972 set_thread (pid
, 0); /* run this thread */
1974 dcache_flush (remote_dcache
);
1976 last_sent_signal
= siggnal
;
1977 last_sent_step
= step
;
1979 /* A hook for when we need to do something at the last moment before
1981 if (target_resume_hook
)
1982 (*target_resume_hook
) ();
1984 if (siggnal
!= TARGET_SIGNAL_0
)
1986 buf
[0] = step
? 'S' : 'C';
1987 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
1988 buf
[2] = tohex ((int) siggnal
& 0xf);
1992 strcpy (buf
, step
? "s" : "c");
1997 /* Same as remote_resume, but with async support. */
1999 remote_async_resume (pid
, step
, siggnal
)
2001 enum target_signal siggnal
;
2003 char *buf
= alloca (PBUFSIZ
);
2006 set_thread (0, 0); /* run any thread */
2008 set_thread (pid
, 0); /* run this thread */
2010 dcache_flush (remote_dcache
);
2012 last_sent_signal
= siggnal
;
2013 last_sent_step
= step
;
2015 /* A hook for when we need to do something at the last moment before
2017 if (target_resume_hook
)
2018 (*target_resume_hook
) ();
2020 /* Set things up before execution starts for async commands. */
2021 /* This function can be entered more than once for the same execution
2022 command, because it is also called by handle_inferior_event. So
2023 we make sure that we don't do the initialization for sync
2024 execution more than once. */
2025 if (async_p
&& !target_executing
)
2027 target_executing
= 1;
2029 /* If the command must look synchronous, fake it, by making gdb
2030 display an empty prompt after the command has completed. Also
2034 push_prompt ("", "", "");
2035 delete_file_handler (input_fd
);
2036 initialize_sigint_signal_handler ();
2040 if (siggnal
!= TARGET_SIGNAL_0
)
2042 buf
[0] = step
? 'S' : 'C';
2043 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2044 buf
[2] = tohex ((int) siggnal
& 0xf);
2048 strcpy (buf
, step
? "s" : "c");
2054 /* Set up the signal handler for SIGINT, while the target is
2055 executing, ovewriting the 'regular' SIGINT signal handler. */
2057 initialize_sigint_signal_handler ()
2059 sigint_remote_token
=
2060 create_async_signal_handler (async_remote_interrupt
, NULL
);
2061 signal (SIGINT
, handle_remote_sigint
);
2064 /* Signal handler for SIGINT, while the target is executing. */
2066 handle_remote_sigint (sig
)
2069 signal (sig
, handle_remote_sigint_twice
);
2070 sigint_remote_twice_token
=
2071 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2072 mark_async_signal_handler_wrapper (sigint_remote_token
);
2075 /* Signal handler for SIGINT, installed after SIGINT has already been
2076 sent once. It will take effect the second time that the user sends
2079 handle_remote_sigint_twice (sig
)
2082 signal (sig
, handle_sigint
);
2083 sigint_remote_twice_token
=
2084 create_async_signal_handler (async_remote_interrupt
, NULL
);
2085 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2088 /* Perform the real interruption of hte target execution, in response
2091 async_remote_interrupt (arg
)
2092 gdb_client_data arg
;
2095 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2100 /* Perform interrupt, if the first attempt did not succeed. Just give
2101 up on the target alltogether. */
2103 async_remote_interrupt_twice (arg
)
2104 gdb_client_data arg
;
2107 signal (SIGINT
, handle_remote_sigint
);
2110 /* Reinstall the usual SIGINT handlers, after the target has
2113 cleanup_sigint_signal_handler ()
2115 signal (SIGINT
, handle_sigint
);
2116 if (sigint_remote_twice_token
)
2117 delete_async_signal_handler ((async_signal_handler
**) & sigint_remote_twice_token
);
2118 if (sigint_remote_token
)
2119 delete_async_signal_handler ((async_signal_handler
**) & sigint_remote_token
);
2122 /* Send ^C to target to halt it. Target will respond, and send us a
2124 static void (*ofunc
) PARAMS ((int));
2126 /* The command line interface's stop routine. This function is installed
2127 as a signal handler for SIGINT. The first time a user requests a
2128 stop, we call remote_stop to send a break or ^C. If there is no
2129 response from the target (it didn't stop when the user requested it),
2130 we ask the user if he'd like to detach from the target. */
2132 remote_interrupt (signo
)
2135 /* If this doesn't work, try more severe steps. */
2136 signal (signo
, remote_interrupt_twice
);
2139 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2144 /* The user typed ^C twice. */
2147 remote_interrupt_twice (signo
)
2150 signal (signo
, ofunc
);
2152 signal (signo
, remote_interrupt
);
2155 /* This is the generic stop called via the target vector. When a target
2156 interrupt is requested, either by the command line or the GUI, we
2157 will eventually end up here. */
2161 /* Send a break or a ^C, depending on user preference. */
2163 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2166 SERIAL_SEND_BREAK (remote_desc
);
2168 SERIAL_WRITE (remote_desc
, "\003", 1);
2171 /* Ask the user what to do when an interrupt is received. */
2176 target_terminal_ours ();
2178 if (query ("Interrupted while waiting for the program.\n\
2179 Give up (and stop debugging it)? "))
2181 target_mourn_inferior ();
2182 return_to_top_level (RETURN_QUIT
);
2185 target_terminal_inferior ();
2188 /* If nonzero, ignore the next kill. */
2193 remote_console_output (msg
)
2198 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2201 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2204 fputs_unfiltered (tb
, gdb_stdtarg
);
2208 /* Wait until the remote machine stops, then return,
2209 storing status in STATUS just as `wait' would.
2210 Returns "pid", which in the case of a multi-threaded
2211 remote OS, is the thread-id. */
2214 remote_wait (pid
, status
)
2216 struct target_waitstatus
*status
;
2218 unsigned char *buf
= alloca (PBUFSIZ
);
2219 int thread_num
= -1;
2221 status
->kind
= TARGET_WAITKIND_EXITED
;
2222 status
->value
.integer
= 0;
2228 ofunc
= signal (SIGINT
, remote_interrupt
);
2229 getpkt ((char *) buf
, 1);
2230 signal (SIGINT
, ofunc
);
2232 /* This is a hook for when we need to do something (perhaps the
2233 collection of trace data) every time the target stops. */
2234 if (target_wait_loop_hook
)
2235 (*target_wait_loop_hook
) ();
2239 case 'E': /* Error of some sort */
2240 warning ("Remote failure reply: %s", buf
);
2242 case 'T': /* Status with PC, SP, FP, ... */
2246 char regs
[MAX_REGISTER_RAW_SIZE
];
2248 /* Expedited reply, containing Signal, {regno, reg} repeat */
2249 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2251 n... = register number
2252 r... = register contents
2254 p
= &buf
[3]; /* after Txx */
2261 /* Read the register number */
2262 regno
= strtol ((const char *) p
, &p_temp
, 16);
2263 p1
= (unsigned char *) p_temp
;
2265 if (p1
== p
) /* No register number present here */
2267 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2269 warning ("Malformed packet(a) (missing colon): %s\n\
2272 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2274 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2275 record_currthread (thread_num
);
2276 p
= (unsigned char *) p_temp
;
2284 warning ("Malformed packet(b) (missing colon): %s\n\
2288 if (regno
>= NUM_REGS
)
2289 warning ("Remote sent bad register number %ld: %s\n\
2293 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2295 if (p
[0] == 0 || p
[1] == 0)
2296 warning ("Remote reply is too short: %s", buf
);
2297 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2300 supply_register (regno
, regs
);
2305 warning ("Remote register badly formatted: %s", buf
);
2306 warning (" here: %s", p
);
2311 case 'S': /* Old style status, just signal only */
2312 status
->kind
= TARGET_WAITKIND_STOPPED
;
2313 status
->value
.sig
= (enum target_signal
)
2314 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2318 /* Export Cisco kernel mode as a convenience variable
2319 (so that it can be used in the GDB prompt if desired). */
2321 if (cisco_kernel_mode
== 1)
2322 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2323 value_from_string ("PDEBUG-"));
2324 cisco_kernel_mode
= 0;
2325 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2326 record_currthread (thread_num
);
2328 else if (buf
[3] == 'k')
2330 /* Export Cisco kernel mode as a convenience variable
2331 (so that it can be used in the GDB prompt if desired). */
2333 if (cisco_kernel_mode
== 1)
2334 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2335 value_from_string ("KDEBUG-"));
2336 cisco_kernel_mode
= 1;
2339 case 'N': /* Cisco special: status and offsets */
2341 bfd_vma text_addr
, data_addr
, bss_addr
;
2342 bfd_signed_vma text_off
, data_off
, bss_off
;
2345 status
->kind
= TARGET_WAITKIND_STOPPED
;
2346 status
->value
.sig
= (enum target_signal
)
2347 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2349 if (symfile_objfile
== NULL
)
2351 warning ("Relocation packet recieved with no symbol file. \
2356 /* Relocate object file. Buffer format is NAATT;DD;BB
2357 * where AA is the signal number, TT is the new text
2358 * address, DD * is the new data address, and BB is the
2359 * new bss address. */
2362 text_addr
= strtoul (p
, (char **) &p1
, 16);
2363 if (p1
== p
|| *p1
!= ';')
2364 warning ("Malformed relocation packet: Packet '%s'", buf
);
2366 data_addr
= strtoul (p
, (char **) &p1
, 16);
2367 if (p1
== p
|| *p1
!= ';')
2368 warning ("Malformed relocation packet: Packet '%s'", buf
);
2370 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2372 warning ("Malformed relocation packet: Packet '%s'", buf
);
2374 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2375 &text_off
, &data_off
, &bss_off
)
2377 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2378 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2382 case 'W': /* Target exited */
2384 /* The remote process exited. */
2385 status
->kind
= TARGET_WAITKIND_EXITED
;
2386 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2390 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2391 status
->value
.sig
= (enum target_signal
)
2392 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2396 case 'O': /* Console output */
2397 remote_console_output (buf
+ 1);
2400 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2402 /* Zero length reply means that we tried 'S' or 'C' and
2403 the remote system doesn't support it. */
2404 target_terminal_ours_for_output ();
2406 ("Can't send signals to this remote system. %s not sent.\n",
2407 target_signal_to_name (last_sent_signal
));
2408 last_sent_signal
= TARGET_SIGNAL_0
;
2409 target_terminal_inferior ();
2411 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2412 putpkt ((char *) buf
);
2415 /* else fallthrough */
2417 warning ("Invalid remote reply: %s", buf
);
2422 if (thread_num
!= -1)
2426 return inferior_pid
;
2429 /* Async version of remote_wait. */
2431 remote_async_wait (pid
, status
)
2433 struct target_waitstatus
*status
;
2435 unsigned char *buf
= alloca (PBUFSIZ
);
2436 int thread_num
= -1;
2438 status
->kind
= TARGET_WAITKIND_EXITED
;
2439 status
->value
.integer
= 0;
2446 ofunc
= signal (SIGINT
, remote_interrupt
);
2447 getpkt ((char *) buf
, 1);
2449 signal (SIGINT
, ofunc
);
2451 /* This is a hook for when we need to do something (perhaps the
2452 collection of trace data) every time the target stops. */
2453 if (target_wait_loop_hook
)
2454 (*target_wait_loop_hook
) ();
2458 case 'E': /* Error of some sort */
2459 warning ("Remote failure reply: %s", buf
);
2461 case 'T': /* Status with PC, SP, FP, ... */
2465 char regs
[MAX_REGISTER_RAW_SIZE
];
2467 /* Expedited reply, containing Signal, {regno, reg} repeat */
2468 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2470 n... = register number
2471 r... = register contents
2473 p
= &buf
[3]; /* after Txx */
2480 /* Read the register number */
2481 regno
= strtol ((const char *) p
, &p_temp
, 16);
2482 p1
= (unsigned char *) p_temp
;
2484 if (p1
== p
) /* No register number present here */
2486 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2488 warning ("Malformed packet(a) (missing colon): %s\n\
2491 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2493 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2494 record_currthread (thread_num
);
2495 p
= (unsigned char *) p_temp
;
2503 warning ("Malformed packet(b) (missing colon): %s\n\
2507 if (regno
>= NUM_REGS
)
2508 warning ("Remote sent bad register number %ld: %s\n\
2512 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2514 if (p
[0] == 0 || p
[1] == 0)
2515 warning ("Remote reply is too short: %s", buf
);
2516 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2519 supply_register (regno
, regs
);
2524 warning ("Remote register badly formatted: %s", buf
);
2525 warning (" here: %s", p
);
2530 case 'S': /* Old style status, just signal only */
2531 status
->kind
= TARGET_WAITKIND_STOPPED
;
2532 status
->value
.sig
= (enum target_signal
)
2533 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2537 /* Export Cisco kernel mode as a convenience variable
2538 (so that it can be used in the GDB prompt if desired). */
2540 if (cisco_kernel_mode
== 1)
2541 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2542 value_from_string ("PDEBUG-"));
2543 cisco_kernel_mode
= 0;
2544 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2545 record_currthread (thread_num
);
2547 else if (buf
[3] == 'k')
2549 /* Export Cisco kernel mode as a convenience variable
2550 (so that it can be used in the GDB prompt if desired). */
2552 if (cisco_kernel_mode
== 1)
2553 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2554 value_from_string ("KDEBUG-"));
2555 cisco_kernel_mode
= 1;
2558 case 'N': /* Cisco special: status and offsets */
2560 bfd_vma text_addr
, data_addr
, bss_addr
;
2561 bfd_signed_vma text_off
, data_off
, bss_off
;
2564 status
->kind
= TARGET_WAITKIND_STOPPED
;
2565 status
->value
.sig
= (enum target_signal
)
2566 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2568 if (symfile_objfile
== NULL
)
2570 warning ("Relocation packet recieved with no symbol file. \
2575 /* Relocate object file. Buffer format is NAATT;DD;BB
2576 * where AA is the signal number, TT is the new text
2577 * address, DD * is the new data address, and BB is the
2578 * new bss address. */
2581 text_addr
= strtoul (p
, (char **) &p1
, 16);
2582 if (p1
== p
|| *p1
!= ';')
2583 warning ("Malformed relocation packet: Packet '%s'", buf
);
2585 data_addr
= strtoul (p
, (char **) &p1
, 16);
2586 if (p1
== p
|| *p1
!= ';')
2587 warning ("Malformed relocation packet: Packet '%s'", buf
);
2589 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2591 warning ("Malformed relocation packet: Packet '%s'", buf
);
2593 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2594 &text_off
, &data_off
, &bss_off
)
2596 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2597 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2601 case 'W': /* Target exited */
2603 /* The remote process exited. */
2604 status
->kind
= TARGET_WAITKIND_EXITED
;
2605 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2609 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2610 status
->value
.sig
= (enum target_signal
)
2611 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2615 case 'O': /* Console output */
2616 remote_console_output (buf
+ 1);
2619 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2621 /* Zero length reply means that we tried 'S' or 'C' and
2622 the remote system doesn't support it. */
2623 target_terminal_ours_for_output ();
2625 ("Can't send signals to this remote system. %s not sent.\n",
2626 target_signal_to_name (last_sent_signal
));
2627 last_sent_signal
= TARGET_SIGNAL_0
;
2628 target_terminal_inferior ();
2630 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2631 putpkt ((char *) buf
);
2634 /* else fallthrough */
2636 warning ("Invalid remote reply: %s", buf
);
2641 if (thread_num
!= -1)
2645 return inferior_pid
;
2648 /* Number of bytes of registers this stub implements. */
2650 static int register_bytes_found
;
2652 /* Read the remote registers into the block REGS. */
2653 /* Currently we just read all the registers, so we don't use regno. */
2657 remote_fetch_registers (regno
)
2660 char *buf
= alloca (PBUFSIZ
);
2663 char regs
[REGISTER_BYTES
];
2665 set_thread (inferior_pid
, 1);
2670 if (remote_register_buf_size
== 0)
2671 remote_register_buf_size
= strlen (buf
);
2673 /* Unimplemented registers read as all bits zero. */
2674 memset (regs
, 0, REGISTER_BYTES
);
2676 /* We can get out of synch in various cases. If the first character
2677 in the buffer is not a hex character, assume that has happened
2678 and try to fetch another packet to read. */
2679 while ((buf
[0] < '0' || buf
[0] > '9')
2680 && (buf
[0] < 'a' || buf
[0] > 'f')
2681 && buf
[0] != 'x') /* New: unavailable register value */
2684 fprintf_unfiltered (gdb_stdlog
,
2685 "Bad register packet; fetching a new packet\n");
2689 /* Reply describes registers byte by byte, each byte encoded as two
2690 hex characters. Suck them all up, then supply them to the
2691 register cacheing/storage mechanism. */
2694 for (i
= 0; i
< REGISTER_BYTES
; i
++)
2700 warning ("Remote reply is of odd length: %s", buf
);
2701 /* Don't change register_bytes_found in this case, and don't
2702 print a second warning. */
2705 if (p
[0] == 'x' && p
[1] == 'x')
2706 regs
[i
] = 0; /* 'x' */
2708 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2712 if (i
!= register_bytes_found
)
2714 register_bytes_found
= i
;
2715 #ifdef REGISTER_BYTES_OK
2716 if (!REGISTER_BYTES_OK (i
))
2717 warning ("Remote reply is too short: %s", buf
);
2722 for (i
= 0; i
< NUM_REGS
; i
++)
2724 supply_register (i
, ®s
[REGISTER_BYTE (i
)]);
2725 if (buf
[REGISTER_BYTE (i
) * 2] == 'x')
2726 register_valid
[i
] = -1; /* register value not available */
2730 /* Prepare to store registers. Since we may send them all (using a
2731 'G' request), we have to read out the ones we don't want to change
2735 remote_prepare_to_store ()
2737 /* Make sure the entire registers array is valid. */
2738 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
);
2741 /* Store register REGNO, or all registers if REGNO == -1, from the contents
2742 of REGISTERS. FIXME: ignores errors. */
2745 remote_store_registers (regno
)
2748 char *buf
= alloca (PBUFSIZ
);
2752 set_thread (inferior_pid
, 1);
2754 if (regno
>= 0 && stub_supports_P
)
2756 /* Try storing a single register. */
2759 sprintf (buf
, "P%x=", regno
);
2760 p
= buf
+ strlen (buf
);
2761 regp
= ®isters
[REGISTER_BYTE (regno
)];
2762 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
2764 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
2765 *p
++ = tohex (regp
[i
] & 0xf);
2771 /* The stub understands the 'P' request. We are done. */
2775 /* The stub does not support the 'P' request. Use 'G' instead,
2776 and don't try using 'P' in the future (it will just waste our
2778 stub_supports_P
= 0;
2783 /* Command describes registers byte by byte,
2784 each byte encoded as two hex characters. */
2787 /* remote_prepare_to_store insures that register_bytes_found gets set. */
2788 for (i
= 0; i
< register_bytes_found
; i
++)
2790 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
2791 *p
++ = tohex (registers
[i
] & 0xf);
2798 /* Use of the data cache *used* to be disabled because it loses for looking
2799 at and changing hardware I/O ports and the like. Accepting `volatile'
2800 would perhaps be one way to fix it. Another idea would be to use the
2801 executable file for the text segment (for all SEC_CODE sections?
2802 For all SEC_READONLY sections?). This has problems if you want to
2803 actually see what the memory contains (e.g. self-modifying code,
2804 clobbered memory, user downloaded the wrong thing).
2806 Because it speeds so much up, it's now enabled, if you're playing
2807 with registers you turn it of (set remotecache 0). */
2809 /* Read a word from remote address ADDR and return it.
2810 This goes through the data cache. */
2814 remote_fetch_word (addr
)
2817 return dcache_fetch (remote_dcache
, addr
);
2820 /* Write a word WORD into remote address ADDR.
2821 This goes through the data cache. */
2824 remote_store_word (addr
, word
)
2828 dcache_poke (remote_dcache
, addr
, word
);
2830 #endif /* 0 (unused?) */
2834 /* Return the number of hex digits in num. */
2842 for (i
= 0; num
!= 0; i
++)
2848 /* Set BUF to the hex digits representing NUM. */
2851 hexnumstr (buf
, num
)
2856 int len
= hexnumlen (num
);
2860 for (i
= len
- 1; i
>= 0; i
--)
2862 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
2869 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
2872 remote_address_masked (addr
)
2875 if (remote_address_size
> 0
2876 && remote_address_size
< (sizeof (ULONGEST
) * 8))
2878 /* Only create a mask when that mask can safely be constructed
2879 in a ULONGEST variable. */
2881 mask
= (mask
<< remote_address_size
) - 1;
2887 /* Determine whether the remote target supports binary downloading.
2888 This is accomplished by sending a no-op memory write of zero length
2889 to the target at the specified address. It does not suffice to send
2890 the whole packet, since many stubs strip the eighth bit and subsequently
2891 compute a wrong checksum, which causes real havoc with remote_write_bytes.
2893 NOTE: This can still lose if the serial line is not eight-bit clean. In
2894 cases like this, the user should clear "remotebinarydownload". */
2896 check_binary_download (addr
)
2899 if (remote_binary_download
&& !remote_binary_checked
)
2901 char *buf
= alloca (PBUFSIZ
);
2903 remote_binary_checked
= 1;
2907 p
+= hexnumstr (p
, (ULONGEST
) addr
);
2909 p
+= hexnumstr (p
, (ULONGEST
) 0);
2913 putpkt_binary (buf
, (int) (p
- buf
));
2917 remote_binary_download
= 0;
2922 if (remote_binary_download
)
2923 fprintf_unfiltered (gdb_stdlog
,
2924 "binary downloading suppported by target\n");
2926 fprintf_unfiltered (gdb_stdlog
,
2927 "binary downloading NOT suppported by target\n");
2931 /* Write memory data directly to the remote machine.
2932 This does not inform the data cache; the data cache uses this.
2933 MEMADDR is the address in the remote memory space.
2934 MYADDR is the address of the buffer in our space.
2935 LEN is the number of bytes.
2937 Returns number of bytes transferred, or 0 for error. */
2940 remote_write_bytes (memaddr
, myaddr
, len
)
2945 unsigned char *buf
= alloca (PBUFSIZ
);
2946 int max_buf_size
; /* Max size of packet output buffer */
2949 /* Verify that the target can support a binary download */
2950 check_binary_download (memaddr
);
2952 /* Chop the transfer down if necessary */
2954 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
2955 if (remote_register_buf_size
!= 0)
2956 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
2958 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
2959 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
2964 unsigned char *p
, *plen
;
2968 /* construct "M"<memaddr>","<len>":" */
2969 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
2970 memaddr
= remote_address_masked (memaddr
);
2972 if (remote_binary_download
)
2975 todo
= min (len
, max_buf_size
);
2980 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
2983 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
2986 plen
= p
; /* remember where len field goes */
2987 p
+= hexnumstr (p
, (ULONGEST
) todo
);
2991 /* We send target system values byte by byte, in increasing byte
2992 addresses, each byte encoded as two hex characters (or one
2993 binary character). */
2994 if (remote_binary_download
)
2998 (i
< todo
) && (i
+ escaped
) < (max_buf_size
- 2);
3001 switch (myaddr
[i
] & 0xff)
3006 /* These must be escaped */
3009 *p
++ = (myaddr
[i
] & 0xff) ^ 0x20;
3012 *p
++ = myaddr
[i
] & 0xff;
3019 /* Escape chars have filled up the buffer prematurely,
3020 and we have actually sent fewer bytes than planned.
3021 Fix-up the length field of the packet. */
3023 /* FIXME: will fail if new len is a shorter string than
3026 plen
+= hexnumstr (plen
, (ULONGEST
) i
);
3032 for (i
= 0; i
< todo
; i
++)
3034 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
3035 *p
++ = tohex (myaddr
[i
] & 0xf);
3040 putpkt_binary (buf
, (int) (p
- buf
));
3045 /* There is no correspondance between what the remote protocol uses
3046 for errors and errno codes. We would like a cleaner way of
3047 representing errors (big enough to include errno codes, bfd_error
3048 codes, and others). But for now just return EIO. */
3053 /* Increment by i, not by todo, in case escape chars
3054 caused us to send fewer bytes than we'd planned. */
3062 /* Read memory data directly from the remote machine.
3063 This does not use the data cache; the data cache uses this.
3064 MEMADDR is the address in the remote memory space.
3065 MYADDR is the address of the buffer in our space.
3066 LEN is the number of bytes.
3068 Returns number of bytes transferred, or 0 for error. */
3071 remote_read_bytes (memaddr
, myaddr
, len
)
3076 char *buf
= alloca (PBUFSIZ
);
3077 int max_buf_size
; /* Max size of packet output buffer */
3080 /* Chop the transfer down if necessary */
3082 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
3083 if (remote_register_buf_size
!= 0)
3084 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
3093 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3095 /* construct "m"<memaddr>","<len>" */
3096 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3097 memaddr
= remote_address_masked (memaddr
);
3100 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3102 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3110 /* There is no correspondance between what the remote protocol uses
3111 for errors and errno codes. We would like a cleaner way of
3112 representing errors (big enough to include errno codes, bfd_error
3113 codes, and others). But for now just return EIO. */
3118 /* Reply describes memory byte by byte,
3119 each byte encoded as two hex characters. */
3122 for (i
= 0; i
< todo
; i
++)
3124 if (p
[0] == 0 || p
[1] == 0)
3125 /* Reply is short. This means that we were able to read
3126 only part of what we wanted to. */
3127 return i
+ (origlen
- len
);
3128 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3138 /* Read or write LEN bytes from inferior memory at MEMADDR,
3139 transferring to or from debugger address BUFFER. Write to inferior if
3140 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3143 #ifndef REMOTE_TRANSLATE_XFER_ADDRESS
3144 #define REMOTE_TRANSLATE_XFER_ADDRESS(MEM_ADDR, MEM_LEN, TARG_ADDR, TARG_LEN) \
3145 (*(TARG_ADDR) = (MEM_ADDR), *(TARG_LEN) = (MEM_LEN))
3150 remote_xfer_memory (mem_addr
, buffer
, mem_len
, should_write
, target
)
3155 struct target_ops
*target
; /* ignored */
3157 CORE_ADDR targ_addr
;
3159 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3163 return dcache_xfer_memory (remote_dcache
, targ_addr
, buffer
,
3164 targ_len
, should_write
);
3169 /* Enable after 4.12. */
3172 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
3173 addr_found
, data_found
)
3177 CORE_ADDR startaddr
;
3181 CORE_ADDR
*addr_found
;
3184 if (increment
== -4 && len
== 4)
3186 long mask_long
, data_long
;
3187 long data_found_long
;
3188 CORE_ADDR addr_we_found
;
3189 char *buf
= alloca (PBUFSIZ
);
3190 long returned_long
[2];
3193 mask_long
= extract_unsigned_integer (mask
, len
);
3194 data_long
= extract_unsigned_integer (data
, len
);
3195 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
3200 /* The stub doesn't support the 't' request. We might want to
3201 remember this fact, but on the other hand the stub could be
3202 switched on us. Maybe we should remember it only until
3203 the next "target remote". */
3204 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3205 hirange
, addr_found
, data_found
);
3210 /* There is no correspondance between what the remote protocol uses
3211 for errors and errno codes. We would like a cleaner way of
3212 representing errors (big enough to include errno codes, bfd_error
3213 codes, and others). But for now just use EIO. */
3214 memory_error (EIO
, startaddr
);
3217 while (*p
!= '\0' && *p
!= ',')
3218 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
3220 error ("Protocol error: short return for search");
3222 data_found_long
= 0;
3223 while (*p
!= '\0' && *p
!= ',')
3224 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
3225 /* Ignore anything after this comma, for future extensions. */
3227 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
3233 *addr_found
= addr_we_found
;
3234 *data_found
= store_unsigned_integer (data_we_found
, len
);
3237 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3238 hirange
, addr_found
, data_found
);
3243 remote_files_info (ignore
)
3244 struct target_ops
*ignore
;
3246 puts_filtered ("Debugging a target over a serial line.\n");
3249 /* Stuff for dealing with the packets which are part of this protocol.
3250 See comment at top of file for details. */
3252 /* Read a single character from the remote end, masking it down to 7 bits. */
3260 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
3265 error ("Remote connection closed");
3267 perror_with_name ("Remote communication error");
3268 case SERIAL_TIMEOUT
:
3275 /* Send the command in BUF to the remote machine, and read the reply
3276 into BUF. Report an error if we get an error reply. */
3286 error ("Remote failure reply: %s", buf
);
3289 /* Display a null-terminated packet on stdout, for debugging, using C
3296 puts_filtered ("\"");
3297 fputstr_filtered (buf
, '"', gdb_stdout
);
3298 puts_filtered ("\"");
3305 return putpkt_binary (buf
, strlen (buf
));
3308 /* Send a packet to the remote machine, with error checking. The data
3309 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3310 to account for the $, # and checksum, and for a possible /0 if we are
3311 debugging (remote_debug) and want to print the sent packet as a string */
3314 putpkt_binary (buf
, cnt
)
3319 unsigned char csum
= 0;
3320 char *buf2
= alloca (PBUFSIZ
);
3321 char *junkbuf
= alloca (PBUFSIZ
);
3327 /* Copy the packet into buffer BUF2, encapsulating it
3328 and giving it a checksum. */
3330 if (cnt
> BUFSIZ
- 5) /* Prosanity check */
3336 for (i
= 0; i
< cnt
; i
++)
3342 *p
++ = tohex ((csum
>> 4) & 0xf);
3343 *p
++ = tohex (csum
& 0xf);
3345 /* Send it over and over until we get a positive ack. */
3349 int started_error_output
= 0;
3354 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
3355 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
3356 fprintf_unfiltered (gdb_stdlog
, "...", buf2
);
3357 gdb_flush (gdb_stdlog
);
3359 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
3360 perror_with_name ("putpkt: write failed");
3362 /* read until either a timeout occurs (-2) or '+' is read */
3365 ch
= readchar (remote_timeout
);
3372 case SERIAL_TIMEOUT
:
3374 if (started_error_output
)
3376 putchar_unfiltered ('\n');
3377 started_error_output
= 0;
3386 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
3388 case SERIAL_TIMEOUT
:
3392 break; /* Retransmit buffer */
3395 /* It's probably an old response, and we're out of sync.
3396 Just gobble up the packet and ignore it. */
3397 getpkt (junkbuf
, 0);
3398 continue; /* Now, go look for + */
3403 if (!started_error_output
)
3405 started_error_output
= 1;
3406 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
3408 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
3412 break; /* Here to retransmit */
3416 /* This is wrong. If doing a long backtrace, the user should be
3417 able to get out next time we call QUIT, without anything as
3418 violent as interrupt_query. If we want to provide a way out of
3419 here without getting to the next QUIT, it should be based on
3420 hitting ^C twice as in remote_wait. */
3430 static int remote_cisco_mode
;
3433 remote_cisco_expand (src
, dest
)
3444 repeat
= (fromhex (src
[1]) << 4) + fromhex (src
[2]);
3445 for (i
= 0; i
< repeat
; i
++)
3447 *dest
++ = *(src
- 1);
3459 /* Come here after finding the start of the frame. Collect the rest
3460 into BUF, verifying the checksum, length, and handling run-length
3461 compression. Returns 0 on any error, 1 on success. */
3476 c
= readchar (remote_timeout
);
3480 case SERIAL_TIMEOUT
:
3482 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
3486 fputs_filtered ("Saw new packet start in middle of old one\n",
3488 return 0; /* Start a new packet, count retries */
3491 unsigned char pktcsum
;
3495 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
3496 pktcsum
|= fromhex (readchar (remote_timeout
));
3498 if (csum
== pktcsum
)
3500 if (remote_cisco_mode
) /* variant run-length-encoding */
3502 char *tmp_buf
= alloca (PBUFSIZ
);
3504 remote_cisco_expand (buf
, tmp_buf
);
3505 strcpy (buf
, tmp_buf
);
3512 fprintf_filtered (gdb_stdlog
,
3513 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3515 fputs_filtered (buf
, gdb_stdlog
);
3516 fputs_filtered ("\n", gdb_stdlog
);
3520 case '*': /* Run length encoding */
3521 if (remote_cisco_mode
== 0) /* variant run-length-encoding */
3524 c
= readchar (remote_timeout
);
3526 c
= c
- ' ' + 3; /* Compute repeat count */
3528 if (c
> 0 && c
< 255 && bp
+ c
- 1 < buf
+ PBUFSIZ
- 1)
3530 memset (bp
, *(bp
- 1), c
);
3536 printf_filtered ("Repeat count %d too large for buffer: ", c
);
3537 puts_filtered (buf
);
3538 puts_filtered ("\n");
3541 /* else fall thru to treat like default */
3543 if (bp
< buf
+ PBUFSIZ
- 1)
3551 puts_filtered ("Remote packet too long: ");
3552 puts_filtered (buf
);
3553 puts_filtered ("\n");
3560 /* Read a packet from the remote machine, with error checking, and
3561 store it in BUF. BUF is expected to be of size PBUFSIZ. If
3562 FOREVER, wait forever rather than timing out; this is used while
3563 the target is executing user code. */
3566 getpkt (buf
, forever
)
3575 strcpy (buf
, "timeout");
3579 timeout
= watchdog
> 0 ? watchdog
: -1;
3583 timeout
= remote_timeout
;
3587 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
3589 /* This can loop forever if the remote side sends us characters
3590 continuously, but if it pauses, we'll get a zero from readchar
3591 because of timeout. Then we'll count that as a retry. */
3593 /* Note that we will only wait forever prior to the start of a packet.
3594 After that, we expect characters to arrive at a brisk pace. They
3595 should show up within remote_timeout intervals. */
3599 c
= readchar (timeout
);
3601 if (c
== SERIAL_TIMEOUT
)
3603 if (forever
) /* Watchdog went off. Kill the target. */
3605 target_mourn_inferior ();
3606 error ("Watchdog has expired. Target detached.\n");
3609 fputs_filtered ("Timed out.\n", gdb_stdlog
);
3615 /* We've found the start of a packet, now collect the data. */
3617 val
= read_frame (buf
);
3623 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
3624 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
3625 fprintf_unfiltered (gdb_stdlog
, "\n");
3627 SERIAL_WRITE (remote_desc
, "+", 1);
3631 /* Try the whole thing again. */
3633 SERIAL_WRITE (remote_desc
, "-", 1);
3636 /* We have tried hard enough, and just can't receive the packet. Give up. */
3638 printf_unfiltered ("Ignoring packet error, continuing...\n");
3639 SERIAL_WRITE (remote_desc
, "+", 1);
3645 /* For some mysterious reason, wait_for_inferior calls kill instead of
3646 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3650 target_mourn_inferior ();
3654 /* Use catch_errors so the user can quit from gdb even when we aren't on
3655 speaking terms with the remote system. */
3656 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
3658 /* Don't wait for it to die. I'm not really sure it matters whether
3659 we do or not. For the existing stubs, kill is a noop. */
3660 target_mourn_inferior ();
3663 /* Async version of remote_kill. */
3665 remote_async_kill ()
3667 /* Unregister the file descriptor from the event loop. */
3669 delete_file_handler (remote_desc
->fd
);
3671 /* For some mysterious reason, wait_for_inferior calls kill instead of
3672 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3676 target_mourn_inferior ();
3680 /* Use catch_errors so the user can quit from gdb even when we aren't on
3681 speaking terms with the remote system. */
3682 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
3684 /* Don't wait for it to die. I'm not really sure it matters whether
3685 we do or not. For the existing stubs, kill is a noop. */
3686 target_mourn_inferior ();
3692 remote_mourn_1 (&remote_ops
);
3696 extended_remote_mourn ()
3698 /* We do _not_ want to mourn the target like this; this will
3699 remove the extended remote target from the target stack,
3700 and the next time the user says "run" it'll fail.
3702 FIXME: What is the right thing to do here? */
3704 remote_mourn_1 (&extended_remote_ops
);
3708 /* Worker function for remote_mourn. */
3710 remote_mourn_1 (target
)
3711 struct target_ops
*target
;
3713 unpush_target (target
);
3714 generic_mourn_inferior ();
3717 /* In the extended protocol we want to be able to do things like
3718 "run" and have them basically work as expected. So we need
3719 a special create_inferior function.
3721 FIXME: One day add support for changing the exec file
3722 we're debugging, arguments and an environment. */
3725 extended_remote_create_inferior (exec_file
, args
, env
)
3730 /* Rip out the breakpoints; we'll reinsert them after restarting
3731 the remote server. */
3732 remove_breakpoints ();
3734 /* Now restart the remote server. */
3735 extended_remote_restart ();
3737 /* Now put the breakpoints back in. This way we're safe if the
3738 restart function works via a unix fork on the remote side. */
3739 insert_breakpoints ();
3741 /* Clean up from the last time we were running. */
3742 clear_proceed_status ();
3744 /* Let the remote process run. */
3745 proceed (-1, TARGET_SIGNAL_0
, 0);
3748 /* Async version of extended_remote_create_inferior. */
3750 extended_remote_async_create_inferior (exec_file
, args
, env
)
3755 /* Rip out the breakpoints; we'll reinsert them after restarting
3756 the remote server. */
3757 remove_breakpoints ();
3759 /* If running asynchronously, register the target file descriptor
3760 with the event loop. */
3762 add_file_handler (remote_desc
->fd
, (file_handler_func
*) fetch_inferior_event
, 0);
3764 /* Now restart the remote server. */
3765 extended_remote_restart ();
3767 /* Now put the breakpoints back in. This way we're safe if the
3768 restart function works via a unix fork on the remote side. */
3769 insert_breakpoints ();
3771 /* Clean up from the last time we were running. */
3772 clear_proceed_status ();
3774 /* Let the remote process run. */
3775 proceed (-1, TARGET_SIGNAL_0
, 0);
3779 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
3780 than other targets; in those use REMOTE_BREAKPOINT instead of just
3781 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
3782 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
3783 the standard routines that are in mem-break.c. */
3785 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
3786 the choice of breakpoint instruction affects target program design and
3787 vice versa, and by making it user-tweakable, the special code here
3788 goes away and we need fewer special GDB configurations. */
3790 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
3791 #define REMOTE_BREAKPOINT
3794 #ifdef REMOTE_BREAKPOINT
3796 /* If the target isn't bi-endian, just pretend it is. */
3797 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
3798 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3799 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3802 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
3803 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
3805 #endif /* REMOTE_BREAKPOINT */
3807 /* Insert a breakpoint on targets that don't have any better breakpoint
3808 support. We read the contents of the target location and stash it,
3809 then overwrite it with a breakpoint instruction. ADDR is the target
3810 location in the target machine. CONTENTS_CACHE is a pointer to
3811 memory allocated for saving the target contents. It is guaranteed
3812 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
3813 is accomplished via BREAKPOINT_MAX). */
3816 remote_insert_breakpoint (addr
, contents_cache
)
3818 char *contents_cache
;
3820 #ifdef REMOTE_BREAKPOINT
3823 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
3827 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
3828 val
= target_write_memory (addr
, (char *) big_break_insn
,
3829 sizeof big_break_insn
);
3831 val
= target_write_memory (addr
, (char *) little_break_insn
,
3832 sizeof little_break_insn
);
3837 return memory_insert_breakpoint (addr
, contents_cache
);
3838 #endif /* REMOTE_BREAKPOINT */
3842 remote_remove_breakpoint (addr
, contents_cache
)
3844 char *contents_cache
;
3846 #ifdef REMOTE_BREAKPOINT
3847 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
3849 return memory_remove_breakpoint (addr
, contents_cache
);
3850 #endif /* REMOTE_BREAKPOINT */
3853 /* Some targets are only capable of doing downloads, and afterwards
3854 they switch to the remote serial protocol. This function provides
3855 a clean way to get from the download target to the remote target.
3856 It's basically just a wrapper so that we don't have to expose any
3857 of the internal workings of remote.c.
3859 Prior to calling this routine, you should shutdown the current
3860 target code, else you will get the "A program is being debugged
3861 already..." message. Usually a call to pop_target() suffices. */
3864 push_remote_target (name
, from_tty
)
3868 printf_filtered ("Switching to remote protocol\n");
3869 remote_open (name
, from_tty
);
3872 /* Other targets want to use the entire remote serial module but with
3873 certain remote_ops overridden. */
3876 open_remote_target (name
, from_tty
, target
, extended_p
)
3879 struct target_ops
*target
;
3882 printf_filtered ("Selecting the %sremote protocol\n",
3883 (extended_p
? "extended-" : ""));
3884 remote_open_1 (name
, from_tty
, target
, extended_p
);
3887 /* Table used by the crc32 function to calcuate the checksum. */
3889 static unsigned long crc32_table
[256] =
3892 static unsigned long
3893 crc32 (buf
, len
, crc
)
3898 if (!crc32_table
[1])
3900 /* Initialize the CRC table and the decoding table. */
3904 for (i
= 0; i
< 256; i
++)
3906 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
3907 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
3914 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
3920 /* compare-sections command
3922 With no arguments, compares each loadable section in the exec bfd
3923 with the same memory range on the target, and reports mismatches.
3924 Useful for verifying the image on the target against the exec file.
3925 Depends on the target understanding the new "qCRC:" request. */
3928 compare_sections_command (args
, from_tty
)
3933 unsigned long host_crc
, target_crc
;
3934 extern bfd
*exec_bfd
;
3935 struct cleanup
*old_chain
;
3939 char *buf
= alloca (PBUFSIZ
);
3946 error ("command cannot be used without an exec file");
3947 if (!current_target
.to_shortname
||
3948 strcmp (current_target
.to_shortname
, "remote") != 0)
3949 error ("command can only be used with remote target");
3951 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
3953 if (!(s
->flags
& SEC_LOAD
))
3954 continue; /* skip non-loadable section */
3956 size
= bfd_get_section_size_before_reloc (s
);
3958 continue; /* skip zero-length section */
3960 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
3961 if (args
&& strcmp (args
, sectname
) != 0)
3962 continue; /* not the section selected by user */
3964 matched
= 1; /* do this section */
3966 /* FIXME: assumes lma can fit into long */
3967 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
3970 /* be clever; compute the host_crc before waiting for target reply */
3971 sectdata
= xmalloc (size
);
3972 old_chain
= make_cleanup (free
, sectdata
);
3973 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
3974 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
3978 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
3979 sectname
, lma
, lma
+ size
);
3981 error ("remote target does not support this operation");
3983 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
3984 target_crc
= target_crc
* 16 + fromhex (*tmp
);
3986 printf_filtered ("Section %s, range 0x%08x -- 0x%08x: ",
3987 sectname
, lma
, lma
+ size
);
3988 if (host_crc
== target_crc
)
3989 printf_filtered ("matched.\n");
3992 printf_filtered ("MIS-MATCHED!\n");
3996 do_cleanups (old_chain
);
3999 warning ("One or more sections of the remote executable does not match\n\
4000 the loaded file\n");
4001 if (args
&& !matched
)
4002 printf_filtered ("No loaded section named '%s'.\n", args
);
4006 remote_query (query_type
, buf
, outbuf
, bufsiz
)
4013 char *buf2
= alloca (PBUFSIZ
);
4014 char *p2
= &buf2
[0];
4018 error ("null pointer to remote bufer size specified");
4020 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4021 the caller know and return what the minimum size is */
4022 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4023 if (*bufsiz
< PBUFSIZ
)
4029 /* except for querying the minimum buffer size, target must be open */
4031 error ("remote query is only available after target open");
4033 /* we only take uppercase letters as query types, at least for now */
4034 if ((query_type
< 'A') || (query_type
> 'Z'))
4035 error ("invalid remote query type");
4038 error ("null remote query specified");
4041 error ("remote query requires a buffer to receive data");
4048 /* we used one buffer char for the remote protocol q command and another
4049 for the query type. As the remote protocol encapsulation uses 4 chars
4050 plus one extra in case we are debugging (remote_debug),
4051 we have PBUFZIZ - 7 left to pack the query string */
4053 while (buf
[i
] && (i
< (PBUFSIZ
- 8)))
4055 /* bad caller may have sent forbidden characters */
4056 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
4057 error ("illegal characters in query string");
4065 error ("query larger than available buffer");
4077 packet_command (args
, from_tty
)
4081 char *buf
= alloca (PBUFSIZ
);
4084 error ("command can only be used with remote target");
4087 error ("remote-packet command requires packet text as argument");
4089 puts_filtered ("sending: ");
4090 print_packet (args
);
4091 puts_filtered ("\n");
4095 puts_filtered ("received: ");
4097 puts_filtered ("\n");
4101 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4103 static void display_thread_info
PARAMS ((struct gdb_ext_thread_info
* info
));
4105 static void threadset_test_cmd
PARAMS ((char *cmd
, int tty
));
4107 static void threadalive_test
PARAMS ((char *cmd
, int tty
));
4109 static void threadlist_test_cmd
PARAMS ((char *cmd
, int tty
));
4111 int get_and_display_threadinfo
PARAMS ((threadref
* ref
));
4113 static void threadinfo_test_cmd
PARAMS ((char *cmd
, int tty
));
4115 static int thread_display_step
PARAMS ((threadref
* ref
, void *context
));
4117 static void threadlist_update_test_cmd
PARAMS ((char *cmd
, int tty
));
4119 static void init_remote_threadtests
PARAMS ((void));
4121 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4124 threadset_test_cmd (cmd
, tty
)
4128 int sample_thread
= SAMPLE_THREAD
;
4130 printf_filtered ("Remote threadset test\n");
4131 set_thread (sample_thread
, 1);
4136 threadalive_test (cmd
, tty
)
4140 int sample_thread
= SAMPLE_THREAD
;
4142 if (remote_thread_alive (sample_thread
))
4143 printf_filtered ("PASS: Thread alive test\n");
4145 printf_filtered ("FAIL: Thread alive test\n");
4148 void output_threadid
PARAMS ((char *title
, threadref
* ref
));
4151 output_threadid (title
, ref
)
4157 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
4159 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
4163 threadlist_test_cmd (cmd
, tty
)
4168 threadref nextthread
;
4169 int done
, result_count
;
4170 threadref threadlist
[3];
4172 printf_filtered ("Remote Threadlist test\n");
4173 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
4174 &result_count
, &threadlist
[0]))
4175 printf_filtered ("FAIL: threadlist test\n");
4178 threadref
*scan
= threadlist
;
4179 threadref
*limit
= scan
+ result_count
;
4181 while (scan
< limit
)
4182 output_threadid (" thread ", scan
++);
4187 display_thread_info (info
)
4188 struct gdb_ext_thread_info
*info
;
4190 output_threadid ("Threadid: ", &info
->threadid
);
4191 printf_filtered ("Name: %s\n ", info
->shortname
);
4192 printf_filtered ("State: %s\n", info
->display
);
4193 printf_filtered ("other: %s\n\n", info
->more_display
);
4197 get_and_display_threadinfo (ref
)
4202 struct gdb_ext_thread_info threadinfo
;
4204 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
4205 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
4206 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
4207 display_thread_info (&threadinfo
);
4212 threadinfo_test_cmd (cmd
, tty
)
4216 int athread
= SAMPLE_THREAD
;
4220 int_to_threadref (&thread
, athread
);
4221 printf_filtered ("Remote Threadinfo test\n");
4222 if (!get_and_display_threadinfo (&thread
))
4223 printf_filtered ("FAIL cannot get thread info\n");
4227 thread_display_step (ref
, context
)
4231 /* output_threadid(" threadstep ",ref); *//* simple test */
4232 return get_and_display_threadinfo (ref
);
4236 threadlist_update_test_cmd (cmd
, tty
)
4240 printf_filtered ("Remote Threadlist update test\n");
4241 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
4245 init_remote_threadtests (void)
4247 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
4248 "Fetch and print the remote list of thread identifiers, one pkt only");
4249 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
4250 "Fetch and display info about one thread");
4251 add_com ("tset", class_obscure
, threadset_test_cmd
,
4252 "Test setting to a different thread");
4253 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
4254 "Iterate through updating all remote thread info");
4255 add_com ("talive", class_obscure
, threadalive_test
,
4256 " Remote thread alive test ");
4264 remote_ops
.to_shortname
= "remote";
4265 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
4267 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4268 Specify the serial device it is connected to (e.g. /dev/ttya).";
4269 remote_ops
.to_open
= remote_open
;
4270 remote_ops
.to_close
= remote_close
;
4271 remote_ops
.to_detach
= remote_detach
;
4272 remote_ops
.to_resume
= remote_resume
;
4273 remote_ops
.to_wait
= remote_wait
;
4274 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
4275 remote_ops
.to_store_registers
= remote_store_registers
;
4276 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
4277 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
4278 remote_ops
.to_files_info
= remote_files_info
;
4279 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
4280 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
4281 remote_ops
.to_kill
= remote_kill
;
4282 remote_ops
.to_load
= generic_load
;
4283 remote_ops
.to_mourn_inferior
= remote_mourn
;
4284 remote_ops
.to_thread_alive
= remote_thread_alive
;
4285 remote_ops
.to_find_new_threads
= remote_threads_info
;
4286 remote_ops
.to_stop
= remote_stop
;
4287 remote_ops
.to_query
= remote_query
;
4288 remote_ops
.to_stratum
= process_stratum
;
4289 remote_ops
.to_has_all_memory
= 1;
4290 remote_ops
.to_has_memory
= 1;
4291 remote_ops
.to_has_stack
= 1;
4292 remote_ops
.to_has_registers
= 1;
4293 remote_ops
.to_has_execution
= 1;
4294 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
4295 remote_ops
.to_magic
= OPS_MAGIC
;
4298 /* Set up the extended remote vector by making a copy of the standard
4299 remote vector and adding to it. */
4302 init_extended_remote_ops ()
4304 extended_remote_ops
= remote_ops
;
4306 extended_remote_ops
.to_shortname
= "extended-remote";
4307 extended_remote_ops
.to_longname
=
4308 "Extended remote serial target in gdb-specific protocol";
4309 extended_remote_ops
.to_doc
=
4310 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4311 Specify the serial device it is connected to (e.g. /dev/ttya).",
4312 extended_remote_ops
.to_open
= extended_remote_open
;
4313 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
4314 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
4318 * Command: info remote-process
4320 * This implements Cisco's version of the "info proc" command.
4322 * This query allows the target stub to return an arbitrary string
4323 * (or strings) giving arbitrary information about the target process.
4324 * This is optional; the target stub isn't required to implement it.
4326 * Syntax: qfProcessInfo request first string
4327 * qsProcessInfo request subsequent string
4328 * reply: 'O'<hex-encoded-string>
4329 * 'l' last reply (empty)
4333 remote_info_process (args
, from_tty
)
4337 char *buf
= alloca (PBUFSIZ
);
4339 if (remote_desc
== 0)
4340 error ("Command can only be used when connected to the remote target.");
4342 putpkt ("qfProcessInfo");
4345 return; /* Silently: target does not support this feature. */
4348 error ("info proc: target error.");
4350 while (buf
[0] == 'O') /* Capitol-O packet */
4352 remote_console_output (&buf
[1]);
4353 putpkt ("qsProcessInfo");
4363 remote_cisco_open (name
, from_tty
)
4369 "To open a remote debug connection, you need to specify what \n\
4370 device is attached to the remote system (e.g. host:port).");
4372 target_preopen (from_tty
);
4374 unpush_target (&remote_cisco_ops
);
4376 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
4378 remote_desc
= SERIAL_OPEN (name
);
4380 perror_with_name (name
);
4383 * If a baud rate was specified on the gdb command line it will
4384 * be greater than the initial value of -1. If it is, use it otherwise
4388 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
4389 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
4391 SERIAL_CLOSE (remote_desc
);
4392 perror_with_name (name
);
4395 SERIAL_RAW (remote_desc
);
4397 /* If there is something sitting in the buffer we might take it as a
4398 response to a command, which would be bad. */
4399 SERIAL_FLUSH_INPUT (remote_desc
);
4403 puts_filtered ("Remote debugging using ");
4404 puts_filtered (name
);
4405 puts_filtered ("\n");
4408 remote_cisco_mode
= 1;
4410 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
4412 /* Start out by trying the 'P' request to set registers. We set this each
4413 time that we open a new target so that if the user switches from one
4414 stub to another, we can (if the target is closed and reopened) cope. */
4415 stub_supports_P
= 1;
4417 general_thread
= -2;
4418 continue_thread
= -2;
4420 /* Force remote_write_bytes to check whether target supports
4421 binary downloading. */
4422 remote_binary_checked
= 0;
4424 /* Without this, some commands which require an active target (such
4425 as kill) won't work. This variable serves (at least) double duty
4426 as both the pid of the target process (if it has such), and as a
4427 flag indicating that a target is active. These functions should
4428 be split out into seperate variables, especially since GDB will
4429 someday have a notion of debugging several processes. */
4430 inferior_pid
= MAGIC_NULL_PID
;
4432 /* Start the remote connection; if error (0), discard this target. */
4434 if (!catch_errors (remote_start_remote_dummy
, (char *) 0,
4435 "Couldn't establish connection to remote target\n",
4444 remote_cisco_close (quitting
)
4447 remote_cisco_mode
= 0;
4448 remote_close (quitting
);
4455 remote_mourn_1 (&remote_cisco_ops
);
4467 /* shared between readsocket() and readtty() */
4468 static char *tty_input
;
4470 static int escape_count
;
4471 static int echo_check
;
4472 extern int quit_flag
;
4479 /* Loop until the socket doesn't have any more data */
4481 while ((data
= readchar (0)) >= 0)
4483 /* Check for the escape sequence */
4486 /* If this is the fourth escape, get out */
4487 if (++escape_count
== 4)
4492 { /* This is a '|', but not the fourth in a row.
4493 Continue without echoing it. If it isn't actually
4494 one of four in a row, it'll be echoed later. */
4501 /* Ensure any pending '|'s are flushed. */
4503 for (; escape_count
> 0; escape_count
--)
4507 if (data
== '\r') /* If this is a return character, */
4508 continue; /* - just supress it. */
4510 if (echo_check
!= -1) /* Check for echo of user input. */
4512 if (tty_input
[echo_check
] == data
)
4514 echo_check
++; /* Character matched user input: */
4515 continue; /* Continue without echoing it. */
4517 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
4518 { /* End of the line (and of echo checking). */
4519 echo_check
= -1; /* No more echo supression */
4520 continue; /* Continue without echoing. */
4523 { /* Failed check for echo of user input.
4524 We now have some suppressed output to flush! */
4527 for (j
= 0; j
< echo_check
; j
++)
4528 putchar (tty_input
[j
]);
4532 putchar (data
); /* Default case: output the char. */
4535 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
4536 return READ_MORE
; /* Try to read some more */
4538 return FATAL_ERROR
; /* Trouble, bail out */
4547 /* First, read a buffer full from the terminal */
4548 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
4549 if (tty_bytecount
== -1)
4551 perror ("readtty: read failed");
4555 /* Remove a quoted newline. */
4556 if (tty_input
[tty_bytecount
- 1] == '\n' &&
4557 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
4559 tty_input
[--tty_bytecount
] = 0; /* remove newline */
4560 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
4563 /* Turn trailing newlines into returns */
4564 if (tty_input
[tty_bytecount
- 1] == '\n')
4565 tty_input
[tty_bytecount
- 1] = '\r';
4567 /* If the line consists of a ~, enter debugging mode. */
4568 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
4571 /* Make this a zero terminated string and write it out */
4572 tty_input
[tty_bytecount
] = 0;
4573 if (SERIAL_WRITE (remote_desc
, tty_input
, tty_bytecount
))
4575 perror_with_name ("readtty: write failed");
4585 fd_set input
; /* file descriptors for select */
4586 int tablesize
; /* max number of FDs for select */
4590 extern int escape_count
; /* global shared by readsocket */
4591 extern int echo_check
; /* ditto */
4596 tablesize
= 8 * sizeof (input
);
4600 /* Check for anything from our socket - doesn't block. Note that
4601 this must be done *before* the select as there may be
4602 buffered I/O waiting to be processed. */
4604 if ((status
= readsocket ()) == FATAL_ERROR
)
4606 error ("Debugging terminated by communications error");
4608 else if (status
!= READ_MORE
)
4613 fflush (stdout
); /* Flush output before blocking */
4615 /* Now block on more socket input or TTY input */
4618 FD_SET (fileno (stdin
), &input
);
4619 FD_SET (remote_desc
->fd
, &input
);
4621 status
= select (tablesize
, &input
, 0, 0, 0);
4622 if ((status
== -1) && (errno
!= EINTR
))
4624 error ("Communications error on select %d", errno
);
4627 /* Handle Control-C typed */
4631 if ((++quit_count
) == 2)
4633 if (query ("Interrupt GDB? "))
4635 printf_filtered ("Interrupted by user.\n");
4636 return_to_top_level (RETURN_QUIT
);
4643 SERIAL_SEND_BREAK (remote_desc
);
4645 SERIAL_WRITE (remote_desc
, "\003", 1);
4650 /* Handle console input */
4652 if (FD_ISSET (fileno (stdin
), &input
))
4656 status
= readtty ();
4657 if (status
== READ_MORE
)
4660 return status
; /* telnet session ended */
4666 remote_cisco_wait (pid
, status
)
4668 struct target_waitstatus
*status
;
4670 if (minitelnet () != ENTER_DEBUG
)
4672 error ("Debugging session terminated by protocol error");
4675 return remote_wait (pid
, status
);
4679 init_remote_cisco_ops ()
4681 remote_cisco_ops
.to_shortname
= "cisco";
4682 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
4683 remote_cisco_ops
.to_doc
=
4684 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
4685 Specify the serial device it is connected to (e.g. host:2020).";
4686 remote_cisco_ops
.to_open
= remote_cisco_open
;
4687 remote_cisco_ops
.to_close
= remote_cisco_close
;
4688 remote_cisco_ops
.to_detach
= remote_detach
;
4689 remote_cisco_ops
.to_resume
= remote_resume
;
4690 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
4691 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
4692 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
4693 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
4694 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
4695 remote_cisco_ops
.to_files_info
= remote_files_info
;
4696 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
4697 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
4698 remote_cisco_ops
.to_kill
= remote_kill
;
4699 remote_cisco_ops
.to_load
= generic_load
;
4700 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
4701 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
4702 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
4703 remote_cisco_ops
.to_stratum
= process_stratum
;
4704 remote_cisco_ops
.to_has_all_memory
= 1;
4705 remote_cisco_ops
.to_has_memory
= 1;
4706 remote_cisco_ops
.to_has_stack
= 1;
4707 remote_cisco_ops
.to_has_registers
= 1;
4708 remote_cisco_ops
.to_has_execution
= 1;
4709 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
4712 /* Target async and target extended-async.
4714 This are temporary targets, until it is all tested. Eventually
4715 async support will be incorporated int the usual 'remote'
4719 init_remote_async_ops ()
4721 remote_async_ops
.to_shortname
= "async";
4722 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
4723 remote_async_ops
.to_doc
=
4724 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4725 Specify the serial device it is connected to (e.g. /dev/ttya).";
4726 remote_async_ops
.to_open
= remote_async_open
;
4727 remote_async_ops
.to_close
= remote_close
;
4728 remote_async_ops
.to_detach
= remote_async_detach
;
4729 remote_async_ops
.to_resume
= remote_async_resume
;
4730 remote_async_ops
.to_wait
= remote_async_wait
;
4731 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
4732 remote_async_ops
.to_store_registers
= remote_store_registers
;
4733 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
4734 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
4735 remote_async_ops
.to_files_info
= remote_files_info
;
4736 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
4737 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
4738 remote_async_ops
.to_kill
= remote_async_kill
;
4739 remote_async_ops
.to_load
= generic_load
;
4740 remote_async_ops
.to_mourn_inferior
= remote_mourn
;
4741 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
4742 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
4743 remote_async_ops
.to_stop
= remote_stop
;
4744 remote_async_ops
.to_query
= remote_query
;
4745 remote_async_ops
.to_stratum
= process_stratum
;
4746 remote_async_ops
.to_has_all_memory
= 1;
4747 remote_async_ops
.to_has_memory
= 1;
4748 remote_async_ops
.to_has_stack
= 1;
4749 remote_async_ops
.to_has_registers
= 1;
4750 remote_async_ops
.to_has_execution
= 1;
4751 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
4752 remote_async_ops
.to_has_async_exec
= 1;
4753 remote_async_ops
.to_magic
= OPS_MAGIC
;
4756 /* Set up the async extended remote vector by making a copy of the standard
4757 remote vector and adding to it. */
4760 init_extended_async_remote_ops ()
4762 extended_async_remote_ops
= remote_async_ops
;
4764 extended_async_remote_ops
.to_shortname
= "extended-async";
4765 extended_async_remote_ops
.to_longname
=
4766 "Extended remote serial target in async gdb-specific protocol";
4767 extended_async_remote_ops
.to_doc
=
4768 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
4769 Specify the serial device it is connected to (e.g. /dev/ttya).",
4770 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
4771 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
4772 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
4776 build_remote_gdbarch_data ()
4778 tty_input
= xmalloc (PBUFSIZ
);
4782 _initialize_remote ()
4784 /* architecture specific data */
4785 build_remote_gdbarch_data ();
4786 register_gdbarch_swap (&tty_input
, sizeof (&tty_input
), NULL
);
4787 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
4789 /* runtime constants - we retain the value of remote_write_size
4790 across architecture swaps. */
4791 remote_write_size
= PBUFSIZ
;
4794 add_target (&remote_ops
);
4796 init_extended_remote_ops ();
4797 add_target (&extended_remote_ops
);
4799 init_remote_async_ops ();
4800 add_target (&remote_async_ops
);
4802 init_extended_async_remote_ops ();
4803 add_target (&extended_async_remote_ops
);
4805 init_remote_cisco_ops ();
4806 add_target (&remote_cisco_ops
);
4809 init_remote_threadtests ();
4812 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
4813 "Compare section data on target to the exec file.\n\
4814 Argument is a single section name (default: all loaded sections).",
4817 add_cmd ("packet", class_maintenance
, packet_command
,
4818 "Send an arbitrary packet to a remote target.\n\
4819 maintenance packet TEXT\n\
4820 If GDB is talking to an inferior via the GDB serial protocol, then\n\
4821 this command sends the string TEXT to the inferior, and displays the\n\
4822 response packet. GDB supplies the initial `$' character, and the\n\
4823 terminating `#' character and checksum.",
4827 (add_set_cmd ("remotetimeout", no_class
,
4828 var_integer
, (char *) &remote_timeout
,
4829 "Set timeout value for remote read.\n",
4834 (add_set_cmd ("remotebreak", no_class
,
4835 var_boolean
, (char *) &remote_break
,
4836 "Set whether to send break if interrupted.\n",
4841 (add_set_cmd ("remotewritesize", no_class
,
4842 var_integer
, (char *) &remote_write_size
,
4843 "Set the maximum number of bytes per memory write packet.\n",
4847 remote_address_size
= TARGET_PTR_BIT
;
4849 (add_set_cmd ("remoteaddresssize", class_obscure
,
4850 var_integer
, (char *) &remote_address_size
,
4851 "Set the maximum size of the address (in bits) \
4852 in a memory packet.\n",
4857 (add_set_cmd ("remotebinarydownload", no_class
,
4858 var_boolean
, (char *) &remote_binary_download
,
4859 "Set binary downloads.\n", &setlist
),
4862 add_info ("remote-process", remote_info_process
,
4863 "Query the remote system for process info.");