1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* Remote communication protocol.
23 A debug packet whose contents are <data>
24 is encapsulated for transmission in the form:
26 $ <data> # CSUM1 CSUM2
28 <data> must be ASCII alphanumeric and cannot include characters
29 '$' or '#'. If <data> starts with two characters followed by
30 ':', then the existing stubs interpret this as a sequence number.
32 CSUM1 and CSUM2 are ascii hex representation of an 8-bit
33 checksum of <data>, the most significant nibble is sent first.
34 the hex digits 0-9,a-f are used.
36 Receiver responds with:
38 + - if CSUM is correct and ready for next packet
39 - - if CSUM is incorrect
42 Most values are encoded in ascii hex digits. Signal numbers are according
43 to the numbering in target.h.
47 set thread Hct... Set thread for subsequent operations.
48 c = 'c' for thread used in step and
49 continue; t... can be -1 for all
51 c = 'g' for thread used in other
52 operations. If zero, pick a thread,
58 reply XX....X Each byte of register data
59 is described by two hex digits.
60 Registers are in the internal order
61 for GDB, and the bytes in a register
62 are in the same order the machine uses.
65 write regs GXX..XX Each byte of register data
66 is described by two hex digits.
70 write reg Pn...=r... Write register n... with value r...,
71 which contains two hex digits for each
72 byte in the register (target byte
76 (not supported by all stubs).
78 read mem mAA..AA,LLLL AA..AA is address, LLLL is length.
79 reply XX..XX XX..XX is mem contents
80 Can be fewer bytes than requested
81 if able to read only part of the data.
84 write mem MAA..AA,LLLL:XX..XX
86 LLLL is number of bytes,
89 ENN for an error (this includes the case
90 where only part of the data was
93 continue cAA..AA AA..AA is address to resume
95 resume at same address.
97 step sAA..AA AA..AA is address to resume
99 resume at same address.
101 continue with Csig;AA..AA Continue with signal sig (hex signal
102 signal number). If ;AA..AA is omitted,
103 resume at same address.
105 step with Ssig;AA..AA Like 'C' but step not continue.
108 last signal ? Reply the current reason for stopping.
109 This is the same reply as is generated
110 for step or cont : SAA where AA is the
115 There is no immediate reply to step or cont.
116 The reply comes when the machine stops.
117 It is SAA AA is the signal number.
119 or... TAAn...:r...;n...:r...;n...:r...;
121 n... = register number (hex)
122 r... = register contents
124 r... = thread process ID. This is
126 n... = other string not starting
127 with valid hex digit.
128 gdb should ignore this n,r pair
129 and go on to the next. This way
130 we can extend the protocol.
131 or... WAA The process exited, and AA is
132 the exit status. This is only
133 applicable for certains sorts of
135 or... XAA The process terminated with signal
137 or... OXX..XX XX..XX is hex encoding of ASCII data. This
138 can happen at any time while the
139 program is running and the debugger
140 should continue to wait for
143 thread alive TXX Find out if the thread XX is alive.
144 reply OK thread is still alive
147 remote restart RXX Restart the remote server
149 extended ops ! Use the extended remote protocol.
150 Sticky -- only needs to be set once.
154 toggle debug d toggle debug flag (see 386 & 68k stubs)
155 reset r reset -- see sparc stub.
156 reserved <other> On other requests, the stub should
157 ignore the request and send an empty
158 response ($#<checksum>). This way
159 we can extend the protocol and GDB
160 can tell whether the stub it is
161 talking to uses the old or the new.
162 search tAA:PP,MM Search backwards starting at address
163 AA for a match with pattern PP and
164 mask MM. PP and MM are 4 bytes.
165 Not supported by all stubs.
167 general query qXXXX Request info about XXXX.
168 general set QXXXX=yyyy Set value of XXXX to yyyy.
169 query sect offs qOffsets Get section offsets. Reply is
170 Text=xxx;Data=yyy;Bss=zzz
172 Responses can be run-length encoded to save space. A '*' means that
173 the next character is an ASCII encoding giving a repeat count which
174 stands for that many repititions of the character preceding the '*'.
175 The encoding is n+29, yielding a printable character where n >=3
176 (which is where rle starts to win). Don't use an n > 126.
179 "0* " means the same as "0000". */
182 #include "gdb_string.h"
185 #include "inferior.h"
190 /*#include "terminal.h"*/
192 #include "objfiles.h"
193 #include "gdb-stabs.h"
194 #include "gdbthread.h"
199 #include <sys/types.h>
205 /* Prototypes for local functions */
207 static int remote_write_bytes
PARAMS ((CORE_ADDR memaddr
,
208 char *myaddr
, int len
));
210 static int remote_read_bytes
PARAMS ((CORE_ADDR memaddr
,
211 char *myaddr
, int len
));
213 static void remote_files_info
PARAMS ((struct target_ops
*ignore
));
215 static int remote_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char * myaddr
,
216 int len
, int should_write
,
217 struct target_ops
* target
));
219 static void remote_prepare_to_store
PARAMS ((void));
221 static void remote_fetch_registers
PARAMS ((int regno
));
223 static void remote_resume
PARAMS ((int pid
, int step
,
224 enum target_signal siggnal
));
226 static int remote_start_remote
PARAMS ((char *dummy
));
228 static void remote_open
PARAMS ((char *name
, int from_tty
));
230 static void extended_remote_open
PARAMS ((char *name
, int from_tty
));
232 static void remote_open_1
PARAMS ((char *, int, struct target_ops
*,
235 static void remote_close
PARAMS ((int quitting
));
237 static void remote_store_registers
PARAMS ((int regno
));
239 static void remote_mourn
PARAMS ((void));
241 static void extended_remote_restart
PARAMS ((void));
243 static void extended_remote_mourn
PARAMS ((void));
245 static void extended_remote_create_inferior
PARAMS ((char *, char *, char **));
247 static void remote_mourn_1
PARAMS ((struct target_ops
*));
249 static void remote_send
PARAMS ((char *buf
));
251 static int readchar
PARAMS ((int timeout
));
253 static int remote_wait
PARAMS ((int pid
, struct target_waitstatus
* status
));
255 static void remote_kill
PARAMS ((void));
257 static int tohex
PARAMS ((int nib
));
259 static void remote_detach
PARAMS ((char *args
, int from_tty
));
261 static void remote_interrupt
PARAMS ((int signo
));
263 static void interrupt_query
PARAMS ((void));
265 static void set_thread
PARAMS ((int, int));
267 static int remote_thread_alive
PARAMS ((int));
269 static void get_offsets
PARAMS ((void));
271 static int read_frame
PARAMS ((char *));
273 static int remote_insert_breakpoint
PARAMS ((CORE_ADDR
, char *));
275 static int remote_remove_breakpoint
PARAMS ((CORE_ADDR
, char *));
277 static int hexnumlen
PARAMS ((ULONGEST num
));
279 static void init_remote_ops
PARAMS ((void));
281 static void init_extended_remote_ops
PARAMS ((void));
283 static void remote_stop
PARAMS ((void));
285 static int ishex
PARAMS ((int ch
, int *val
));
287 static int stubhex
PARAMS ((int ch
));
289 static int remote_query
PARAMS ((char, char *, char *, int *));
291 static int hexnumstr
PARAMS ((char *, ULONGEST
));
293 static CORE_ADDR remote_address_masked
PARAMS ((CORE_ADDR
));
295 static void print_packet
PARAMS ((char *));
297 static unsigned long crc32
PARAMS ((unsigned char *, int, unsigned int));
299 static void compare_sections_command
PARAMS ((char *, int));
301 static void packet_command
PARAMS ((char *, int));
303 static int stub_unpack_int
PARAMS ((char *buff
, int fieldlength
));
305 char *unpack_varlen_hex
PARAMS ((char *buff
, int *result
));
307 static char *unpack_nibble
PARAMS ((char *buf
, int *val
));
309 static char *pack_nibble
PARAMS ((char *buf
, int nibble
));
311 static char *pack_hex_byte
PARAMS ((char *pkt
, unsigned char byte
));
313 static char *unpack_byte
PARAMS ((char *buf
, int *value
));
315 static char *pack_int
PARAMS ((char *buf
, int value
));
317 static char *unpack_int
PARAMS ((char *buf
, int *value
));
319 static char *unpack_string
PARAMS ((char *src
, char *dest
, int length
));
321 static char *pack_threadid
PARAMS ((char *pkt
, threadref
*id
));
323 static char *unpack_threadid
PARAMS ((char *inbuf
, threadref
*id
));
325 void int_to_threadref
PARAMS ((threadref
*id
, int value
));
327 static int threadref_to_int
PARAMS ((threadref
*ref
));
329 static void copy_threadref
PARAMS ((threadref
*dest
, threadref
*src
));
331 static int threadmatch
PARAMS ((threadref
*dest
, threadref
*src
));
333 static char *pack_threadinfo_request
PARAMS ((char *pkt
, int mode
,
336 static int remote_unpack_thread_info_response
PARAMS ((char *pkt
,
337 threadref
*expectedref
,
338 struct gdb_ext_thread_info
*info
));
341 static int remote_get_threadinfo
PARAMS ((threadref
*threadid
,
342 int fieldset
, /*TAG mask */
343 struct gdb_ext_thread_info
*info
));
345 static int adapt_remote_get_threadinfo
PARAMS ((gdb_threadref
*ref
,
347 struct gdb_ext_thread_info
*info
));
349 static char *pack_threadlist_request
PARAMS ((char *pkt
, int startflag
,
351 threadref
*nextthread
));
353 static int parse_threadlist_response
PARAMS ((char *pkt
,
355 threadref
*original_echo
,
356 threadref
*resultlist
,
359 static int remote_get_threadlist
PARAMS ((int startflag
,
360 threadref
*nextthread
,
364 threadref
*threadlist
));
366 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
368 static int remote_threadlist_iterator
PARAMS ((rmt_thread_action stepfunction
,
369 void *context
, int looplimit
));
371 static int remote_newthread_step
PARAMS ((threadref
*ref
, void *context
));
373 static int remote_current_thread
PARAMS ((int oldpid
));
375 int remote_find_new_threads
PARAMS ((void));
377 static void record_currthread
PARAMS ((int currthread
));
379 static void init_remote_threads
PARAMS ((void));
381 /* exported functions */
383 extern int fromhex
PARAMS ((int a
));
385 extern void getpkt
PARAMS ((char *buf
, int forever
));
387 extern int putpkt
PARAMS ((char *buf
));
389 void remote_console_output
PARAMS ((char *));
391 /* Define the target subroutine names */
393 void open_remote_target
PARAMS ((char *, int, struct target_ops
*, int));
395 void _initialize_remote
PARAMS ((void));
399 static struct target_ops remote_ops
;
401 static struct target_ops extended_remote_ops
;
403 static struct target_thread_vector remote_thread_vec
;
405 /* This was 5 seconds, which is a long time to sit and wait.
406 Unless this is going though some terminal server or multiplexer or
407 other form of hairy serial connection, I would think 2 seconds would
410 /* Changed to allow option to set timeout value.
411 was static int remote_timeout = 2; */
412 extern int remote_timeout
;
414 /* This variable chooses whether to send a ^C or a break when the user
415 requests program interruption. Although ^C is usually what remote
416 systems expect, and that is the default here, sometimes a break is
417 preferable instead. */
419 static int remote_break
;
421 /* Has the user attempted to interrupt the target? If so, then offer
422 the user the opportunity to bail out completely if he interrupts
424 static int interrupted_already
= 0;
426 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
427 remote_open knows that we don't have a file open when the program
429 static serial_t remote_desc
= NULL
;
431 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
432 and i386-stub.c. Normally, no one would notice because it only matters
433 for writing large chunks of memory (e.g. in downloads). Also, this needs
434 to be more than 400 if required to hold the registers (see below, where
435 we round it up based on REGISTER_BYTES). */
438 /* Maximum number of bytes to read/write at once. The value here
439 is chosen to fill up a packet (the headers account for the 32). */
440 #define MAXBUFBYTES ((PBUFSIZ-32)/2)
442 /* Round up PBUFSIZ to hold all the registers, at least. */
443 /* The blank line after the #if seems to be required to work around a
444 bug in HP's PA compiler. */
445 #if REGISTER_BYTES > MAXBUFBYTES
448 #define PBUFSIZ (REGISTER_BYTES * 2 + 32)
452 /* This variable sets the number of bytes to be written to the target
453 in a single packet. Normally PBUFSIZ is satisfactory, but some
454 targets need smaller values (perhaps because the receiving end
457 static int remote_write_size
= PBUFSIZ
;
459 /* This variable sets the number of bits in an address that are to be
460 sent in a memory ("M" or "m") packet. Normally, after stripping
461 leading zeros, the entire address would be sent. This variable
462 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
463 initial implementation of remote.c restricted the address sent in
464 memory packets to ``host::sizeof long'' bytes - (typically 32
465 bits). Consequently, for 64 bit targets, the upper 32 bits of an
466 address was never sent. Since fixing this bug may cause a break in
467 some remote targets this variable is principly provided to
468 facilitate backward compatibility. */
470 static int remote_address_size
;
472 /* This is the size (in chars) of the first response to the `g' command. This
473 is used to limit the size of the memory read and write commands to prevent
474 stub buffers from overflowing. The size does not include headers and
475 trailers, it is only the payload size. */
477 static int remote_register_buf_size
= 0;
479 /* Should we try the 'P' request? If this is set to one when the stub
480 doesn't support 'P', the only consequence is some unnecessary traffic. */
481 static int stub_supports_P
= 1;
483 /* These are pointers to hook functions that may be set in order to
484 modify resume/wait behavior for a particular architecture. */
486 void (*target_resume_hook
) PARAMS ((void));
487 void (*target_wait_loop_hook
) PARAMS ((void));
491 /* These are the threads which we last sent to the remote system.
492 -1 for all or -2 for not sent yet. */
493 static int general_thread
;
494 static int cont_thread
;
496 /* Call this function as a result of
497 1) A halt indication (T packet) containing a thread id
498 2) A direct query of currthread
499 3) Successful execution of set thread
503 record_currthread (currthread
)
506 #if 0 /* target_wait must not modify inferior_pid! */
507 inferior_pid
= currthread
;
509 general_thread
= currthread
;
510 #if 0 /* setting cont_thread has a different meaning
511 from having the target report its thread id. */
512 cont_thread
= currthread
;
514 /* If this is a new thread, add it to GDB's thread list.
515 If we leave it up to WFI to do this, bad things will happen. */
516 if (!in_thread_list (currthread
))
517 add_thread (currthread
);
520 #define MAGIC_NULL_PID 42000
528 int state
= gen
? general_thread
: cont_thread
;
534 buf
[1] = gen
? 'g' : 'c';
535 if (th
== MAGIC_NULL_PID
)
541 sprintf (&buf
[2], "-%x", -th
);
543 sprintf (&buf
[2], "%x", th
);
552 /* Return nonzero if the thread TH is still alive on the remote system. */
555 remote_thread_alive (th
)
562 sprintf (&buf
[1], "-%08x", -th
);
564 sprintf (&buf
[1], "%08x", th
);
567 return (buf
[0] == 'O' && buf
[1] == 'K');
570 /* About these extended threadlist and threadinfo packets. They are
571 variable length packets but, the fields within them are often fixed
572 length. They are redundent enough to send over UDP as is the
573 remote protocol in general. There is a matching unit test module
576 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
578 /* encode 64 bits in 16 chars of hex */
580 static const char hexchars
[] = "0123456789abcdef";
587 if ((ch
>= 'a') && (ch
<= 'f'))
589 *val
= ch
- 'a' + 10;
592 if ((ch
>= 'A') && (ch
<= 'F'))
594 *val
= ch
- 'A' + 10;
597 if ((ch
>= '0') && (ch
<= '9'))
609 if (ch
>= 'a' && ch
<= 'f')
610 return ch
- 'a' + 10;
611 if (ch
>= '0' && ch
<= '9')
613 if (ch
>= 'A' && ch
<= 'F')
614 return ch
- 'A' + 10;
619 stub_unpack_int (buff
, fieldlength
)
628 nibble
= stubhex (*buff
++);
632 retval
= retval
<< 4;
638 unpack_varlen_hex (buff
, result
)
639 char *buff
; /* packet to parse */
645 while (ishex (*buff
, &nibble
))
648 retval
= retval
<< 4;
649 retval
|= nibble
& 0x0f;
656 unpack_nibble (buf
, val
)
665 pack_nibble (buf
, nibble
)
669 *buf
++ = hexchars
[(nibble
& 0x0f)];
674 pack_hex_byte (pkt
, byte
)
678 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
679 *pkt
++ = hexchars
[(byte
& 0xf)];
684 unpack_byte (buf
, value
)
688 *value
= stub_unpack_int (buf
, 2);
693 pack_int (buf
, value
)
697 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
698 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
699 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
700 buf
= pack_hex_byte (buf
, (value
& 0xff));
705 unpack_int (buf
, value
)
709 *value
= stub_unpack_int (buf
, 8);
713 #if 0 /* currently unused, uncomment when needed */
714 static char *pack_string
PARAMS ((char *pkt
, char *string
));
717 pack_string (pkt
, string
)
724 len
= strlen (string
);
726 len
= 200; /* Bigger than most GDB packets, junk??? */
727 pkt
= pack_hex_byte (pkt
, len
);
731 if ((ch
== '\0') || (ch
== '#'))
732 ch
= '*'; /* Protect encapsulation */
737 #endif /* 0 (unused) */
740 unpack_string (src
, dest
, length
)
752 pack_threadid (pkt
, id
)
757 unsigned char *altid
;
759 altid
= (unsigned char *) id
;
760 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
762 pkt
= pack_hex_byte (pkt
, *altid
++);
768 unpack_threadid (inbuf
, id
)
773 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
776 altref
= (char *) id
;
778 while (inbuf
< limit
)
780 x
= stubhex (*inbuf
++);
781 y
= stubhex (*inbuf
++);
782 *altref
++ = (x
<< 4) | y
;
787 /* Externally, threadrefs are 64 bits but internally, they are still
788 ints. This is due to a mismatch of specifications. We would like
789 to use 64bit thread references internally. This is an adapter
793 int_to_threadref (id
, value
)
799 scan
= (unsigned char *) id
;
805 *scan
++ = (value
>> 24) & 0xff;
806 *scan
++ = (value
>> 16) & 0xff;
807 *scan
++ = (value
>> 8) & 0xff;
808 *scan
++ = (value
& 0xff);
812 threadref_to_int (ref
)
822 value
= (value
<< 8) | ((*scan
++) & 0xff);
827 copy_threadref (dest
, src
)
832 unsigned char *csrc
, *cdest
;
834 csrc
= (unsigned char *) src
;
835 cdest
= (unsigned char *) dest
;
842 threadmatch (dest
, src
)
846 /* things are broken right now, so just assume we got a match */
848 unsigned char *srcp
, *destp
;
851 destp
= (char *) dest
;
855 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
862 threadid:1, # always request threadid
869 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
872 pack_threadinfo_request (pkt
, mode
, id
)
877 *pkt
++ = 'q'; /* Info Query */
878 *pkt
++ = 'P'; /* process or thread info */
879 pkt
= pack_int (pkt
, mode
); /* mode */
880 pkt
= pack_threadid (pkt
, id
); /* threadid */
881 *pkt
= '\0'; /* terminate */
885 /* These values tag the fields in a thread info response packet */
886 /* Tagging the fields allows us to request specific fields and to
887 add more fields as time goes by */
889 #define TAG_THREADID 1 /* Echo the thread identifier */
890 #define TAG_EXISTS 2 /* Is this process defined enough to
891 fetch registers and its stack */
892 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
893 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
894 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
898 remote_unpack_thread_info_response (pkt
, expectedref
, info
)
900 threadref
*expectedref
;
901 struct gdb_ext_thread_info
*info
;
906 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
909 /* info->threadid = 0; FIXME: implement zero_threadref */
911 info
->display
[0] = '\0';
912 info
->shortname
[0] = '\0';
913 info
->more_display
[0] = '\0';
915 /* Assume the characters indicating the packet type have been stripped */
916 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
917 pkt
= unpack_threadid (pkt
, &ref
);
920 warning ("Incomplete response to threadinfo request\n");
921 if (!threadmatch (&ref
, expectedref
))
922 { /* This is an answer to a different request */
923 warning ("ERROR RMT Thread info mismatch\n");
926 copy_threadref (&info
->threadid
, &ref
);
928 /* Loop on tagged fields , try to bail if somthing goes wrong */
930 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
932 pkt
= unpack_int (pkt
, &tag
); /* tag */
933 pkt
= unpack_byte (pkt
, &length
); /* length */
934 if (!(tag
& mask
)) /* tags out of synch with mask */
936 warning ("ERROR RMT: threadinfo tag mismatch\n");
940 if (tag
== TAG_THREADID
)
944 warning ("ERROR RMT: length of threadid is not 16\n");
948 pkt
= unpack_threadid (pkt
, &ref
);
949 mask
= mask
& ~TAG_THREADID
;
952 if (tag
== TAG_EXISTS
)
954 info
->active
= stub_unpack_int (pkt
, length
);
956 mask
= mask
& ~(TAG_EXISTS
);
959 warning ("ERROR RMT: 'exists' length too long\n");
965 if (tag
== TAG_THREADNAME
)
967 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
968 mask
= mask
& ~TAG_THREADNAME
;
971 if (tag
== TAG_DISPLAY
)
973 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
974 mask
= mask
& ~TAG_DISPLAY
;
977 if (tag
== TAG_MOREDISPLAY
)
979 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
980 mask
= mask
& ~TAG_MOREDISPLAY
;
983 warning ("ERROR RMT: unknown thread info tag\n");
984 break; /* Not a tag we know about */
990 remote_get_threadinfo (threadid
, fieldset
, info
)
992 int fieldset
; /* TAG mask */
993 struct gdb_ext_thread_info
*info
;
996 char threadinfo_pkt
[PBUFSIZ
];
998 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
999 putpkt (threadinfo_pkt
);
1000 getpkt (threadinfo_pkt
, 0);
1001 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1006 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1007 representation of a threadid. */
1010 adapt_remote_get_threadinfo (ref
, selection
, info
)
1013 struct gdb_ext_thread_info
*info
;
1017 int_to_threadref (&lclref
, *ref
);
1018 return remote_get_threadinfo (&lclref
, selection
, info
);
1021 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1024 pack_threadlist_request (pkt
, startflag
, threadcount
, nextthread
)
1028 threadref
*nextthread
;
1030 *pkt
++ = 'q'; /* info query packet */
1031 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1032 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1033 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1034 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1039 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1042 parse_threadlist_response (pkt
, result_limit
, original_echo
, resultlist
,
1046 threadref
*original_echo
;
1047 threadref
*resultlist
;
1051 int count
, resultcount
, done
;
1054 /* Assume the 'q' and 'M chars have been stripped. */
1055 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1056 pkt
= unpack_byte (pkt
, &count
); /* count field */
1057 pkt
= unpack_nibble (pkt
, &done
);
1058 /* The first threadid is the argument threadid. */
1059 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1060 while ((count
-- > 0) && (pkt
< limit
))
1062 pkt
= unpack_threadid (pkt
, resultlist
++);
1063 if (resultcount
++ >= result_limit
)
1072 remote_get_threadlist (startflag
, nextthread
, result_limit
,
1073 done
, result_count
, threadlist
)
1075 threadref
*nextthread
;
1079 threadref
*threadlist
;
1082 static threadref echo_nextthread
;
1083 char threadlist_packet
[PBUFSIZ
];
1084 char t_response
[PBUFSIZ
];
1087 /* Trancate result limit to be smaller than the packet size */
1088 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1089 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1091 pack_threadlist_request (threadlist_packet
,
1092 startflag
, result_limit
, nextthread
);
1093 putpkt (threadlist_packet
);
1094 getpkt (t_response
, 0);
1097 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1100 if (!threadmatch (&echo_nextthread
, nextthread
))
1102 /* FIXME: This is a good reason to drop the packet */
1103 /* Possably, there is a duplicate response */
1105 retransmit immediatly - race conditions
1106 retransmit after timeout - yes
1108 wait for packet, then exit
1110 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1111 return 0; /* I choose simply exiting */
1113 if (*result_count
<= 0)
1117 warning ("RMT ERROR : failed to get remote thread list\n");
1120 return result
; /* break; */
1122 if (*result_count
> result_limit
)
1125 warning ("RMT ERROR: threadlist response longer than requested\n");
1131 /* This is the interface between remote and threads, remotes upper interface */
1133 /* remote_find_new_threads retrieves the thread list and for each
1134 thread in the list, looks up the thread in GDB's internal list,
1135 ading the thread if it does not already exist. This involves
1136 getting partial thread lists from the remote target so, polling the
1137 quit_flag is required. */
1140 /* About this many threadisds fit in a packet. */
1142 #define MAXTHREADLISTRESULTS 32
1145 remote_threadlist_iterator (stepfunction
, context
, looplimit
)
1146 rmt_thread_action stepfunction
;
1150 int done
, i
, result_count
;
1154 static threadref nextthread
;
1155 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1160 if (loopcount
++ > looplimit
)
1163 warning ("Remote fetch threadlist -infinite loop-\n");
1166 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1167 &done
, &result_count
, resultthreadlist
))
1172 /* clear for later iterations */
1174 /* Setup to resume next batch of thread references, set nextthread. */
1175 if (result_count
>= 1)
1176 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1178 while (result_count
--)
1179 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1186 remote_newthread_step (ref
, context
)
1192 pid
= threadref_to_int (ref
);
1193 if (!in_thread_list (pid
))
1195 return 1; /* continue iterator */
1198 #define CRAZY_MAX_THREADS 1000
1201 remote_current_thread (oldpid
)
1208 if (buf
[0] == 'Q' && buf
[1] == 'C')
1209 return strtol (&buf
[2], NULL
, 16);
1215 remote_find_new_threads ()
1219 ret
= remote_threadlist_iterator (remote_newthread_step
, 0,
1221 if (inferior_pid
== MAGIC_NULL_PID
) /* ack ack ack */
1222 inferior_pid
= remote_current_thread (inferior_pid
);
1226 /* Initialize the thread vector which is used by threads.c */
1227 /* The thread stub is a package, it has an initializer */
1230 init_remote_threads ()
1232 remote_thread_vec
.find_new_threads
= remote_find_new_threads
;
1233 remote_thread_vec
.get_thread_info
= adapt_remote_get_threadinfo
;
1237 /* Restart the remote side; this is an extended protocol operation. */
1240 extended_remote_restart ()
1244 /* Send the restart command; for reasons I don't understand the
1245 remote side really expects a number after the "R". */
1247 sprintf (&buf
[1], "%x", 0);
1250 /* Now query for status so this looks just like we restarted
1251 gdbserver from scratch. */
1256 /* Clean up connection to a remote debugger. */
1260 remote_close (quitting
)
1264 SERIAL_CLOSE (remote_desc
);
1268 /* Query the remote side for the text, data and bss offsets. */
1273 char buf
[PBUFSIZ
], *ptr
;
1275 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1276 struct section_offsets
*offs
;
1278 putpkt ("qOffsets");
1282 if (buf
[0] == '\000')
1283 return; /* Return silently. Stub doesn't support
1287 warning ("Remote failure reply: %s", buf
);
1291 /* Pick up each field in turn. This used to be done with scanf, but
1292 scanf will make trouble if CORE_ADDR size doesn't match
1293 conversion directives correctly. The following code will work
1294 with any size of CORE_ADDR. */
1295 text_addr
= data_addr
= bss_addr
= 0;
1299 if (strncmp (ptr
, "Text=", 5) == 0)
1302 /* Don't use strtol, could lose on big values. */
1303 while (*ptr
&& *ptr
!= ';')
1304 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1309 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1312 while (*ptr
&& *ptr
!= ';')
1313 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1318 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1321 while (*ptr
&& *ptr
!= ';')
1322 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1328 error ("Malformed response to offset query, %s", buf
);
1330 if (symfile_objfile
== NULL
)
1333 offs
= (struct section_offsets
*) alloca (sizeof (struct section_offsets
)
1334 + symfile_objfile
->num_sections
1335 * sizeof (offs
->offsets
));
1336 memcpy (offs
, symfile_objfile
->section_offsets
,
1337 sizeof (struct section_offsets
)
1338 + symfile_objfile
->num_sections
1339 * sizeof (offs
->offsets
));
1341 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
1343 /* This is a temporary kludge to force data and bss to use the same offsets
1344 because that's what nlmconv does now. The real solution requires changes
1345 to the stub and remote.c that I don't have time to do right now. */
1347 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
1348 ANOFFSET (offs
, SECT_OFF_BSS
) = data_addr
;
1350 objfile_relocate (symfile_objfile
, offs
);
1353 /* Stub for catch_errors. */
1356 remote_start_remote (dummy
)
1359 immediate_quit
= 1; /* Allow user to interrupt it */
1361 /* Ack any packet which the remote side has already sent. */
1362 SERIAL_WRITE (remote_desc
, "+", 1);
1364 /* Let the stub know that we want it to return the thread. */
1367 inferior_pid
= remote_current_thread (inferior_pid
);
1369 get_offsets (); /* Get text, data & bss offsets */
1371 putpkt ("?"); /* initiate a query from remote machine */
1374 start_remote (); /* Initialize gdb process mechanisms */
1378 /* Open a connection to a remote debugger.
1379 NAME is the filename used for communication. */
1382 remote_open (name
, from_tty
)
1386 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
1389 /* Open a connection to a remote debugger using the extended
1390 remote gdb protocol. NAME is the filename used for communication. */
1393 extended_remote_open (name
, from_tty
)
1397 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1/*extended_p*/);
1400 /* Generic code for opening a connection to a remote target. */
1402 static DCACHE
*remote_dcache
;
1405 remote_open_1 (name
, from_tty
, target
, extended_p
)
1408 struct target_ops
*target
;
1412 error ("To open a remote debug connection, you need to specify what\n\
1413 serial device is attached to the remote system (e.g. /dev/ttya).");
1415 target_preopen (from_tty
);
1417 unpush_target (target
);
1419 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1421 remote_desc
= SERIAL_OPEN (name
);
1423 perror_with_name (name
);
1425 if (baud_rate
!= -1)
1427 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1429 SERIAL_CLOSE (remote_desc
);
1430 perror_with_name (name
);
1435 SERIAL_RAW (remote_desc
);
1437 /* If there is something sitting in the buffer we might take it as a
1438 response to a command, which would be bad. */
1439 SERIAL_FLUSH_INPUT (remote_desc
);
1443 puts_filtered ("Remote debugging using ");
1444 puts_filtered (name
);
1445 puts_filtered ("\n");
1447 push_target (target
); /* Switch to using remote target now */
1449 /* The target vector does not have the thread functions in it yet,
1450 so we use this function to call back into the thread module and
1451 register the thread vector and its contained functions. */
1452 bind_target_thread_vector (&remote_thread_vec
);
1454 /* Start out by trying the 'P' request to set registers. We set
1455 this each time that we open a new target so that if the user
1456 switches from one stub to another, we can (if the target is
1457 closed and reopened) cope. */
1458 stub_supports_P
= 1;
1460 general_thread
= -2;
1463 /* Without this, some commands which require an active target (such
1464 as kill) won't work. This variable serves (at least) double duty
1465 as both the pid of the target process (if it has such), and as a
1466 flag indicating that a target is active. These functions should
1467 be split out into seperate variables, especially since GDB will
1468 someday have a notion of debugging several processes. */
1470 inferior_pid
= MAGIC_NULL_PID
;
1471 /* Start the remote connection; if error (0), discard this target.
1472 In particular, if the user quits, be sure to discard it
1473 (we'd be in an inconsistent state otherwise). */
1474 if (!catch_errors (remote_start_remote
, (char *)0,
1475 "Couldn't establish connection to remote target\n",
1484 /* tell the remote that we're using the extended protocol. */
1491 /* This takes a program previously attached to and detaches it. After
1492 this is done, GDB can be used to debug some other program. We
1493 better not have left any breakpoints in the target program or it'll
1494 die when it hits one. */
1497 remote_detach (args
, from_tty
)
1504 error ("Argument given to \"detach\" when remotely debugging.");
1506 /* Tell the remote target to detach. */
1512 puts_filtered ("Ending remote debugging.\n");
1515 /* Convert hex digit A to a number. */
1521 if (a
>= '0' && a
<= '9')
1523 else if (a
>= 'a' && a
<= 'f')
1524 return a
- 'a' + 10;
1525 else if (a
>= 'A' && a
<= 'F')
1526 return a
- 'A' + 10;
1528 error ("Reply contains invalid hex digit %d", a
);
1531 /* Convert number NIB to a hex digit. */
1543 /* Tell the remote machine to resume. */
1545 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
1547 static int last_sent_step
;
1550 remote_resume (pid
, step
, siggnal
)
1552 enum target_signal siggnal
;
1557 set_thread (0, 0); /* run any thread */
1559 set_thread (pid
, 0); /* run this thread */
1561 dcache_flush (remote_dcache
);
1563 last_sent_signal
= siggnal
;
1564 last_sent_step
= step
;
1566 /* A hook for when we need to do something at the last moment before
1568 if (target_resume_hook
)
1569 (*target_resume_hook
) ();
1571 if (siggnal
!= TARGET_SIGNAL_0
)
1573 buf
[0] = step
? 'S' : 'C';
1574 buf
[1] = tohex (((int)siggnal
>> 4) & 0xf);
1575 buf
[2] = tohex ((int)siggnal
& 0xf);
1579 strcpy (buf
, step
? "s": "c");
1584 /* Send ^C to target to halt it. Target will respond, and send us a
1587 static void (*ofunc
) PARAMS ((int));
1590 remote_interrupt (signo
)
1594 signal (signo
, remote_interrupt
);
1600 if (!interrupted_already
)
1602 /* Send a break or a ^C, depending on user preference. */
1603 interrupted_already
= 1;
1606 printf_unfiltered ("remote_stop called\n");
1609 SERIAL_SEND_BREAK (remote_desc
);
1611 SERIAL_WRITE (remote_desc
, "\003", 1);
1615 signal (SIGINT
, ofunc
);
1617 signal (SIGINT
, remote_interrupt
);
1618 interrupted_already
= 0;
1622 /* Ask the user what to do when an interrupt is received. */
1627 target_terminal_ours ();
1629 if (query ("Interrupted while waiting for the program.\n\
1630 Give up (and stop debugging it)? "))
1632 target_mourn_inferior ();
1633 return_to_top_level (RETURN_QUIT
);
1636 target_terminal_inferior ();
1639 /* If nonzero, ignore the next kill. */
1644 remote_console_output (msg
)
1649 for (p
= msg
; *p
; p
+=2)
1652 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
1655 if (target_output_hook
)
1656 target_output_hook (tb
);
1658 fputs_filtered (tb
, gdb_stdout
);
1662 /* Wait until the remote machine stops, then return, storing status in
1663 STATUS just as `wait' would. Returns "pid" (though it's not clear
1664 what, if anything, that means in the case of this target). */
1667 remote_wait (pid
, status
)
1669 struct target_waitstatus
*status
;
1671 unsigned char buf
[PBUFSIZ
];
1672 int thread_num
= -1;
1674 status
->kind
= TARGET_WAITKIND_EXITED
;
1675 status
->value
.integer
= 0;
1681 interrupted_already
= 0;
1682 ofunc
= signal (SIGINT
, remote_interrupt
);
1683 getpkt ((char *) buf
, 1);
1684 signal (SIGINT
, ofunc
);
1686 /* This is a hook for when we need to do something (perhaps the
1687 collection of trace data) every time the target stops. */
1688 if (target_wait_loop_hook
)
1689 (*target_wait_loop_hook
) ();
1693 case 'E': /* Error of some sort */
1694 warning ("Remote failure reply: %s", buf
);
1696 case 'T': /* Status with PC, SP, FP, ... */
1700 char regs
[MAX_REGISTER_RAW_SIZE
];
1702 /* Expedited reply, containing Signal, {regno, reg} repeat */
1703 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
1705 n... = register number
1706 r... = register contents
1708 p
= &buf
[3]; /* after Txx */
1715 /* Read the register number */
1716 regno
= strtol ((const char *) p
, &p_temp
, 16);
1717 p1
= (unsigned char *)p_temp
;
1719 if (p1
== p
) /* No register number present here */
1721 p1
= (unsigned char *) strchr ((const char *) p
, ':');
1723 warning ("Malformed packet(a) (missing colon): %s\n\
1726 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
1728 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
1729 record_currthread (thread_num
);
1730 p
= (unsigned char *) p_temp
;
1738 warning ("Malformed packet(b) (missing colon): %s\n\
1742 if (regno
>= NUM_REGS
)
1743 warning ("Remote sent bad register number %ld: %s\n\
1747 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
1749 if (p
[0] == 0 || p
[1] == 0)
1750 warning ("Remote reply is too short: %s", buf
);
1751 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
1754 supply_register (regno
, regs
);
1759 warning ("Remote register badly formatted: %s", buf
);
1760 warning (" here: %s",p
);
1765 case 'S': /* Old style status, just signal only */
1766 status
->kind
= TARGET_WAITKIND_STOPPED
;
1767 status
->value
.sig
= (enum target_signal
)
1768 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
1771 case 'W': /* Target exited */
1773 /* The remote process exited. */
1774 status
->kind
= TARGET_WAITKIND_EXITED
;
1775 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
1779 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
1780 status
->value
.sig
= (enum target_signal
)
1781 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
1785 case 'O': /* Console output */
1786 remote_console_output (buf
+ 1);
1789 if (last_sent_signal
!= TARGET_SIGNAL_0
)
1791 /* Zero length reply means that we tried 'S' or 'C' and
1792 the remote system doesn't support it. */
1793 target_terminal_ours_for_output ();
1795 ("Can't send signals to this remote system. %s not sent.\n",
1796 target_signal_to_name (last_sent_signal
));
1797 last_sent_signal
= TARGET_SIGNAL_0
;
1798 target_terminal_inferior ();
1800 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
1801 putpkt ((char *) buf
);
1804 /* else fallthrough */
1806 warning ("Invalid remote reply: %s", buf
);
1811 if (thread_num
!= -1)
1813 /* Initial thread value can only be acquired via wait, so deal with
1814 this marker which is used before the first thread value is
1816 if (inferior_pid
== MAGIC_NULL_PID
)
1818 inferior_pid
= thread_num
;
1819 if (!in_thread_list (inferior_pid
))
1820 add_thread (inferior_pid
);
1824 return inferior_pid
;
1827 /* Number of bytes of registers this stub implements. */
1829 static int register_bytes_found
;
1831 /* Read the remote registers into the block REGS. */
1832 /* Currently we just read all the registers, so we don't use regno. */
1836 remote_fetch_registers (regno
)
1842 char regs
[REGISTER_BYTES
];
1844 set_thread (inferior_pid
, 1);
1849 if (remote_register_buf_size
== 0)
1850 remote_register_buf_size
= strlen (buf
);
1852 /* Unimplemented registers read as all bits zero. */
1853 memset (regs
, 0, REGISTER_BYTES
);
1855 /* We can get out of synch in various cases. If the first character
1856 in the buffer is not a hex character, assume that has happened
1857 and try to fetch another packet to read. */
1858 while ((buf
[0] < '0' || buf
[0] > '9')
1859 && (buf
[0] < 'a' || buf
[0] > 'f')
1860 && buf
[0] != 'x') /* New: unavailable register value */
1863 printf_unfiltered ("Bad register packet; fetching a new packet\n");
1867 /* Reply describes registers byte by byte, each byte encoded as two
1868 hex characters. Suck them all up, then supply them to the
1869 register cacheing/storage mechanism. */
1872 for (i
= 0; i
< REGISTER_BYTES
; i
++)
1878 warning ("Remote reply is of odd length: %s", buf
);
1879 /* Don't change register_bytes_found in this case, and don't
1880 print a second warning. */
1883 if (p
[0] == 'x' && p
[1] == 'x')
1884 regs
[i
] = 0; /* 'x' */
1886 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
1890 if (i
!= register_bytes_found
)
1892 register_bytes_found
= i
;
1893 #ifdef REGISTER_BYTES_OK
1894 if (!REGISTER_BYTES_OK (i
))
1895 warning ("Remote reply is too short: %s", buf
);
1900 for (i
= 0; i
< NUM_REGS
; i
++)
1902 supply_register (i
, ®s
[REGISTER_BYTE(i
)]);
1903 if (buf
[REGISTER_BYTE(i
) * 2] == 'x')
1904 register_valid
[i
] = -1; /* register value not available */
1908 /* Prepare to store registers. Since we may send them all (using a
1909 'G' request), we have to read out the ones we don't want to change
1913 remote_prepare_to_store ()
1915 /* Make sure the entire registers array is valid. */
1916 read_register_bytes (0, (char *)NULL
, REGISTER_BYTES
);
1919 /* Store register REGNO, or all registers if REGNO == -1, from the contents
1920 of REGISTERS. FIXME: ignores errors. */
1923 remote_store_registers (regno
)
1930 set_thread (inferior_pid
, 1);
1932 if (regno
>= 0 && stub_supports_P
)
1934 /* Try storing a single register. */
1937 sprintf (buf
, "P%x=", regno
);
1938 p
= buf
+ strlen (buf
);
1939 regp
= ®isters
[REGISTER_BYTE (regno
)];
1940 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
1942 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
1943 *p
++ = tohex (regp
[i
] & 0xf);
1949 /* The stub understands the 'P' request. We are done. */
1953 /* The stub does not support the 'P' request. Use 'G' instead,
1954 and don't try using 'P' in the future (it will just waste our
1956 stub_supports_P
= 0;
1961 /* Command describes registers byte by byte,
1962 each byte encoded as two hex characters. */
1965 /* remote_prepare_to_store insures that register_bytes_found gets set. */
1966 for (i
= 0; i
< register_bytes_found
; i
++)
1968 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
1969 *p
++ = tohex (registers
[i
] & 0xf);
1976 /* Use of the data cache *used* to be disabled because it loses for looking
1977 at and changing hardware I/O ports and the like. Accepting `volatile'
1978 would perhaps be one way to fix it. Another idea would be to use the
1979 executable file for the text segment (for all SEC_CODE sections?
1980 For all SEC_READONLY sections?). This has problems if you want to
1981 actually see what the memory contains (e.g. self-modifying code,
1982 clobbered memory, user downloaded the wrong thing).
1984 Because it speeds so much up, it's now enabled, if you're playing
1985 with registers you turn it of (set remotecache 0). */
1987 /* Read a word from remote address ADDR and return it.
1988 This goes through the data cache. */
1992 remote_fetch_word (addr
)
1995 return dcache_fetch (remote_dcache
, addr
);
1998 /* Write a word WORD into remote address ADDR.
1999 This goes through the data cache. */
2002 remote_store_word (addr
, word
)
2006 dcache_poke (remote_dcache
, addr
, word
);
2008 #endif /* 0 (unused?) */
2012 /* Return the number of hex digits in num. */
2020 for (i
= 0; num
!= 0; i
++)
2026 /* Set BUF to the hex digits representing NUM. */
2029 hexnumstr (buf
, num
)
2034 int len
= hexnumlen (num
);
2038 for (i
= len
- 1; i
>= 0; i
--)
2040 buf
[i
] = "0123456789abcdef" [(num
& 0xf)];
2047 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
2050 remote_address_masked (addr
)
2053 if (remote_address_size
> 0
2054 && remote_address_size
< (sizeof (ULONGEST
) * 8))
2056 /* Only create a mask when that mask can safely be constructed
2057 in a ULONGEST variable. */
2059 mask
= (mask
<< remote_address_size
) - 1;
2065 /* Write memory data directly to the remote machine.
2066 This does not inform the data cache; the data cache uses this.
2067 MEMADDR is the address in the remote memory space.
2068 MYADDR is the address of the buffer in our space.
2069 LEN is the number of bytes.
2071 Returns number of bytes transferred, or 0 for error. */
2074 remote_write_bytes (memaddr
, myaddr
, len
)
2079 int max_buf_size
; /* Max size of packet output buffer */
2082 /* Chop the transfer down if necessary */
2084 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
2085 if (remote_register_buf_size
!= 0)
2086 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
2088 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
2089 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
2099 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
2101 /* construct "M"<memaddr>","<len>":" */
2102 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
2103 memaddr
= remote_address_masked (memaddr
);
2106 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
2108 p
+= hexnumstr (p
, (ULONGEST
) todo
);
2112 /* We send target system values byte by byte, in increasing byte
2113 addresses, each byte encoded as two hex characters. */
2115 for (i
= 0; i
< todo
; i
++)
2117 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
2118 *p
++ = tohex (myaddr
[i
] & 0xf);
2127 /* There is no correspondance between what the remote protocol uses
2128 for errors and errno codes. We would like a cleaner way of
2129 representing errors (big enough to include errno codes, bfd_error
2130 codes, and others). But for now just return EIO. */
2141 /* Read memory data directly from the remote machine.
2142 This does not use the data cache; the data cache uses this.
2143 MEMADDR is the address in the remote memory space.
2144 MYADDR is the address of the buffer in our space.
2145 LEN is the number of bytes.
2147 Returns number of bytes transferred, or 0 for error. */
2150 remote_read_bytes (memaddr
, myaddr
, len
)
2155 int max_buf_size
; /* Max size of packet output buffer */
2158 /* Chop the transfer down if necessary */
2160 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
2161 if (remote_register_buf_size
!= 0)
2162 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
2172 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
2174 /* construct "m"<memaddr>","<len>" */
2175 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
2176 memaddr
= remote_address_masked (memaddr
);
2179 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
2181 p
+= hexnumstr (p
, (ULONGEST
) todo
);
2189 /* There is no correspondance between what the remote protocol uses
2190 for errors and errno codes. We would like a cleaner way of
2191 representing errors (big enough to include errno codes, bfd_error
2192 codes, and others). But for now just return EIO. */
2197 /* Reply describes memory byte by byte,
2198 each byte encoded as two hex characters. */
2201 for (i
= 0; i
< todo
; i
++)
2203 if (p
[0] == 0 || p
[1] == 0)
2204 /* Reply is short. This means that we were able to read
2205 only part of what we wanted to. */
2206 return i
+ (origlen
- len
);
2207 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2217 /* Read or write LEN bytes from inferior memory at MEMADDR,
2218 transferring to or from debugger address MYADDR. Write to inferior
2219 if SHOULD_WRITE is nonzero. Returns length of data written or
2220 read; 0 for error. */
2224 remote_xfer_memory (memaddr
, myaddr
, len
, should_write
, target
)
2229 struct target_ops
*target
; /* ignored */
2231 #ifdef REMOTE_TRANSLATE_XFER_ADDRESS
2234 REMOTE_TRANSLATE_XFER_ADDRESS (memaddr
, len
, targaddr
, targlen
);
2241 return dcache_xfer_memory (remote_dcache
, memaddr
, myaddr
,
2247 /* Enable after 4.12. */
2250 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
2251 addr_found
, data_found
)
2255 CORE_ADDR startaddr
;
2259 CORE_ADDR
*addr_found
;
2262 if (increment
== -4 && len
== 4)
2264 long mask_long
, data_long
;
2265 long data_found_long
;
2266 CORE_ADDR addr_we_found
;
2268 long returned_long
[2];
2271 mask_long
= extract_unsigned_integer (mask
, len
);
2272 data_long
= extract_unsigned_integer (data
, len
);
2273 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
2278 /* The stub doesn't support the 't' request. We might want to
2279 remember this fact, but on the other hand the stub could be
2280 switched on us. Maybe we should remember it only until
2281 the next "target remote". */
2282 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
2283 hirange
, addr_found
, data_found
);
2288 /* There is no correspondance between what the remote protocol uses
2289 for errors and errno codes. We would like a cleaner way of
2290 representing errors (big enough to include errno codes, bfd_error
2291 codes, and others). But for now just use EIO. */
2292 memory_error (EIO
, startaddr
);
2295 while (*p
!= '\0' && *p
!= ',')
2296 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
2298 error ("Protocol error: short return for search");
2300 data_found_long
= 0;
2301 while (*p
!= '\0' && *p
!= ',')
2302 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
2303 /* Ignore anything after this comma, for future extensions. */
2305 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
2311 *addr_found
= addr_we_found
;
2312 *data_found
= store_unsigned_integer (data_we_found
, len
);
2315 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
2316 hirange
, addr_found
, data_found
);
2321 remote_files_info (ignore
)
2322 struct target_ops
*ignore
;
2324 puts_filtered ("Debugging a target over a serial line.\n");
2327 /* Stuff for dealing with the packets which are part of this protocol.
2328 See comment at top of file for details. */
2330 /* Read a single character from the remote end, masking it down to 7 bits. */
2338 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
2343 error ("Remote connection closed");
2345 perror_with_name ("Remote communication error");
2346 case SERIAL_TIMEOUT
:
2353 /* Send the command in BUF to the remote machine, and read the reply
2354 into BUF. Report an error if we get an error reply. */
2364 error ("Remote failure reply: %s", buf
);
2367 /* Display a null-terminated packet on stdout, for debugging, using C
2374 puts_filtered ("\"");
2376 gdb_printchar (*buf
++, gdb_stdout
, '"');
2377 puts_filtered ("\"");
2381 /* Send a packet to the remote machine, with error checking. The data
2382 of the packet is in BUF. */
2389 unsigned char csum
= 0;
2391 int cnt
= strlen (buf
);
2396 /* Copy the packet into buffer BUF2, encapsulating it
2397 and giving it a checksum. */
2399 if (cnt
> (int) sizeof (buf2
) - 5) /* Prosanity check */
2405 for (i
= 0; i
< cnt
; i
++)
2411 *p
++ = tohex ((csum
>> 4) & 0xf);
2412 *p
++ = tohex (csum
& 0xf);
2414 /* Send it over and over until we get a positive ack. */
2418 int started_error_output
= 0;
2423 printf_unfiltered ("Sending packet: %s...", buf2
);
2424 gdb_flush (gdb_stdout
);
2426 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
2427 perror_with_name ("putpkt: write failed");
2429 /* read until either a timeout occurs (-2) or '+' is read */
2432 ch
= readchar (remote_timeout
);
2439 case SERIAL_TIMEOUT
:
2441 if (started_error_output
)
2443 putchar_unfiltered ('\n');
2444 started_error_output
= 0;
2453 printf_unfiltered ("Ack\n");
2455 case SERIAL_TIMEOUT
:
2459 break; /* Retransmit buffer */
2462 char junkbuf
[PBUFSIZ
];
2464 /* It's probably an old response, and we're out of sync.
2465 Just gobble up the packet and ignore it. */
2466 getpkt (junkbuf
, 0);
2467 continue; /* Now, go look for + */
2472 if (!started_error_output
)
2474 started_error_output
= 1;
2475 printf_unfiltered ("putpkt: Junk: ");
2477 putchar_unfiltered (ch
& 0177);
2481 break; /* Here to retransmit */
2485 /* This is wrong. If doing a long backtrace, the user should be
2486 able to get out next time we call QUIT, without anything as
2487 violent as interrupt_query. If we want to provide a way out of
2488 here without getting to the next QUIT, it should be based on
2489 hitting ^C twice as in remote_wait. */
2499 /* Come here after finding the start of the frame. Collect the rest
2500 into BUF, verifying the checksum, length, and handling run-length
2501 compression. Returns 0 on any error, 1 on success. */
2516 c
= readchar (remote_timeout
);
2520 case SERIAL_TIMEOUT
:
2522 puts_filtered ("Timeout in mid-packet, retrying\n");
2526 puts_filtered ("Saw new packet start in middle of old one\n");
2527 return 0; /* Start a new packet, count retries */
2530 unsigned char pktcsum
;
2534 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
2535 pktcsum
|= fromhex (readchar (remote_timeout
));
2537 if (csum
== pktcsum
)
2542 printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
2544 puts_filtered (buf
);
2545 puts_filtered ("\n");
2549 case '*': /* Run length encoding */
2551 c
= readchar (remote_timeout
);
2553 c
= c
- ' ' + 3; /* Compute repeat count */
2556 if (c
> 0 && c
< 255 && bp
+ c
- 1 < buf
+ PBUFSIZ
- 1)
2558 memset (bp
, *(bp
- 1), c
);
2564 printf_filtered ("Repeat count %d too large for buffer: ", c
);
2565 puts_filtered (buf
);
2566 puts_filtered ("\n");
2570 if (bp
< buf
+ PBUFSIZ
- 1)
2578 puts_filtered ("Remote packet too long: ");
2579 puts_filtered (buf
);
2580 puts_filtered ("\n");
2587 /* Read a packet from the remote machine, with error checking, and
2588 store it in BUF. BUF is expected to be of size PBUFSIZ. If
2589 FOREVER, wait forever rather than timing out; this is used while
2590 the target is executing user code. */
2593 getpkt (buf
, forever
)
2602 strcpy (buf
,"timeout");
2606 #ifdef MAINTENANCE_CMDS
2607 timeout
= watchdog
> 0 ? watchdog
: -1;
2614 timeout
= remote_timeout
;
2618 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
2620 /* This can loop forever if the remote side sends us characters
2621 continuously, but if it pauses, we'll get a zero from readchar
2622 because of timeout. Then we'll count that as a retry. */
2624 /* Note that we will only wait forever prior to the start of a packet.
2625 After that, we expect characters to arrive at a brisk pace. They
2626 should show up within remote_timeout intervals. */
2630 c
= readchar (timeout
);
2632 if (c
== SERIAL_TIMEOUT
)
2634 #ifdef MAINTENANCE_CMDS
2635 if (forever
) /* Watchdog went off. Kill the target. */
2637 target_mourn_inferior ();
2638 error ("Watchdog has expired. Target detached.\n");
2642 puts_filtered ("Timed out.\n");
2648 /* We've found the start of a packet, now collect the data. */
2650 val
= read_frame (buf
);
2655 fprintf_unfiltered (gdb_stdout
, "Packet received: %s\n", buf
);
2656 SERIAL_WRITE (remote_desc
, "+", 1);
2660 /* Try the whole thing again. */
2662 SERIAL_WRITE (remote_desc
, "-", 1);
2665 /* We have tried hard enough, and just can't receive the packet. Give up. */
2667 printf_unfiltered ("Ignoring packet error, continuing...\n");
2668 SERIAL_WRITE (remote_desc
, "+", 1);
2674 /* For some mysterious reason, wait_for_inferior calls kill instead of
2675 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
2679 target_mourn_inferior ();
2683 /* Use catch_errors so the user can quit from gdb even when we aren't on
2684 speaking terms with the remote system. */
2685 catch_errors (putpkt
, "k", "", RETURN_MASK_ERROR
);
2687 /* Don't wait for it to die. I'm not really sure it matters whether
2688 we do or not. For the existing stubs, kill is a noop. */
2689 target_mourn_inferior ();
2695 remote_mourn_1 (&remote_ops
);
2699 extended_remote_mourn ()
2701 /* We do _not_ want to mourn the target like this; this will
2702 remove the extended remote target from the target stack,
2703 and the next time the user says "run" it'll fail.
2705 FIXME: What is the right thing to do here? */
2707 remote_mourn_1 (&extended_remote_ops
);
2711 /* Worker function for remote_mourn. */
2713 remote_mourn_1 (target
)
2714 struct target_ops
*target
;
2716 unpush_target (target
);
2717 generic_mourn_inferior ();
2720 /* In the extended protocol we want to be able to do things like
2721 "run" and have them basically work as expected. So we need
2722 a special create_inferior function.
2724 FIXME: One day add support for changing the exec file
2725 we're debugging, arguments and an environment. */
2728 extended_remote_create_inferior (exec_file
, args
, env
)
2733 /* Rip out the breakpoints; we'll reinsert them after restarting
2734 the remote server. */
2735 remove_breakpoints ();
2737 /* Now restart the remote server. */
2738 extended_remote_restart ();
2740 /* Now put the breakpoints back in. This way we're safe if the
2741 restart function works via a unix fork on the remote side. */
2742 insert_breakpoints ();
2744 /* Clean up from the last time we were running. */
2745 clear_proceed_status ();
2747 /* Let the remote process run. */
2748 proceed (-1, TARGET_SIGNAL_0
, 0);
2752 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
2753 than other targets; in those use REMOTE_BREAKPOINT instead of just
2754 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
2755 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
2756 the standard routines that are in mem-break.c. */
2758 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
2759 the choice of breakpoint instruction affects target program design and
2760 vice versa, and by making it user-tweakable, the special code here
2761 goes away and we need fewer special GDB configurations. */
2763 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
2764 #define REMOTE_BREAKPOINT
2767 #ifdef REMOTE_BREAKPOINT
2769 /* If the target isn't bi-endian, just pretend it is. */
2770 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
2771 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
2772 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
2775 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
2776 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
2778 #endif /* REMOTE_BREAKPOINT */
2780 /* Insert a breakpoint on targets that don't have any better breakpoint
2781 support. We read the contents of the target location and stash it,
2782 then overwrite it with a breakpoint instruction. ADDR is the target
2783 location in the target machine. CONTENTS_CACHE is a pointer to
2784 memory allocated for saving the target contents. It is guaranteed
2785 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
2786 is accomplished via BREAKPOINT_MAX). */
2789 remote_insert_breakpoint (addr
, contents_cache
)
2791 char *contents_cache
;
2793 #ifdef REMOTE_BREAKPOINT
2796 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
2800 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
2801 val
= target_write_memory (addr
, (char *) big_break_insn
,
2802 sizeof big_break_insn
);
2804 val
= target_write_memory (addr
, (char *) little_break_insn
,
2805 sizeof little_break_insn
);
2810 return memory_insert_breakpoint (addr
, contents_cache
);
2811 #endif /* REMOTE_BREAKPOINT */
2815 remote_remove_breakpoint (addr
, contents_cache
)
2817 char *contents_cache
;
2819 #ifdef REMOTE_BREAKPOINT
2820 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
2822 return memory_remove_breakpoint (addr
, contents_cache
);
2823 #endif /* REMOTE_BREAKPOINT */
2826 /* Some targets are only capable of doing downloads, and afterwards
2827 they switch to the remote serial protocol. This function provides
2828 a clean way to get from the download target to the remote target.
2829 It's basically just a wrapper so that we don't have to expose any
2830 of the internal workings of remote.c.
2832 Prior to calling this routine, you should shutdown the current
2833 target code, else you will get the "A program is being debugged
2834 already..." message. Usually a call to pop_target() suffices. */
2837 push_remote_target (name
, from_tty
)
2841 printf_filtered ("Switching to remote protocol\n");
2842 remote_open (name
, from_tty
);
2845 /* Other targets want to use the entire remote serial module but with
2846 certain remote_ops overridden. */
2849 open_remote_target (name
, from_tty
, target
, extended_p
)
2852 struct target_ops
*target
;
2855 printf_filtered ("Selecting the %sremote protocol\n",
2856 (extended_p
? "extended-" : ""));
2857 remote_open_1 (name
, from_tty
, target
, extended_p
);
2860 /* Table used by the crc32 function to calcuate the checksum. */
2862 static unsigned long crc32_table
[256] = {0, 0};
2864 static unsigned long
2865 crc32 (buf
, len
, crc
)
2870 if (! crc32_table
[1])
2872 /* Initialize the CRC table and the decoding table. */
2876 for (i
= 0; i
< 256; i
++)
2878 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
2879 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
2886 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
2892 /* compare-sections command
2894 With no arguments, compares each loadable section in the exec bfd
2895 with the same memory range on the target, and reports mismatches.
2896 Useful for verifying the image on the target against the exec file.
2897 Depends on the target understanding the new "qCRC:" request. */
2900 compare_sections_command (args
, from_tty
)
2905 unsigned long host_crc
, target_crc
;
2906 extern bfd
*exec_bfd
;
2907 struct cleanup
*old_chain
;
2908 char *tmp
, *sectdata
, *sectname
, buf
[PBUFSIZ
];
2915 error ("command cannot be used without an exec file");
2916 if (!current_target
.to_shortname
||
2917 strcmp (current_target
.to_shortname
, "remote") != 0)
2918 error ("command can only be used with remote target");
2920 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
2922 if (!(s
->flags
& SEC_LOAD
))
2923 continue; /* skip non-loadable section */
2925 size
= bfd_get_section_size_before_reloc (s
);
2927 continue; /* skip zero-length section */
2929 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
2930 if (args
&& strcmp (args
, sectname
) != 0)
2931 continue; /* not the section selected by user */
2933 matched
= 1; /* do this section */
2935 /* FIXME: assumes lma can fit into long */
2936 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
2939 /* be clever; compute the host_crc before waiting for target reply */
2940 sectdata
= xmalloc (size
);
2941 old_chain
= make_cleanup (free
, sectdata
);
2942 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
2943 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
2947 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
2948 sectname
, lma
, lma
+ size
);
2950 error ("remote target does not support this operation");
2952 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
2953 target_crc
= target_crc
* 16 + fromhex (*tmp
);
2955 printf_filtered ("Section %s, range 0x%08x -- 0x%08x: ",
2956 sectname
, lma
, lma
+ size
);
2957 if (host_crc
== target_crc
)
2958 printf_filtered ("matched.\n");
2961 printf_filtered ("MIS-MATCHED!\n");
2965 do_cleanups (old_chain
);
2968 warning ("One or more sections of the remote executable does not match\n\
2969 the loaded file\n");
2970 if (args
&& !matched
)
2971 printf_filtered ("No loaded section named '%s'.\n", args
);
2975 remote_query (query_type
, buf
, outbuf
, bufsiz
)
2983 char *p2
= &buf2
[0];
2987 error ("null pointer to remote bufer size specified");
2989 /* minimum outbuf size is PBUFSIZE - if bufsiz is not large enough let
2990 the caller know and return what the minimum size is */
2991 /* Note: a zero bufsiz can be used to query the minimum buffer size */
2992 if ( *bufsiz
< PBUFSIZ
)
2998 /* except for querying the minimum buffer size, target must be open */
3000 error ("remote query is only available after target open");
3002 /* we only take uppercase letters as query types, at least for now */
3003 if ( (query_type
< 'A') || (query_type
> 'Z') )
3004 error ("invalid remote query type");
3007 error ("null remote query specified");
3010 error ("remote query requires a buffer to receive data");
3017 /* we used one buffer char for the remote protocol q command and another
3018 for the query type. As the remote protocol encapsulation uses 4 chars
3019 we have PBUFZIZ -6 left to pack the query string */
3021 while ( buf
[i
] && (i
< (PBUFSIZ
- 7)) )
3023 /* bad caller may have sent forbidden characters */
3024 if ( (!isprint(buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#') )
3025 error ("illegal characters in query string");
3033 error ("query larger than avaiable buffer");
3036 if ( i
< 0 ) return i
;
3044 packet_command (args
, from_tty
)
3051 error ("command can only be used with remote target");
3054 error ("remote-packet command requires packet text as argument");
3056 puts_filtered ("sending: ");
3057 print_packet (args
);
3058 puts_filtered ("\n");
3062 puts_filtered ("received: ");
3064 puts_filtered ("\n");
3068 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
3070 static void display_thread_info
PARAMS ((struct gdb_ext_thread_info
*info
));
3072 static void threadset_test_cmd
PARAMS ((char *cmd
, int tty
));
3074 static void threadalive_test
PARAMS ((char *cmd
, int tty
));
3076 static void threadlist_test_cmd
PARAMS ((char *cmd
, int tty
));
3078 int get_and_display_threadinfo
PARAMS ((threadref
*ref
));
3080 static void threadinfo_test_cmd
PARAMS ((char *cmd
, int tty
));
3082 static int thread_display_step
PARAMS ((threadref
*ref
, void *context
));
3084 static void threadlist_update_test_cmd
PARAMS ((char *cmd
, int tty
));
3086 static void init_remote_threadtests
PARAMS ((void));
3088 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
3091 threadset_test_cmd (cmd
, tty
)
3095 int sample_thread
= SAMPLE_THREAD
;
3097 printf_filtered ("Remote threadset test\n");
3098 set_thread (sample_thread
, 1);
3103 threadalive_test (cmd
, tty
)
3107 int sample_thread
= SAMPLE_THREAD
;
3109 if (remote_thread_alive (sample_thread
))
3110 printf_filtered ("PASS: Thread alive test\n");
3112 printf_filtered ("FAIL: Thread alive test\n");
3115 void output_threadid
PARAMS ((char *title
, threadref
* ref
));
3118 output_threadid (title
, ref
)
3124 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
3126 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
3130 threadlist_test_cmd (cmd
, tty
)
3135 threadref nextthread
;
3136 int done
, result_count
;
3137 threadref threadlist
[3];
3139 printf_filtered ("Remote Threadlist test\n");
3140 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
3141 &result_count
, &threadlist
[0]))
3142 printf_filtered ("FAIL: threadlist test\n");
3145 threadref
*scan
= threadlist
;
3146 threadref
*limit
= scan
+ result_count
;
3148 while (scan
< limit
)
3149 output_threadid (" thread ", scan
++);
3154 display_thread_info (info
)
3155 struct gdb_ext_thread_info
*info
;
3157 output_threadid ("Threadid: ", &info
->threadid
);
3158 printf_filtered ("Name: %s\n ", info
->shortname
);
3159 printf_filtered ("State: %s\n", info
->display
);
3160 printf_filtered ("other: %s\n\n", info
->more_display
);
3164 get_and_display_threadinfo (ref
)
3169 struct gdb_ext_thread_info threadinfo
;
3171 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3172 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3173 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
3174 display_thread_info (&threadinfo
);
3179 threadinfo_test_cmd (cmd
, tty
)
3183 int athread
= SAMPLE_THREAD
;
3187 int_to_threadref (&thread
, athread
);
3188 printf_filtered ("Remote Threadinfo test\n");
3189 if (!get_and_display_threadinfo (&thread
))
3190 printf_filtered ("FAIL cannot get thread info\n");
3194 thread_display_step (ref
, context
)
3198 /* output_threadid(" threadstep ",ref); *//* simple test */
3199 return get_and_display_threadinfo (ref
);
3203 threadlist_update_test_cmd (cmd
, tty
)
3207 printf_filtered ("Remote Threadlist update test\n");
3208 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
3212 init_remote_threadtests (void)
3214 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
3215 "Fetch and print the remote list of thread identifiers, one pkt only");
3216 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
3217 "Fetch and display info about one thread");
3218 add_com ("tset", class_obscure
, threadset_test_cmd
,
3219 "Test setting to a different thread");
3220 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
3221 "Iterate through updating all remote thread info");
3222 add_com ("talive", class_obscure
, threadalive_test
,
3223 " Remote thread alive test ");
3231 remote_ops
.to_shortname
= "remote";
3232 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
3234 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
3235 Specify the serial device it is connected to (e.g. /dev/ttya).";
3236 remote_ops
.to_open
= remote_open
;
3237 remote_ops
.to_close
= remote_close
;
3238 remote_ops
.to_detach
= remote_detach
;
3239 remote_ops
.to_resume
= remote_resume
;
3240 remote_ops
.to_wait
= remote_wait
;
3241 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
3242 remote_ops
.to_store_registers
= remote_store_registers
;
3243 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
3244 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
3245 remote_ops
.to_files_info
= remote_files_info
;
3246 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
3247 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
3248 remote_ops
.to_kill
= remote_kill
;
3249 remote_ops
.to_load
= generic_load
;
3250 remote_ops
.to_mourn_inferior
= remote_mourn
;
3251 remote_ops
.to_thread_alive
= remote_thread_alive
;
3252 remote_ops
.to_stop
= remote_stop
;
3253 remote_ops
.to_query
= remote_query
;
3254 remote_ops
.to_stratum
= process_stratum
;
3255 remote_ops
.to_has_all_memory
= 1;
3256 remote_ops
.to_has_memory
= 1;
3257 remote_ops
.to_has_stack
= 1;
3258 remote_ops
.to_has_registers
= 1;
3259 remote_ops
.to_has_execution
= 1;
3260 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
3261 remote_ops
.to_magic
= OPS_MAGIC
;
3264 /* Set up the extended remote vector by making a copy of the standard
3265 remote vector and adding to it. */
3268 init_extended_remote_ops ()
3270 extended_remote_ops
= remote_ops
;
3272 extended_remote_ops
.to_shortname
= "extended-remote";
3273 extended_remote_ops
.to_longname
=
3274 "Extended remote serial target in gdb-specific protocol";
3275 extended_remote_ops
.to_doc
=
3276 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
3277 Specify the serial device it is connected to (e.g. /dev/ttya).",
3278 extended_remote_ops
.to_open
= extended_remote_open
;
3279 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
3280 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
3284 _initialize_remote ()
3287 add_target (&remote_ops
);
3289 init_extended_remote_ops ();
3290 add_target (&extended_remote_ops
);
3291 init_remote_threads ();
3293 init_remote_threadtests ();
3296 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
3297 "Compare section data on target to the exec file.\n\
3298 Argument is a single section name (default: all loaded sections).",
3301 add_cmd ("packet", class_maintenance
, packet_command
,
3302 "Send an arbitrary packet to a remote target.\n\
3303 maintenance packet TEXT\n\
3304 If GDB is talking to an inferior via the GDB serial protocol, then\n\
3305 this command sends the string TEXT to the inferior, and displays the\n\
3306 response packet. GDB supplies the initial `$' character, and the\n\
3307 terminating `#' character and checksum.",
3311 (add_set_cmd ("remotetimeout", no_class
,
3312 var_integer
, (char *)&remote_timeout
,
3313 "Set timeout value for remote read.\n",
3318 (add_set_cmd ("remotebreak", no_class
,
3319 var_integer
, (char *)&remote_break
,
3320 "Set whether to send break if interrupted.\n",
3325 (add_set_cmd ("remotewritesize", no_class
,
3326 var_integer
, (char *)&remote_write_size
,
3327 "Set the maximum number of bytes per memory write packet.\n",
3331 remote_address_size
= TARGET_PTR_BIT
;
3333 (add_set_cmd ("remoteaddresssize", class_obscure
,
3334 var_integer
, (char *)&remote_address_size
,
3335 "Set the maximum size of the address (in bits) \
3336 in a memory packet.\n",