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 hexnumstr
PARAMS ((char *, ULONGEST
));
291 static CORE_ADDR remote_address_masked
PARAMS ((CORE_ADDR
));
293 static void print_packet
PARAMS ((char *));
295 static unsigned long crc32
PARAMS ((unsigned char *, int, unsigned int));
297 static void compare_sections_command
PARAMS ((char *, int));
299 static void packet_command
PARAMS ((char *, int));
301 static int stub_unpack_int
PARAMS ((char *buff
, int fieldlength
));
303 char *unpack_varlen_hex
PARAMS ((char *buff
, int *result
));
305 static char *unpack_nibble
PARAMS ((char *buf
, int *val
));
307 static char *pack_nibble
PARAMS ((char *buf
, int nibble
));
309 static char *pack_hex_byte
PARAMS ((char *pkt
, unsigned char byte
));
311 static char *unpack_byte
PARAMS ((char *buf
, int *value
));
313 static char *pack_int
PARAMS ((char *buf
, int value
));
315 static char *unpack_int
PARAMS ((char *buf
, int *value
));
317 static char *unpack_string
PARAMS ((char *src
, char *dest
, int length
));
319 static char *pack_threadid
PARAMS ((char *pkt
, threadref
*id
));
321 static char *unpack_threadid
PARAMS ((char *inbuf
, threadref
*id
));
323 void int_to_threadref
PARAMS ((threadref
*id
, int value
));
325 static int threadref_to_int
PARAMS ((threadref
*ref
));
327 static void copy_threadref
PARAMS ((threadref
*dest
, threadref
*src
));
329 static int threadmatch
PARAMS ((threadref
*dest
, threadref
*src
));
331 static char *pack_threadinfo_request
PARAMS ((char *pkt
, int mode
,
334 static int remote_unpack_thread_info_response
PARAMS ((char *pkt
,
335 threadref
*expectedref
,
336 struct gdb_ext_thread_info
*info
));
339 static int remote_get_threadinfo
PARAMS ((threadref
*threadid
,
340 int fieldset
, /*TAG mask */
341 struct gdb_ext_thread_info
*info
));
343 static int adapt_remote_get_threadinfo
PARAMS ((gdb_threadref
*ref
,
345 struct gdb_ext_thread_info
*info
));
347 static char *pack_threadlist_request
PARAMS ((char *pkt
, int startflag
,
349 threadref
*nextthread
));
351 static int parse_threadlist_response
PARAMS ((char *pkt
,
353 threadref
*original_echo
,
354 threadref
*resultlist
,
357 static int remote_get_threadlist
PARAMS ((int startflag
,
358 threadref
*nextthread
,
362 threadref
*threadlist
));
364 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
366 static int remote_threadlist_iterator
PARAMS ((rmt_thread_action stepfunction
,
367 void *context
, int looplimit
));
369 static int remote_newthread_step
PARAMS ((threadref
*ref
, void *context
));
371 static int remote_current_thread
PARAMS ((int oldpid
));
373 int remote_find_new_threads
PARAMS ((void));
375 static void record_currthread
PARAMS ((int currthread
));
377 static void init_remote_threads
PARAMS ((void));
379 /* exported functions */
381 extern int fromhex
PARAMS ((int a
));
383 extern void getpkt
PARAMS ((char *buf
, int forever
));
385 extern int putpkt
PARAMS ((char *buf
));
387 void remote_console_output
PARAMS ((char *));
389 /* Define the target subroutine names */
391 void open_remote_target
PARAMS ((char *, int, struct target_ops
*, int));
393 void _initialize_remote
PARAMS ((void));
397 static struct target_ops remote_ops
;
399 static struct target_ops extended_remote_ops
;
401 static struct target_thread_vector remote_thread_vec
;
403 /* This was 5 seconds, which is a long time to sit and wait.
404 Unless this is going though some terminal server or multiplexer or
405 other form of hairy serial connection, I would think 2 seconds would
408 /* Changed to allow option to set timeout value.
409 was static int remote_timeout = 2; */
410 extern int remote_timeout
;
412 /* This variable chooses whether to send a ^C or a break when the user
413 requests program interruption. Although ^C is usually what remote
414 systems expect, and that is the default here, sometimes a break is
415 preferable instead. */
417 static int remote_break
;
419 /* Has the user attempted to interrupt the target? If so, then offer
420 the user the opportunity to bail out completely if he interrupts
422 static int interrupted_already
= 0;
424 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
425 remote_open knows that we don't have a file open when the program
427 static serial_t remote_desc
= NULL
;
429 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
430 and i386-stub.c. Normally, no one would notice because it only matters
431 for writing large chunks of memory (e.g. in downloads). Also, this needs
432 to be more than 400 if required to hold the registers (see below, where
433 we round it up based on REGISTER_BYTES). */
436 /* Maximum number of bytes to read/write at once. The value here
437 is chosen to fill up a packet (the headers account for the 32). */
438 #define MAXBUFBYTES ((PBUFSIZ-32)/2)
440 /* Round up PBUFSIZ to hold all the registers, at least. */
441 /* The blank line after the #if seems to be required to work around a
442 bug in HP's PA compiler. */
443 #if REGISTER_BYTES > MAXBUFBYTES
446 #define PBUFSIZ (REGISTER_BYTES * 2 + 32)
450 /* This variable sets the number of bytes to be written to the target
451 in a single packet. Normally PBUFSIZ is satisfactory, but some
452 targets need smaller values (perhaps because the receiving end
455 static int remote_write_size
= PBUFSIZ
;
457 /* This variable sets the number of bits in an address that are to be
458 sent in a memory ("M" or "m") packet. Normally, after stripping
459 leading zeros, the entire address would be sent. This variable
460 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
461 initial implementation of remote.c restricted the address sent in
462 memory packets to ``host::sizeof long'' bytes - (typically 32
463 bits). Consequently, for 64 bit targets, the upper 32 bits of an
464 address was never sent. Since fixing this bug may cause a break in
465 some remote targets this variable is principly provided to
466 facilitate backward compatibility. */
468 static int remote_address_size
;
470 /* This is the size (in chars) of the first response to the `g' command. This
471 is used to limit the size of the memory read and write commands to prevent
472 stub buffers from overflowing. The size does not include headers and
473 trailers, it is only the payload size. */
475 static int remote_register_buf_size
= 0;
477 /* Should we try the 'P' request? If this is set to one when the stub
478 doesn't support 'P', the only consequence is some unnecessary traffic. */
479 static int stub_supports_P
= 1;
481 /* These are pointers to hook functions that may be set in order to
482 modify resume/wait behavior for a particular architecture. */
484 void (*target_resume_hook
) PARAMS ((void));
485 void (*target_wait_loop_hook
) PARAMS ((void));
489 /* These are the threads which we last sent to the remote system.
490 -1 for all or -2 for not sent yet. */
491 static int general_thread
;
492 static int cont_thread
;
494 /* Call this function as a result of
495 1) A halt indication (T packet) containing a thread id
496 2) A direct query of currthread
497 3) Successful execution of set thread
501 record_currthread (currthread
)
504 #if 0 /* target_wait must not modify inferior_pid! */
505 inferior_pid
= currthread
;
507 general_thread
= currthread
;
508 #if 0 /* setting cont_thread has a different meaning
509 from having the target report its thread id. */
510 cont_thread
= currthread
;
512 /* If this is a new thread, add it to GDB's thread list.
513 If we leave it up to WFI to do this, bad things will happen. */
514 if (!in_thread_list (currthread
))
515 add_thread (currthread
);
518 #define MAGIC_NULL_PID 42000
526 int state
= gen
? general_thread
: cont_thread
;
532 buf
[1] = gen
? 'g' : 'c';
533 if (th
== MAGIC_NULL_PID
)
539 sprintf (&buf
[2], "-%x", -th
);
541 sprintf (&buf
[2], "%x", th
);
550 /* Return nonzero if the thread TH is still alive on the remote system. */
553 remote_thread_alive (th
)
560 sprintf (&buf
[1], "-%08x", -th
);
562 sprintf (&buf
[1], "%08x", th
);
565 return (buf
[0] == 'O' && buf
[1] == 'K');
568 /* About these extended threadlist and threadinfo packets. They are
569 variable length packets but, the fields within them are often fixed
570 length. They are redundent enough to send over UDP as is the
571 remote protocol in general. There is a matching unit test module
574 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
576 /* encode 64 bits in 16 chars of hex */
578 static const char hexchars
[] = "0123456789abcdef";
585 if ((ch
>= 'a') && (ch
<= 'f'))
587 *val
= ch
- 'a' + 10;
590 if ((ch
>= 'A') && (ch
<= 'F'))
592 *val
= ch
- 'A' + 10;
595 if ((ch
>= '0') && (ch
<= '9'))
607 if (ch
>= 'a' && ch
<= 'f')
608 return ch
- 'a' + 10;
609 if (ch
>= '0' && ch
<= '9')
611 if (ch
>= 'A' && ch
<= 'F')
612 return ch
- 'A' + 10;
617 stub_unpack_int (buff
, fieldlength
)
626 nibble
= stubhex (*buff
++);
630 retval
= retval
<< 4;
636 unpack_varlen_hex (buff
, result
)
637 char *buff
; /* packet to parse */
643 while (ishex (*buff
, &nibble
))
646 retval
= retval
<< 4;
647 retval
|= nibble
& 0x0f;
654 unpack_nibble (buf
, val
)
663 pack_nibble (buf
, nibble
)
667 *buf
++ = hexchars
[(nibble
& 0x0f)];
672 pack_hex_byte (pkt
, byte
)
676 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
677 *pkt
++ = hexchars
[(byte
& 0xf)];
682 unpack_byte (buf
, value
)
686 *value
= stub_unpack_int (buf
, 2);
691 pack_int (buf
, value
)
695 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
696 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
697 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
698 buf
= pack_hex_byte (buf
, (value
& 0xff));
703 unpack_int (buf
, value
)
707 *value
= stub_unpack_int (buf
, 8);
711 #if 0 /* currently unused, uncomment when needed */
712 static char *pack_string
PARAMS ((char *pkt
, char *string
));
715 pack_string (pkt
, string
)
722 len
= strlen (string
);
724 len
= 200; /* Bigger than most GDB packets, junk??? */
725 pkt
= pack_hex_byte (pkt
, len
);
729 if ((ch
== '\0') || (ch
== '#'))
730 ch
= '*'; /* Protect encapsulation */
735 #endif /* 0 (unused) */
738 unpack_string (src
, dest
, length
)
750 pack_threadid (pkt
, id
)
755 unsigned char *altid
;
757 altid
= (unsigned char *) id
;
758 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
760 pkt
= pack_hex_byte (pkt
, *altid
++);
766 unpack_threadid (inbuf
, id
)
771 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
774 altref
= (char *) id
;
776 while (inbuf
< limit
)
778 x
= stubhex (*inbuf
++);
779 y
= stubhex (*inbuf
++);
780 *altref
++ = (x
<< 4) | y
;
785 /* Externally, threadrefs are 64 bits but internally, they are still
786 ints. This is due to a mismatch of specifications. We would like
787 to use 64bit thread references internally. This is an adapter
791 int_to_threadref (id
, value
)
797 scan
= (unsigned char *) id
;
803 *scan
++ = (value
>> 24) & 0xff;
804 *scan
++ = (value
>> 16) & 0xff;
805 *scan
++ = (value
>> 8) & 0xff;
806 *scan
++ = (value
& 0xff);
810 threadref_to_int (ref
)
820 value
= (value
<< 8) | ((*scan
++) & 0xff);
825 copy_threadref (dest
, src
)
830 unsigned char *csrc
, *cdest
;
832 csrc
= (unsigned char *) src
;
833 cdest
= (unsigned char *) dest
;
840 threadmatch (dest
, src
)
844 /* things are broken right now, so just assume we got a match */
846 unsigned char *srcp
, *destp
;
849 destp
= (char *) dest
;
853 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
860 threadid:1, # always request threadid
867 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
870 pack_threadinfo_request (pkt
, mode
, id
)
875 *pkt
++ = 'q'; /* Info Query */
876 *pkt
++ = 'P'; /* process or thread info */
877 pkt
= pack_int (pkt
, mode
); /* mode */
878 pkt
= pack_threadid (pkt
, id
); /* threadid */
879 *pkt
= '\0'; /* terminate */
883 /* These values tag the fields in a thread info response packet */
884 /* Tagging the fields allows us to request specific fields and to
885 add more fields as time goes by */
887 #define TAG_THREADID 1 /* Echo the thread identifier */
888 #define TAG_EXISTS 2 /* Is this process defined enough to
889 fetch registers and its stack */
890 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
891 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
892 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
896 remote_unpack_thread_info_response (pkt
, expectedref
, info
)
898 threadref
*expectedref
;
899 struct gdb_ext_thread_info
*info
;
904 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
907 /* info->threadid = 0; FIXME: implement zero_threadref */
909 info
->display
[0] = '\0';
910 info
->shortname
[0] = '\0';
911 info
->more_display
[0] = '\0';
913 /* Assume the characters indicating the packet type have been stripped */
914 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
915 pkt
= unpack_threadid (pkt
, &ref
);
918 warning ("Incomplete response to threadinfo request\n");
919 if (!threadmatch (&ref
, expectedref
))
920 { /* This is an answer to a different request */
921 warning ("ERROR RMT Thread info mismatch\n");
924 copy_threadref (&info
->threadid
, &ref
);
926 /* Loop on tagged fields , try to bail if somthing goes wrong */
928 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
930 pkt
= unpack_int (pkt
, &tag
); /* tag */
931 pkt
= unpack_byte (pkt
, &length
); /* length */
932 if (!(tag
& mask
)) /* tags out of synch with mask */
934 warning ("ERROR RMT: threadinfo tag mismatch\n");
938 if (tag
== TAG_THREADID
)
942 warning ("ERROR RMT: length of threadid is not 16\n");
946 pkt
= unpack_threadid (pkt
, &ref
);
947 mask
= mask
& ~TAG_THREADID
;
950 if (tag
== TAG_EXISTS
)
952 info
->active
= stub_unpack_int (pkt
, length
);
954 mask
= mask
& ~(TAG_EXISTS
);
957 warning ("ERROR RMT: 'exists' length too long\n");
963 if (tag
== TAG_THREADNAME
)
965 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
966 mask
= mask
& ~TAG_THREADNAME
;
969 if (tag
== TAG_DISPLAY
)
971 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
972 mask
= mask
& ~TAG_DISPLAY
;
975 if (tag
== TAG_MOREDISPLAY
)
977 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
978 mask
= mask
& ~TAG_MOREDISPLAY
;
981 warning ("ERROR RMT: unknown thread info tag\n");
982 break; /* Not a tag we know about */
988 remote_get_threadinfo (threadid
, fieldset
, info
)
990 int fieldset
; /* TAG mask */
991 struct gdb_ext_thread_info
*info
;
994 char threadinfo_pkt
[PBUFSIZ
];
996 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
997 putpkt (threadinfo_pkt
);
998 getpkt (threadinfo_pkt
, 0);
999 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1004 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1005 representation of a threadid. */
1008 adapt_remote_get_threadinfo (ref
, selection
, info
)
1011 struct gdb_ext_thread_info
*info
;
1015 int_to_threadref (&lclref
, *ref
);
1016 return remote_get_threadinfo (&lclref
, selection
, info
);
1019 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1022 pack_threadlist_request (pkt
, startflag
, threadcount
, nextthread
)
1026 threadref
*nextthread
;
1028 *pkt
++ = 'q'; /* info query packet */
1029 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1030 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1031 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1032 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1037 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1040 parse_threadlist_response (pkt
, result_limit
, original_echo
, resultlist
,
1044 threadref
*original_echo
;
1045 threadref
*resultlist
;
1049 int count
, resultcount
, done
;
1052 /* Assume the 'q' and 'M chars have been stripped. */
1053 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1054 pkt
= unpack_byte (pkt
, &count
); /* count field */
1055 pkt
= unpack_nibble (pkt
, &done
);
1056 /* The first threadid is the argument threadid. */
1057 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1058 while ((count
-- > 0) && (pkt
< limit
))
1060 pkt
= unpack_threadid (pkt
, resultlist
++);
1061 if (resultcount
++ >= result_limit
)
1070 remote_get_threadlist (startflag
, nextthread
, result_limit
,
1071 done
, result_count
, threadlist
)
1073 threadref
*nextthread
;
1077 threadref
*threadlist
;
1080 static threadref echo_nextthread
;
1081 char threadlist_packet
[PBUFSIZ
];
1082 char t_response
[PBUFSIZ
];
1085 /* Trancate result limit to be smaller than the packet size */
1086 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1087 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1089 pack_threadlist_request (threadlist_packet
,
1090 startflag
, result_limit
, nextthread
);
1091 putpkt (threadlist_packet
);
1092 getpkt (t_response
, 0);
1095 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1098 if (!threadmatch (&echo_nextthread
, nextthread
))
1100 /* FIXME: This is a good reason to drop the packet */
1101 /* Possably, there is a duplicate response */
1103 retransmit immediatly - race conditions
1104 retransmit after timeout - yes
1106 wait for packet, then exit
1108 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1109 return 0; /* I choose simply exiting */
1111 if (*result_count
<= 0)
1115 warning ("RMT ERROR : failed to get remote thread list\n");
1118 return result
; /* break; */
1120 if (*result_count
> result_limit
)
1123 warning ("RMT ERROR: threadlist response longer than requested\n");
1129 /* This is the interface between remote and threads, remotes upper interface */
1131 /* remote_find_new_threads retrieves the thread list and for each
1132 thread in the list, looks up the thread in GDB's internal list,
1133 ading the thread if it does not already exist. This involves
1134 getting partial thread lists from the remote target so, polling the
1135 quit_flag is required. */
1138 /* About this many threadisds fit in a packet. */
1140 #define MAXTHREADLISTRESULTS 32
1143 remote_threadlist_iterator (stepfunction
, context
, looplimit
)
1144 rmt_thread_action stepfunction
;
1148 int done
, i
, result_count
;
1152 static threadref nextthread
;
1153 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1158 if (loopcount
++ > looplimit
)
1161 warning ("Remote fetch threadlist -infinite loop-\n");
1164 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1165 &done
, &result_count
, resultthreadlist
))
1170 /* clear for later iterations */
1172 /* Setup to resume next batch of thread references, set nextthread. */
1173 if (result_count
>= 1)
1174 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1176 while (result_count
--)
1177 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1184 remote_newthread_step (ref
, context
)
1190 pid
= threadref_to_int (ref
);
1191 if (!in_thread_list (pid
))
1193 return 1; /* continue iterator */
1196 #define CRAZY_MAX_THREADS 1000
1199 remote_current_thread (oldpid
)
1206 if (buf
[0] == 'Q' && buf
[1] == 'C')
1207 return strtol (&buf
[2], NULL
, 16);
1213 remote_find_new_threads ()
1217 ret
= remote_threadlist_iterator (remote_newthread_step
, 0,
1219 if (inferior_pid
== MAGIC_NULL_PID
) /* ack ack ack */
1220 inferior_pid
= remote_current_thread (inferior_pid
);
1224 /* Initialize the thread vector which is used by threads.c */
1225 /* The thread stub is a package, it has an initializer */
1228 init_remote_threads ()
1230 remote_thread_vec
.find_new_threads
= remote_find_new_threads
;
1231 remote_thread_vec
.get_thread_info
= adapt_remote_get_threadinfo
;
1235 /* Restart the remote side; this is an extended protocol operation. */
1238 extended_remote_restart ()
1242 /* Send the restart command; for reasons I don't understand the
1243 remote side really expects a number after the "R". */
1245 sprintf (&buf
[1], "%x", 0);
1248 /* Now query for status so this looks just like we restarted
1249 gdbserver from scratch. */
1254 /* Clean up connection to a remote debugger. */
1258 remote_close (quitting
)
1262 SERIAL_CLOSE (remote_desc
);
1266 /* Query the remote side for the text, data and bss offsets. */
1271 char buf
[PBUFSIZ
], *ptr
;
1273 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1274 struct section_offsets
*offs
;
1276 putpkt ("qOffsets");
1280 if (buf
[0] == '\000')
1281 return; /* Return silently. Stub doesn't support
1285 warning ("Remote failure reply: %s", buf
);
1289 /* Pick up each field in turn. This used to be done with scanf, but
1290 scanf will make trouble if CORE_ADDR size doesn't match
1291 conversion directives correctly. The following code will work
1292 with any size of CORE_ADDR. */
1293 text_addr
= data_addr
= bss_addr
= 0;
1297 if (strncmp (ptr
, "Text=", 5) == 0)
1300 /* Don't use strtol, could lose on big values. */
1301 while (*ptr
&& *ptr
!= ';')
1302 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1307 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1310 while (*ptr
&& *ptr
!= ';')
1311 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1316 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1319 while (*ptr
&& *ptr
!= ';')
1320 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1326 error ("Malformed response to offset query, %s", buf
);
1328 if (symfile_objfile
== NULL
)
1331 offs
= (struct section_offsets
*) alloca (sizeof (struct section_offsets
)
1332 + symfile_objfile
->num_sections
1333 * sizeof (offs
->offsets
));
1334 memcpy (offs
, symfile_objfile
->section_offsets
,
1335 sizeof (struct section_offsets
)
1336 + symfile_objfile
->num_sections
1337 * sizeof (offs
->offsets
));
1339 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
1341 /* This is a temporary kludge to force data and bss to use the same offsets
1342 because that's what nlmconv does now. The real solution requires changes
1343 to the stub and remote.c that I don't have time to do right now. */
1345 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
1346 ANOFFSET (offs
, SECT_OFF_BSS
) = data_addr
;
1348 objfile_relocate (symfile_objfile
, offs
);
1351 /* Stub for catch_errors. */
1354 remote_start_remote (dummy
)
1357 immediate_quit
= 1; /* Allow user to interrupt it */
1359 /* Ack any packet which the remote side has already sent. */
1360 SERIAL_WRITE (remote_desc
, "+", 1);
1362 /* Let the stub know that we want it to return the thread. */
1365 inferior_pid
= remote_current_thread (inferior_pid
);
1367 get_offsets (); /* Get text, data & bss offsets */
1369 putpkt ("?"); /* initiate a query from remote machine */
1372 start_remote (); /* Initialize gdb process mechanisms */
1376 /* Open a connection to a remote debugger.
1377 NAME is the filename used for communication. */
1380 remote_open (name
, from_tty
)
1384 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
1387 /* Open a connection to a remote debugger using the extended
1388 remote gdb protocol. NAME is the filename used for communication. */
1391 extended_remote_open (name
, from_tty
)
1395 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1/*extended_p*/);
1398 /* Generic code for opening a connection to a remote target. */
1400 static DCACHE
*remote_dcache
;
1403 remote_open_1 (name
, from_tty
, target
, extended_p
)
1406 struct target_ops
*target
;
1410 error ("To open a remote debug connection, you need to specify what\n\
1411 serial device is attached to the remote system (e.g. /dev/ttya).");
1413 target_preopen (from_tty
);
1415 unpush_target (target
);
1417 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1419 remote_desc
= SERIAL_OPEN (name
);
1421 perror_with_name (name
);
1423 if (baud_rate
!= -1)
1425 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1427 SERIAL_CLOSE (remote_desc
);
1428 perror_with_name (name
);
1433 SERIAL_RAW (remote_desc
);
1435 /* If there is something sitting in the buffer we might take it as a
1436 response to a command, which would be bad. */
1437 SERIAL_FLUSH_INPUT (remote_desc
);
1441 puts_filtered ("Remote debugging using ");
1442 puts_filtered (name
);
1443 puts_filtered ("\n");
1445 push_target (target
); /* Switch to using remote target now */
1447 /* The target vector does not have the thread functions in it yet,
1448 so we use this function to call back into the thread module and
1449 register the thread vector and its contained functions. */
1450 bind_target_thread_vector (&remote_thread_vec
);
1452 /* Start out by trying the 'P' request to set registers. We set
1453 this each time that we open a new target so that if the user
1454 switches from one stub to another, we can (if the target is
1455 closed and reopened) cope. */
1456 stub_supports_P
= 1;
1458 general_thread
= -2;
1461 /* Without this, some commands which require an active target (such
1462 as kill) won't work. This variable serves (at least) double duty
1463 as both the pid of the target process (if it has such), and as a
1464 flag indicating that a target is active. These functions should
1465 be split out into seperate variables, especially since GDB will
1466 someday have a notion of debugging several processes. */
1468 inferior_pid
= MAGIC_NULL_PID
;
1469 /* Start the remote connection; if error (0), discard this target.
1470 In particular, if the user quits, be sure to discard it
1471 (we'd be in an inconsistent state otherwise). */
1472 if (!catch_errors (remote_start_remote
, (char *)0,
1473 "Couldn't establish connection to remote target\n",
1482 /* tell the remote that we're using the extended protocol. */
1489 /* This takes a program previously attached to and detaches it. After
1490 this is done, GDB can be used to debug some other program. We
1491 better not have left any breakpoints in the target program or it'll
1492 die when it hits one. */
1495 remote_detach (args
, from_tty
)
1502 error ("Argument given to \"detach\" when remotely debugging.");
1504 /* Tell the remote target to detach. */
1510 puts_filtered ("Ending remote debugging.\n");
1513 /* Convert hex digit A to a number. */
1519 if (a
>= '0' && a
<= '9')
1521 else if (a
>= 'a' && a
<= 'f')
1522 return a
- 'a' + 10;
1523 else if (a
>= 'A' && a
<= 'F')
1524 return a
- 'A' + 10;
1526 error ("Reply contains invalid hex digit %d", a
);
1529 /* Convert number NIB to a hex digit. */
1541 /* Tell the remote machine to resume. */
1543 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
1545 static int last_sent_step
;
1548 remote_resume (pid
, step
, siggnal
)
1550 enum target_signal siggnal
;
1555 set_thread (0, 0); /* run any thread */
1557 set_thread (pid
, 0); /* run this thread */
1559 dcache_flush (remote_dcache
);
1561 last_sent_signal
= siggnal
;
1562 last_sent_step
= step
;
1564 /* A hook for when we need to do something at the last moment before
1566 if (target_resume_hook
)
1567 (*target_resume_hook
) ();
1569 if (siggnal
!= TARGET_SIGNAL_0
)
1571 buf
[0] = step
? 'S' : 'C';
1572 buf
[1] = tohex (((int)siggnal
>> 4) & 0xf);
1573 buf
[2] = tohex ((int)siggnal
& 0xf);
1577 strcpy (buf
, step
? "s": "c");
1582 /* Send ^C to target to halt it. Target will respond, and send us a
1585 static void (*ofunc
) PARAMS ((int));
1588 remote_interrupt (signo
)
1592 signal (signo
, remote_interrupt
);
1598 if (!interrupted_already
)
1600 /* Send a break or a ^C, depending on user preference. */
1601 interrupted_already
= 1;
1604 printf_unfiltered ("remote_stop called\n");
1607 SERIAL_SEND_BREAK (remote_desc
);
1609 SERIAL_WRITE (remote_desc
, "\003", 1);
1613 signal (SIGINT
, ofunc
);
1615 signal (SIGINT
, remote_interrupt
);
1616 interrupted_already
= 0;
1620 /* Ask the user what to do when an interrupt is received. */
1625 target_terminal_ours ();
1627 if (query ("Interrupted while waiting for the program.\n\
1628 Give up (and stop debugging it)? "))
1630 target_mourn_inferior ();
1631 return_to_top_level (RETURN_QUIT
);
1634 target_terminal_inferior ();
1637 /* If nonzero, ignore the next kill. */
1642 remote_console_output (msg
)
1647 for (p
= msg
; *p
; p
+=2)
1650 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
1653 if (target_output_hook
)
1654 target_output_hook (tb
);
1656 fputs_filtered (tb
, gdb_stdout
);
1660 /* Wait until the remote machine stops, then return, storing status in
1661 STATUS just as `wait' would. Returns "pid" (though it's not clear
1662 what, if anything, that means in the case of this target). */
1665 remote_wait (pid
, status
)
1667 struct target_waitstatus
*status
;
1669 unsigned char buf
[PBUFSIZ
];
1670 int thread_num
= -1;
1672 status
->kind
= TARGET_WAITKIND_EXITED
;
1673 status
->value
.integer
= 0;
1679 interrupted_already
= 0;
1680 ofunc
= signal (SIGINT
, remote_interrupt
);
1681 getpkt ((char *) buf
, 1);
1682 signal (SIGINT
, ofunc
);
1684 /* This is a hook for when we need to do something (perhaps the
1685 collection of trace data) every time the target stops. */
1686 if (target_wait_loop_hook
)
1687 (*target_wait_loop_hook
) ();
1691 case 'E': /* Error of some sort */
1692 warning ("Remote failure reply: %s", buf
);
1694 case 'T': /* Status with PC, SP, FP, ... */
1698 char regs
[MAX_REGISTER_RAW_SIZE
];
1700 /* Expedited reply, containing Signal, {regno, reg} repeat */
1701 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
1703 n... = register number
1704 r... = register contents
1706 p
= &buf
[3]; /* after Txx */
1713 /* Read the register number */
1714 regno
= strtol ((const char *) p
, &p_temp
, 16);
1715 p1
= (unsigned char *)p_temp
;
1717 if (p1
== p
) /* No register number present here */
1719 p1
= (unsigned char *) strchr ((const char *) p
, ':');
1721 warning ("Malformed packet(a) (missing colon): %s\n\
1724 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
1726 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
1727 record_currthread (thread_num
);
1728 p
= (unsigned char *) p_temp
;
1736 warning ("Malformed packet(b) (missing colon): %s\n\
1740 if (regno
>= NUM_REGS
)
1741 warning ("Remote sent bad register number %ld: %s\n\
1745 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
1747 if (p
[0] == 0 || p
[1] == 0)
1748 warning ("Remote reply is too short: %s", buf
);
1749 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
1752 supply_register (regno
, regs
);
1757 warning ("Remote register badly formatted: %s", buf
);
1758 warning (" here: %s",p
);
1763 case 'S': /* Old style status, just signal only */
1764 status
->kind
= TARGET_WAITKIND_STOPPED
;
1765 status
->value
.sig
= (enum target_signal
)
1766 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
1769 case 'W': /* Target exited */
1771 /* The remote process exited. */
1772 status
->kind
= TARGET_WAITKIND_EXITED
;
1773 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
1777 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
1778 status
->value
.sig
= (enum target_signal
)
1779 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
1783 case 'O': /* Console output */
1784 remote_console_output (buf
+ 1);
1787 if (last_sent_signal
!= TARGET_SIGNAL_0
)
1789 /* Zero length reply means that we tried 'S' or 'C' and
1790 the remote system doesn't support it. */
1791 target_terminal_ours_for_output ();
1793 ("Can't send signals to this remote system. %s not sent.\n",
1794 target_signal_to_name (last_sent_signal
));
1795 last_sent_signal
= TARGET_SIGNAL_0
;
1796 target_terminal_inferior ();
1798 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
1799 putpkt ((char *) buf
);
1802 /* else fallthrough */
1804 warning ("Invalid remote reply: %s", buf
);
1809 if (thread_num
!= -1)
1811 /* Initial thread value can only be acquired via wait, so deal with
1812 this marker which is used before the first thread value is
1814 if (inferior_pid
== MAGIC_NULL_PID
)
1816 inferior_pid
= thread_num
;
1817 add_thread (inferior_pid
);
1821 return inferior_pid
;
1824 /* Number of bytes of registers this stub implements. */
1826 static int register_bytes_found
;
1828 /* Read the remote registers into the block REGS. */
1829 /* Currently we just read all the registers, so we don't use regno. */
1833 remote_fetch_registers (regno
)
1839 char regs
[REGISTER_BYTES
];
1841 set_thread (inferior_pid
, 1);
1846 if (remote_register_buf_size
== 0)
1847 remote_register_buf_size
= strlen (buf
);
1849 /* Unimplemented registers read as all bits zero. */
1850 memset (regs
, 0, REGISTER_BYTES
);
1852 /* We can get out of synch in various cases. If the first character
1853 in the buffer is not a hex character, assume that has happened
1854 and try to fetch another packet to read. */
1855 while ((buf
[0] < '0' || buf
[0] > '9')
1856 && (buf
[0] < 'a' || buf
[0] > 'f')
1857 && buf
[0] != 'x') /* New: unavailable register value */
1860 printf_unfiltered ("Bad register packet; fetching a new packet\n");
1864 /* Reply describes registers byte by byte, each byte encoded as two
1865 hex characters. Suck them all up, then supply them to the
1866 register cacheing/storage mechanism. */
1869 for (i
= 0; i
< REGISTER_BYTES
; i
++)
1875 warning ("Remote reply is of odd length: %s", buf
);
1876 /* Don't change register_bytes_found in this case, and don't
1877 print a second warning. */
1880 if (p
[0] == 'x' && p
[1] == 'x')
1881 regs
[i
] = 0; /* 'x' */
1883 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
1887 if (i
!= register_bytes_found
)
1889 register_bytes_found
= i
;
1890 #ifdef REGISTER_BYTES_OK
1891 if (!REGISTER_BYTES_OK (i
))
1892 warning ("Remote reply is too short: %s", buf
);
1897 for (i
= 0; i
< NUM_REGS
; i
++)
1899 supply_register (i
, ®s
[REGISTER_BYTE(i
)]);
1900 if (buf
[REGISTER_BYTE(i
) * 2] == 'x')
1901 register_valid
[i
] = -1; /* register value not available */
1905 /* Prepare to store registers. Since we may send them all (using a
1906 'G' request), we have to read out the ones we don't want to change
1910 remote_prepare_to_store ()
1912 /* Make sure the entire registers array is valid. */
1913 read_register_bytes (0, (char *)NULL
, REGISTER_BYTES
);
1916 /* Store register REGNO, or all registers if REGNO == -1, from the contents
1917 of REGISTERS. FIXME: ignores errors. */
1920 remote_store_registers (regno
)
1927 set_thread (inferior_pid
, 1);
1929 if (regno
>= 0 && stub_supports_P
)
1931 /* Try storing a single register. */
1934 sprintf (buf
, "P%x=", regno
);
1935 p
= buf
+ strlen (buf
);
1936 regp
= ®isters
[REGISTER_BYTE (regno
)];
1937 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
1939 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
1940 *p
++ = tohex (regp
[i
] & 0xf);
1946 /* The stub understands the 'P' request. We are done. */
1950 /* The stub does not support the 'P' request. Use 'G' instead,
1951 and don't try using 'P' in the future (it will just waste our
1953 stub_supports_P
= 0;
1958 /* Command describes registers byte by byte,
1959 each byte encoded as two hex characters. */
1962 /* remote_prepare_to_store insures that register_bytes_found gets set. */
1963 for (i
= 0; i
< register_bytes_found
; i
++)
1965 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
1966 *p
++ = tohex (registers
[i
] & 0xf);
1973 /* Use of the data cache *used* to be disabled because it loses for looking
1974 at and changing hardware I/O ports and the like. Accepting `volatile'
1975 would perhaps be one way to fix it. Another idea would be to use the
1976 executable file for the text segment (for all SEC_CODE sections?
1977 For all SEC_READONLY sections?). This has problems if you want to
1978 actually see what the memory contains (e.g. self-modifying code,
1979 clobbered memory, user downloaded the wrong thing).
1981 Because it speeds so much up, it's now enabled, if you're playing
1982 with registers you turn it of (set remotecache 0). */
1984 /* Read a word from remote address ADDR and return it.
1985 This goes through the data cache. */
1989 remote_fetch_word (addr
)
1992 return dcache_fetch (remote_dcache
, addr
);
1995 /* Write a word WORD into remote address ADDR.
1996 This goes through the data cache. */
1999 remote_store_word (addr
, word
)
2003 dcache_poke (remote_dcache
, addr
, word
);
2005 #endif /* 0 (unused?) */
2009 /* Return the number of hex digits in num. */
2017 for (i
= 0; num
!= 0; i
++)
2023 /* Set BUF to the hex digits representing NUM. */
2026 hexnumstr (buf
, num
)
2031 int len
= hexnumlen (num
);
2035 for (i
= len
- 1; i
>= 0; i
--)
2037 buf
[i
] = "0123456789abcdef" [(num
& 0xf)];
2044 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
2047 remote_address_masked (addr
)
2050 if (remote_address_size
> 0
2051 && remote_address_size
< (sizeof (ULONGEST
) * 8))
2053 /* Only create a mask when that mask can safely be constructed
2054 in a ULONGEST variable. */
2056 mask
= (mask
<< remote_address_size
) - 1;
2062 /* Write memory data directly to the remote machine.
2063 This does not inform the data cache; the data cache uses this.
2064 MEMADDR is the address in the remote memory space.
2065 MYADDR is the address of the buffer in our space.
2066 LEN is the number of bytes.
2068 Returns number of bytes transferred, or 0 for error. */
2071 remote_write_bytes (memaddr
, myaddr
, len
)
2076 int max_buf_size
; /* Max size of packet output buffer */
2079 /* Chop the transfer down if necessary */
2081 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
2082 if (remote_register_buf_size
!= 0)
2083 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
2085 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
2086 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
2096 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
2098 /* construct "M"<memaddr>","<len>":" */
2099 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
2100 memaddr
= remote_address_masked (memaddr
);
2103 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
2105 p
+= hexnumstr (p
, (ULONGEST
) todo
);
2109 /* We send target system values byte by byte, in increasing byte
2110 addresses, each byte encoded as two hex characters. */
2112 for (i
= 0; i
< todo
; i
++)
2114 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
2115 *p
++ = tohex (myaddr
[i
] & 0xf);
2124 /* There is no correspondance between what the remote protocol uses
2125 for errors and errno codes. We would like a cleaner way of
2126 representing errors (big enough to include errno codes, bfd_error
2127 codes, and others). But for now just return EIO. */
2138 /* Read memory data directly from the remote machine.
2139 This does not use the data cache; the data cache uses this.
2140 MEMADDR is the address in the remote memory space.
2141 MYADDR is the address of the buffer in our space.
2142 LEN is the number of bytes.
2144 Returns number of bytes transferred, or 0 for error. */
2147 remote_read_bytes (memaddr
, myaddr
, len
)
2152 int max_buf_size
; /* Max size of packet output buffer */
2155 /* Chop the transfer down if necessary */
2157 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
2158 if (remote_register_buf_size
!= 0)
2159 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
2169 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
2171 /* construct "m"<memaddr>","<len>" */
2172 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
2173 memaddr
= remote_address_masked (memaddr
);
2176 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
2178 p
+= hexnumstr (p
, (ULONGEST
) todo
);
2186 /* There is no correspondance between what the remote protocol uses
2187 for errors and errno codes. We would like a cleaner way of
2188 representing errors (big enough to include errno codes, bfd_error
2189 codes, and others). But for now just return EIO. */
2194 /* Reply describes memory byte by byte,
2195 each byte encoded as two hex characters. */
2198 for (i
= 0; i
< todo
; i
++)
2200 if (p
[0] == 0 || p
[1] == 0)
2201 /* Reply is short. This means that we were able to read
2202 only part of what we wanted to. */
2203 return i
+ (origlen
- len
);
2204 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2214 /* Read or write LEN bytes from inferior memory at MEMADDR,
2215 transferring to or from debugger address MYADDR. Write to inferior
2216 if SHOULD_WRITE is nonzero. Returns length of data written or
2217 read; 0 for error. */
2221 remote_xfer_memory (memaddr
, myaddr
, len
, should_write
, target
)
2226 struct target_ops
*target
; /* ignored */
2228 #ifdef REMOTE_TRANSLATE_XFER_ADDRESS
2231 REMOTE_TRANSLATE_XFER_ADDRESS (memaddr
, len
, targaddr
, targlen
);
2238 return dcache_xfer_memory (remote_dcache
, memaddr
, myaddr
,
2244 /* Enable after 4.12. */
2247 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
2248 addr_found
, data_found
)
2252 CORE_ADDR startaddr
;
2256 CORE_ADDR
*addr_found
;
2259 if (increment
== -4 && len
== 4)
2261 long mask_long
, data_long
;
2262 long data_found_long
;
2263 CORE_ADDR addr_we_found
;
2265 long returned_long
[2];
2268 mask_long
= extract_unsigned_integer (mask
, len
);
2269 data_long
= extract_unsigned_integer (data
, len
);
2270 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
2275 /* The stub doesn't support the 't' request. We might want to
2276 remember this fact, but on the other hand the stub could be
2277 switched on us. Maybe we should remember it only until
2278 the next "target remote". */
2279 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
2280 hirange
, addr_found
, data_found
);
2285 /* There is no correspondance between what the remote protocol uses
2286 for errors and errno codes. We would like a cleaner way of
2287 representing errors (big enough to include errno codes, bfd_error
2288 codes, and others). But for now just use EIO. */
2289 memory_error (EIO
, startaddr
);
2292 while (*p
!= '\0' && *p
!= ',')
2293 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
2295 error ("Protocol error: short return for search");
2297 data_found_long
= 0;
2298 while (*p
!= '\0' && *p
!= ',')
2299 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
2300 /* Ignore anything after this comma, for future extensions. */
2302 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
2308 *addr_found
= addr_we_found
;
2309 *data_found
= store_unsigned_integer (data_we_found
, len
);
2312 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
2313 hirange
, addr_found
, data_found
);
2318 remote_files_info (ignore
)
2319 struct target_ops
*ignore
;
2321 puts_filtered ("Debugging a target over a serial line.\n");
2324 /* Stuff for dealing with the packets which are part of this protocol.
2325 See comment at top of file for details. */
2327 /* Read a single character from the remote end, masking it down to 7 bits. */
2335 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
2340 error ("Remote connection closed");
2342 perror_with_name ("Remote communication error");
2343 case SERIAL_TIMEOUT
:
2350 /* Send the command in BUF to the remote machine, and read the reply
2351 into BUF. Report an error if we get an error reply. */
2361 error ("Remote failure reply: %s", buf
);
2364 /* Display a null-terminated packet on stdout, for debugging, using C
2371 puts_filtered ("\"");
2373 gdb_printchar (*buf
++, gdb_stdout
, '"');
2374 puts_filtered ("\"");
2378 /* Send a packet to the remote machine, with error checking. The data
2379 of the packet is in BUF. */
2386 unsigned char csum
= 0;
2388 int cnt
= strlen (buf
);
2393 /* Copy the packet into buffer BUF2, encapsulating it
2394 and giving it a checksum. */
2396 if (cnt
> (int) sizeof (buf2
) - 5) /* Prosanity check */
2402 for (i
= 0; i
< cnt
; i
++)
2408 *p
++ = tohex ((csum
>> 4) & 0xf);
2409 *p
++ = tohex (csum
& 0xf);
2411 /* Send it over and over until we get a positive ack. */
2415 int started_error_output
= 0;
2420 printf_unfiltered ("Sending packet: %s...", buf2
);
2421 gdb_flush (gdb_stdout
);
2423 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
2424 perror_with_name ("putpkt: write failed");
2426 /* read until either a timeout occurs (-2) or '+' is read */
2429 ch
= readchar (remote_timeout
);
2436 case SERIAL_TIMEOUT
:
2438 if (started_error_output
)
2440 putchar_unfiltered ('\n');
2441 started_error_output
= 0;
2450 printf_unfiltered ("Ack\n");
2452 case SERIAL_TIMEOUT
:
2456 break; /* Retransmit buffer */
2459 char junkbuf
[PBUFSIZ
];
2461 /* It's probably an old response, and we're out of sync.
2462 Just gobble up the packet and ignore it. */
2463 getpkt (junkbuf
, 0);
2464 continue; /* Now, go look for + */
2469 if (!started_error_output
)
2471 started_error_output
= 1;
2472 printf_unfiltered ("putpkt: Junk: ");
2474 putchar_unfiltered (ch
& 0177);
2478 break; /* Here to retransmit */
2482 /* This is wrong. If doing a long backtrace, the user should be
2483 able to get out next time we call QUIT, without anything as
2484 violent as interrupt_query. If we want to provide a way out of
2485 here without getting to the next QUIT, it should be based on
2486 hitting ^C twice as in remote_wait. */
2496 /* Come here after finding the start of the frame. Collect the rest
2497 into BUF, verifying the checksum, length, and handling run-length
2498 compression. Returns 0 on any error, 1 on success. */
2513 c
= readchar (remote_timeout
);
2517 case SERIAL_TIMEOUT
:
2519 puts_filtered ("Timeout in mid-packet, retrying\n");
2523 puts_filtered ("Saw new packet start in middle of old one\n");
2524 return 0; /* Start a new packet, count retries */
2527 unsigned char pktcsum
;
2531 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
2532 pktcsum
|= fromhex (readchar (remote_timeout
));
2534 if (csum
== pktcsum
)
2539 printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
2541 puts_filtered (buf
);
2542 puts_filtered ("\n");
2546 case '*': /* Run length encoding */
2548 c
= readchar (remote_timeout
);
2550 c
= c
- ' ' + 3; /* Compute repeat count */
2553 if (c
> 0 && c
< 255 && bp
+ c
- 1 < buf
+ PBUFSIZ
- 1)
2555 memset (bp
, *(bp
- 1), c
);
2561 printf_filtered ("Repeat count %d too large for buffer: ", c
);
2562 puts_filtered (buf
);
2563 puts_filtered ("\n");
2567 if (bp
< buf
+ PBUFSIZ
- 1)
2575 puts_filtered ("Remote packet too long: ");
2576 puts_filtered (buf
);
2577 puts_filtered ("\n");
2584 /* Read a packet from the remote machine, with error checking, and
2585 store it in BUF. BUF is expected to be of size PBUFSIZ. If
2586 FOREVER, wait forever rather than timing out; this is used while
2587 the target is executing user code. */
2590 getpkt (buf
, forever
)
2599 strcpy (buf
,"timeout");
2603 #ifdef MAINTENANCE_CMDS
2604 timeout
= watchdog
> 0 ? watchdog
: -1;
2611 timeout
= remote_timeout
;
2615 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
2617 /* This can loop forever if the remote side sends us characters
2618 continuously, but if it pauses, we'll get a zero from readchar
2619 because of timeout. Then we'll count that as a retry. */
2621 /* Note that we will only wait forever prior to the start of a packet.
2622 After that, we expect characters to arrive at a brisk pace. They
2623 should show up within remote_timeout intervals. */
2627 c
= readchar (timeout
);
2629 if (c
== SERIAL_TIMEOUT
)
2631 #ifdef MAINTENANCE_CMDS
2632 if (forever
) /* Watchdog went off. Kill the target. */
2634 target_mourn_inferior ();
2635 error ("Watchdog has expired. Target detached.\n");
2639 puts_filtered ("Timed out.\n");
2645 /* We've found the start of a packet, now collect the data. */
2647 val
= read_frame (buf
);
2652 fprintf_unfiltered (gdb_stdout
, "Packet received: %s\n", buf
);
2653 SERIAL_WRITE (remote_desc
, "+", 1);
2657 /* Try the whole thing again. */
2659 SERIAL_WRITE (remote_desc
, "-", 1);
2662 /* We have tried hard enough, and just can't receive the packet. Give up. */
2664 printf_unfiltered ("Ignoring packet error, continuing...\n");
2665 SERIAL_WRITE (remote_desc
, "+", 1);
2671 /* For some mysterious reason, wait_for_inferior calls kill instead of
2672 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
2676 target_mourn_inferior ();
2680 /* Use catch_errors so the user can quit from gdb even when we aren't on
2681 speaking terms with the remote system. */
2682 catch_errors (putpkt
, "k", "", RETURN_MASK_ERROR
);
2684 /* Don't wait for it to die. I'm not really sure it matters whether
2685 we do or not. For the existing stubs, kill is a noop. */
2686 target_mourn_inferior ();
2692 remote_mourn_1 (&remote_ops
);
2696 extended_remote_mourn ()
2698 /* We do _not_ want to mourn the target like this; this will
2699 remove the extended remote target from the target stack,
2700 and the next time the user says "run" it'll fail.
2702 FIXME: What is the right thing to do here? */
2704 remote_mourn_1 (&extended_remote_ops
);
2708 /* Worker function for remote_mourn. */
2710 remote_mourn_1 (target
)
2711 struct target_ops
*target
;
2713 unpush_target (target
);
2714 generic_mourn_inferior ();
2717 /* In the extended protocol we want to be able to do things like
2718 "run" and have them basically work as expected. So we need
2719 a special create_inferior function.
2721 FIXME: One day add support for changing the exec file
2722 we're debugging, arguments and an environment. */
2725 extended_remote_create_inferior (exec_file
, args
, env
)
2730 /* Rip out the breakpoints; we'll reinsert them after restarting
2731 the remote server. */
2732 remove_breakpoints ();
2734 /* Now restart the remote server. */
2735 extended_remote_restart ();
2737 /* Now put the breakpoints back in. This way we're safe if the
2738 restart function works via a unix fork on the remote side. */
2739 insert_breakpoints ();
2741 /* Clean up from the last time we were running. */
2742 clear_proceed_status ();
2744 /* Let the remote process run. */
2745 proceed (-1, TARGET_SIGNAL_0
, 0);
2749 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
2750 than other targets; in those use REMOTE_BREAKPOINT instead of just
2751 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
2752 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
2753 the standard routines that are in mem-break.c. */
2755 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
2756 the choice of breakpoint instruction affects target program design and
2757 vice versa, and by making it user-tweakable, the special code here
2758 goes away and we need fewer special GDB configurations. */
2760 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
2761 #define REMOTE_BREAKPOINT
2764 #ifdef REMOTE_BREAKPOINT
2766 /* If the target isn't bi-endian, just pretend it is. */
2767 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
2768 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
2769 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
2772 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
2773 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
2775 #endif /* REMOTE_BREAKPOINT */
2777 /* Insert a breakpoint on targets that don't have any better breakpoint
2778 support. We read the contents of the target location and stash it,
2779 then overwrite it with a breakpoint instruction. ADDR is the target
2780 location in the target machine. CONTENTS_CACHE is a pointer to
2781 memory allocated for saving the target contents. It is guaranteed
2782 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
2783 is accomplished via BREAKPOINT_MAX). */
2786 remote_insert_breakpoint (addr
, contents_cache
)
2788 char *contents_cache
;
2790 #ifdef REMOTE_BREAKPOINT
2793 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
2797 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
2798 val
= target_write_memory (addr
, (char *) big_break_insn
,
2799 sizeof big_break_insn
);
2801 val
= target_write_memory (addr
, (char *) little_break_insn
,
2802 sizeof little_break_insn
);
2807 return memory_insert_breakpoint (addr
, contents_cache
);
2808 #endif /* REMOTE_BREAKPOINT */
2812 remote_remove_breakpoint (addr
, contents_cache
)
2814 char *contents_cache
;
2816 #ifdef REMOTE_BREAKPOINT
2817 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
2819 return memory_remove_breakpoint (addr
, contents_cache
);
2820 #endif /* REMOTE_BREAKPOINT */
2823 /* Some targets are only capable of doing downloads, and afterwards
2824 they switch to the remote serial protocol. This function provides
2825 a clean way to get from the download target to the remote target.
2826 It's basically just a wrapper so that we don't have to expose any
2827 of the internal workings of remote.c.
2829 Prior to calling this routine, you should shutdown the current
2830 target code, else you will get the "A program is being debugged
2831 already..." message. Usually a call to pop_target() suffices. */
2834 push_remote_target (name
, from_tty
)
2838 printf_filtered ("Switching to remote protocol\n");
2839 remote_open (name
, from_tty
);
2842 /* Other targets want to use the entire remote serial module but with
2843 certain remote_ops overridden. */
2846 open_remote_target (name
, from_tty
, target
, extended_p
)
2849 struct target_ops
*target
;
2852 printf_filtered ("Selecting the %sremote protocol\n",
2853 (extended_p
? "extended-" : ""));
2854 remote_open_1 (name
, from_tty
, target
, extended_p
);
2857 /* Table used by the crc32 function to calcuate the checksum. */
2859 static unsigned long crc32_table
[256] = {0, 0};
2861 static unsigned long
2862 crc32 (buf
, len
, crc
)
2867 if (! crc32_table
[1])
2869 /* Initialize the CRC table and the decoding table. */
2873 for (i
= 0; i
< 256; i
++)
2875 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
2876 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
2883 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
2889 /* compare-sections command
2891 With no arguments, compares each loadable section in the exec bfd
2892 with the same memory range on the target, and reports mismatches.
2893 Useful for verifying the image on the target against the exec file.
2894 Depends on the target understanding the new "qCRC:" request. */
2897 compare_sections_command (args
, from_tty
)
2902 unsigned long host_crc
, target_crc
;
2903 extern bfd
*exec_bfd
;
2904 struct cleanup
*old_chain
;
2905 char *tmp
, *sectdata
, *sectname
, buf
[PBUFSIZ
];
2912 error ("command cannot be used without an exec file");
2913 if (!current_target
.to_shortname
||
2914 strcmp (current_target
.to_shortname
, "remote") != 0)
2915 error ("command can only be used with remote target");
2917 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
2919 if (!(s
->flags
& SEC_LOAD
))
2920 continue; /* skip non-loadable section */
2922 size
= bfd_get_section_size_before_reloc (s
);
2924 continue; /* skip zero-length section */
2926 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
2927 if (args
&& strcmp (args
, sectname
) != 0)
2928 continue; /* not the section selected by user */
2930 matched
= 1; /* do this section */
2932 /* FIXME: assumes lma can fit into long */
2933 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
2936 /* be clever; compute the host_crc before waiting for target reply */
2937 sectdata
= xmalloc (size
);
2938 old_chain
= make_cleanup (free
, sectdata
);
2939 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
2940 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
2944 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
2945 sectname
, lma
, lma
+ size
);
2947 error ("remote target does not support this operation");
2949 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
2950 target_crc
= target_crc
* 16 + fromhex (*tmp
);
2952 printf_filtered ("Section %s, range 0x%08x -- 0x%08x: ",
2953 sectname
, lma
, lma
+ size
);
2954 if (host_crc
== target_crc
)
2955 printf_filtered ("matched.\n");
2958 printf_filtered ("MIS-MATCHED!\n");
2962 do_cleanups (old_chain
);
2965 warning ("One or more sections of the remote executable does not match\n\
2966 the loaded file\n");
2967 if (args
&& !matched
)
2968 printf_filtered ("No loaded section named '%s'.\n", args
);
2972 packet_command (args
, from_tty
)
2979 error ("command can only be used with remote target");
2982 error ("remote-packet command requires packet text as argument");
2984 puts_filtered ("sending: ");
2985 print_packet (args
);
2986 puts_filtered ("\n");
2990 puts_filtered ("received: ");
2992 puts_filtered ("\n");
2996 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
2998 static void display_thread_info
PARAMS ((struct gdb_ext_thread_info
*info
));
3000 static void threadset_test_cmd
PARAMS ((char *cmd
, int tty
));
3002 static void threadalive_test
PARAMS ((char *cmd
, int tty
));
3004 static void threadlist_test_cmd
PARAMS ((char *cmd
, int tty
));
3006 int get_and_display_threadinfo
PARAMS ((threadref
*ref
));
3008 static void threadinfo_test_cmd
PARAMS ((char *cmd
, int tty
));
3010 static int thread_display_step
PARAMS ((threadref
*ref
, void *context
));
3012 static void threadlist_update_test_cmd
PARAMS ((char *cmd
, int tty
));
3014 static void init_remote_threadtests
PARAMS ((void));
3016 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
3019 threadset_test_cmd (cmd
, tty
)
3023 int sample_thread
= SAMPLE_THREAD
;
3025 printf_filtered ("Remote threadset test\n");
3026 set_thread (sample_thread
, 1);
3031 threadalive_test (cmd
, tty
)
3035 int sample_thread
= SAMPLE_THREAD
;
3037 if (remote_thread_alive (sample_thread
))
3038 printf_filtered ("PASS: Thread alive test\n");
3040 printf_filtered ("FAIL: Thread alive test\n");
3043 void output_threadid
PARAMS ((char *title
, threadref
* ref
));
3046 output_threadid (title
, ref
)
3052 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
3054 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
3058 threadlist_test_cmd (cmd
, tty
)
3063 threadref nextthread
;
3064 int done
, result_count
;
3065 threadref threadlist
[3];
3067 printf_filtered ("Remote Threadlist test\n");
3068 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
3069 &result_count
, &threadlist
[0]))
3070 printf_filtered ("FAIL: threadlist test\n");
3073 threadref
*scan
= threadlist
;
3074 threadref
*limit
= scan
+ result_count
;
3076 while (scan
< limit
)
3077 output_threadid (" thread ", scan
++);
3082 display_thread_info (info
)
3083 struct gdb_ext_thread_info
*info
;
3085 output_threadid ("Threadid: ", &info
->threadid
);
3086 printf_filtered ("Name: %s\n ", info
->shortname
);
3087 printf_filtered ("State: %s\n", info
->display
);
3088 printf_filtered ("other: %s\n\n", info
->more_display
);
3092 get_and_display_threadinfo (ref
)
3097 struct gdb_ext_thread_info threadinfo
;
3099 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3100 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3101 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
3102 display_thread_info (&threadinfo
);
3107 threadinfo_test_cmd (cmd
, tty
)
3111 int athread
= SAMPLE_THREAD
;
3115 int_to_threadref (&thread
, athread
);
3116 printf_filtered ("Remote Threadinfo test\n");
3117 if (!get_and_display_threadinfo (&thread
))
3118 printf_filtered ("FAIL cannot get thread info\n");
3122 thread_display_step (ref
, context
)
3126 /* output_threadid(" threadstep ",ref); *//* simple test */
3127 return get_and_display_threadinfo (ref
);
3131 threadlist_update_test_cmd (cmd
, tty
)
3135 printf_filtered ("Remote Threadlist update test\n");
3136 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
3140 init_remote_threadtests (void)
3142 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
3143 "Fetch and print the remote list of thread identifiers, one pkt only");
3144 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
3145 "Fetch and display info about one thread");
3146 add_com ("tset", class_obscure
, threadset_test_cmd
,
3147 "Test setting to a different thread");
3148 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
3149 "Iterate through updating all remote thread info");
3150 add_com ("talive", class_obscure
, threadalive_test
,
3151 " Remote thread alive test ");
3159 remote_ops
.to_shortname
= "remote";
3160 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
3162 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
3163 Specify the serial device it is connected to (e.g. /dev/ttya).";
3164 remote_ops
.to_open
= remote_open
;
3165 remote_ops
.to_close
= remote_close
;
3166 remote_ops
.to_detach
= remote_detach
;
3167 remote_ops
.to_resume
= remote_resume
;
3168 remote_ops
.to_wait
= remote_wait
;
3169 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
3170 remote_ops
.to_store_registers
= remote_store_registers
;
3171 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
3172 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
3173 remote_ops
.to_files_info
= remote_files_info
;
3174 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
3175 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
3176 remote_ops
.to_kill
= remote_kill
;
3177 remote_ops
.to_load
= generic_load
;
3178 remote_ops
.to_mourn_inferior
= remote_mourn
;
3179 remote_ops
.to_thread_alive
= remote_thread_alive
;
3180 remote_ops
.to_stop
= remote_stop
;
3181 remote_ops
.to_stratum
= process_stratum
;
3182 remote_ops
.to_has_all_memory
= 1;
3183 remote_ops
.to_has_memory
= 1;
3184 remote_ops
.to_has_stack
= 1;
3185 remote_ops
.to_has_registers
= 1;
3186 remote_ops
.to_has_execution
= 1;
3187 remote_ops
.to_magic
= OPS_MAGIC
;
3190 /* Set up the extended remote vector by making a copy of the standard
3191 remote vector and adding to it. */
3194 init_extended_remote_ops ()
3196 extended_remote_ops
= remote_ops
;
3198 extended_remote_ops
.to_shortname
= "extended-remote";
3199 extended_remote_ops
.to_longname
=
3200 "Extended remote serial target in gdb-specific protocol";
3201 extended_remote_ops
.to_doc
=
3202 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
3203 Specify the serial device it is connected to (e.g. /dev/ttya).",
3204 extended_remote_ops
.to_open
= extended_remote_open
;
3205 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
3206 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
3210 _initialize_remote ()
3213 add_target (&remote_ops
);
3215 init_extended_remote_ops ();
3216 add_target (&extended_remote_ops
);
3217 init_remote_threads ();
3219 init_remote_threadtests ();
3222 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
3223 "Compare section data on target to the exec file.\n\
3224 Argument is a single section name (default: all loaded sections).",
3227 add_cmd ("packet", class_maintenance
, packet_command
,
3228 "Send an arbitrary packet to a remote target.\n\
3229 maintenance packet TEXT\n\
3230 If GDB is talking to an inferior via the GDB serial protocol, then\n\
3231 this command sends the string TEXT to the inferior, and displays the\n\
3232 response packet. GDB supplies the initial `$' character, and the\n\
3233 terminating `#' character and checksum.",
3237 (add_set_cmd ("remotetimeout", no_class
,
3238 var_integer
, (char *)&remote_timeout
,
3239 "Set timeout value for remote read.\n",
3244 (add_set_cmd ("remotebreak", no_class
,
3245 var_integer
, (char *)&remote_break
,
3246 "Set whether to send break if interrupted.\n",
3251 (add_set_cmd ("remotewritesize", no_class
,
3252 var_integer
, (char *)&remote_write_size
,
3253 "Set the maximum number of bytes per memory write packet.\n",
3257 remote_address_size
= TARGET_PTR_BIT
;
3259 (add_set_cmd ("remoteaddresssize", class_obscure
,
3260 var_integer
, (char *)&remote_address_size
,
3261 "Set the maximum size of the address (in bits) \
3262 in a memory packet.\n",