1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 1991-2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* See the GDB User Guide for details of the GDB remote protocol. */
24 #include "gdb_string.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
45 #include <sys/types.h>
48 #include "event-loop.h"
49 #include "event-top.h"
55 /* Prototypes for local functions */
56 static void cleanup_sigint_signal_handler (void *dummy
);
57 static void initialize_sigint_signal_handler (void);
58 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
60 static void handle_remote_sigint (int);
61 static void handle_remote_sigint_twice (int);
62 static void async_remote_interrupt (gdb_client_data
);
63 void async_remote_interrupt_twice (gdb_client_data
);
65 static void build_remote_gdbarch_data (void);
67 static int remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
69 static int remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
71 static void remote_files_info (struct target_ops
*ignore
);
73 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
74 int len
, int should_write
,
75 struct target_ops
*target
);
77 static void remote_prepare_to_store (void);
79 static void remote_fetch_registers (int regno
);
81 static void remote_resume (int pid
, int step
, enum target_signal siggnal
);
82 static void remote_async_resume (int pid
, int step
,
83 enum target_signal siggnal
);
84 static int remote_start_remote (PTR
);
86 static void remote_open (char *name
, int from_tty
);
87 static void remote_async_open (char *name
, int from_tty
);
89 static void extended_remote_open (char *name
, int from_tty
);
90 static void extended_remote_async_open (char *name
, int from_tty
);
92 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
93 static void remote_async_open_1 (char *, int, struct target_ops
*,
96 static void remote_close (int quitting
);
98 static void remote_store_registers (int regno
);
100 static void remote_mourn (void);
101 static void remote_async_mourn (void);
103 static void extended_remote_restart (void);
105 static void extended_remote_mourn (void);
107 static void extended_remote_create_inferior (char *, char *, char **);
108 static void extended_remote_async_create_inferior (char *, char *, char **);
110 static void remote_mourn_1 (struct target_ops
*);
112 static void remote_send (char *buf
, long sizeof_buf
);
114 static int readchar (int timeout
);
116 static int remote_wait (int pid
, struct target_waitstatus
*status
);
117 static int remote_async_wait (int pid
, struct target_waitstatus
*status
);
119 static void remote_kill (void);
120 static void remote_async_kill (void);
122 static int tohex (int nib
);
124 static void remote_detach (char *args
, int from_tty
);
125 static void remote_async_detach (char *args
, int from_tty
);
127 static void remote_interrupt (int signo
);
129 static void remote_interrupt_twice (int signo
);
131 static void interrupt_query (void);
133 static void set_thread (int, int);
135 static int remote_thread_alive (int);
137 static void get_offsets (void);
139 static long read_frame (char *buf
, long sizeof_buf
);
141 static int remote_insert_breakpoint (CORE_ADDR
, char *);
143 static int remote_remove_breakpoint (CORE_ADDR
, char *);
145 static int hexnumlen (ULONGEST num
);
147 static void init_remote_ops (void);
149 static void init_extended_remote_ops (void);
151 static void init_remote_cisco_ops (void);
153 static struct target_ops remote_cisco_ops
;
155 static void remote_stop (void);
157 static int ishex (int ch
, int *val
);
159 static int stubhex (int ch
);
161 static int remote_query (int /*char */ , char *, char *, int *);
163 static int hexnumstr (char *, ULONGEST
);
165 static int hexnumnstr (char *, ULONGEST
, int);
167 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
169 static void print_packet (char *);
171 static unsigned long crc32 (unsigned char *, int, unsigned int);
173 static void compare_sections_command (char *, int);
175 static void packet_command (char *, int);
177 static int stub_unpack_int (char *buff
, int fieldlength
);
179 static int remote_current_thread (int oldpid
);
181 static void remote_find_new_threads (void);
183 static void record_currthread (int currthread
);
185 /* exported functions */
187 extern int fromhex (int a
);
189 static int putpkt_binary (char *buf
, int cnt
);
191 static void check_binary_download (CORE_ADDR addr
);
193 struct packet_config
;
195 static void show_packet_config_cmd (struct packet_config
*config
);
197 static void set_packet_config_cmd (struct packet_config
*config
,
198 struct cmd_list_element
*c
);
200 static void add_packet_config_cmd (struct packet_config
*config
,
203 void (*set_func
) (char *args
, int from_tty
,
204 struct cmd_list_element
*
206 void (*show_func
) (char *name
,
208 struct cmd_list_element
**setlist
,
209 struct cmd_list_element
**showlist
);
211 static void init_packet_config (struct packet_config
*config
);
213 static void set_remote_protocol_P_packet_cmd (char *args
,
215 struct cmd_list_element
*c
);
217 static void show_remote_protocol_P_packet_cmd (char *args
, int from_tty
);
219 static void set_remote_protocol_Z_packet_cmd (char *args
,
221 struct cmd_list_element
*c
);
223 static void show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
);
228 /* Define the target subroutine names */
230 void open_remote_target (char *, int, struct target_ops
*, int);
232 void _initialize_remote (void);
236 static struct target_ops remote_ops
;
238 static struct target_ops extended_remote_ops
;
240 /* Temporary target ops. Just like the remote_ops and
241 extended_remote_ops, but with asynchronous support. */
242 static struct target_ops remote_async_ops
;
244 static struct target_ops extended_async_remote_ops
;
246 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
247 ``forever'' still use the normal timeout mechanism. This is
248 currently used by the ASYNC code to guarentee that target reads
249 during the initial connect always time-out. Once getpkt has been
250 modified to return a timeout indication and, in turn
251 remote_wait()/wait_for_inferior() have gained a timeout parameter
253 static int wait_forever_enabled_p
= 1;
256 /* This variable chooses whether to send a ^C or a break when the user
257 requests program interruption. Although ^C is usually what remote
258 systems expect, and that is the default here, sometimes a break is
259 preferable instead. */
261 static int remote_break
;
263 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
264 remote_open knows that we don't have a file open when the program
266 static serial_t remote_desc
= NULL
;
268 /* This is set by the target (thru the 'S' message)
269 to denote that the target is in kernel mode. */
270 static int cisco_kernel_mode
= 0;
272 /* This variable sets the number of bits in an address that are to be
273 sent in a memory ("M" or "m") packet. Normally, after stripping
274 leading zeros, the entire address would be sent. This variable
275 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
276 initial implementation of remote.c restricted the address sent in
277 memory packets to ``host::sizeof long'' bytes - (typically 32
278 bits). Consequently, for 64 bit targets, the upper 32 bits of an
279 address was never sent. Since fixing this bug may cause a break in
280 some remote targets this variable is principly provided to
281 facilitate backward compatibility. */
283 static int remote_address_size
;
285 /* Tempoary to track who currently owns the terminal. See
286 target_async_terminal_* for more details. */
288 static int remote_async_terminal_ours_p
;
291 /* This is the size (in chars) of the first response to the ``g''
292 packet. It is used as a heuristic when determining the maximum
293 size of memory-read and memory-write packets. A target will
294 typically only reserve a buffer large enough to hold the ``g''
295 packet. The size does not include packet overhead (headers and
298 static long actual_register_packet_size
;
300 /* This is the maximum size (in chars) of a non read/write packet. It
301 is also used as a cap on the size of read/write packets. */
303 static long remote_packet_size
;
305 #define PBUFSIZ (remote_packet_size)
307 /* User configurable variables for the number of characters in a
308 memory read/write packet. MIN (PBUFSIZ, g-packet-size) is the
309 default. Some targets need smaller values (fifo overruns, et.al.)
310 and some users need larger values (speed up transfers). The
311 variables ``preferred_*'' (the user request), ``current_*'' (what
312 was actually set) and ``forced_*'' (Positive - a soft limit,
313 negative - a hard limit). */
315 struct memory_packet_config
322 /* Compute the current size of a read/write packet. Since this makes
323 use of ``actual_register_packet_size'' the computation is dynamic. */
326 get_memory_packet_size (struct memory_packet_config
*config
)
328 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
329 law?) that some hosts don't cope very well with large alloca()
330 calls. Eventually the alloca() code will be replaced by calls to
331 xmalloc() and make_cleanups() allowing this restriction to either
332 be lifted or removed. */
333 #ifndef MAX_REMOTE_PACKET_SIZE
334 #define MAX_REMOTE_PACKET_SIZE 16384
336 /* NOTE: 16 is just chosen at random. */
337 #ifndef MIN_REMOTE_PACKET_SIZE
338 #define MIN_REMOTE_PACKET_SIZE 16
343 if (config
->size
<= 0)
344 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
346 what_they_get
= config
->size
;
350 what_they_get
= remote_packet_size
;
351 /* Limit the packet to the size specified by the user. */
353 && what_they_get
> config
->size
)
354 what_they_get
= config
->size
;
355 /* Limit it to the size of the targets ``g'' response. */
356 if (actual_register_packet_size
> 0
357 && what_they_get
> actual_register_packet_size
)
358 what_they_get
= actual_register_packet_size
;
360 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
361 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
362 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
363 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
364 return what_they_get
;
367 /* Update the size of a read/write packet. If they user wants
368 something really big then do a sanity check. */
371 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
373 int fixed_p
= config
->fixed_p
;
374 long size
= config
->size
;
376 error ("Argument required (integer, `fixed' or `limited').");
377 else if (strcmp (args
, "hard") == 0
378 || strcmp (args
, "fixed") == 0)
380 else if (strcmp (args
, "soft") == 0
381 || strcmp (args
, "limit") == 0)
386 size
= strtoul (args
, &end
, 0);
388 error ("Invalid %s (bad syntax).", config
->name
);
390 /* Instead of explicitly capping the size of a packet to
391 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
392 instead allowed to set the size to something arbitrarily
394 if (size
> MAX_REMOTE_PACKET_SIZE
)
395 error ("Invalid %s (too large).", config
->name
);
399 if (fixed_p
&& !config
->fixed_p
)
401 if (! query ("The target may not be able to correctly handle a %s\n"
402 "of %ld bytes. Change the packet size? ",
404 error ("Packet size not changed.");
406 /* Update the config. */
407 config
->fixed_p
= fixed_p
;
412 show_memory_packet_size (struct memory_packet_config
*config
)
414 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
416 printf_filtered ("Packets are fixed at %ld bytes.\n",
417 get_memory_packet_size (config
));
419 printf_filtered ("Packets are limited to %ld bytes.\n",
420 get_memory_packet_size (config
));
423 static struct memory_packet_config memory_write_packet_config
=
425 "memory-write-packet-size",
429 set_memory_write_packet_size (char *args
, int from_tty
)
431 set_memory_packet_size (args
, &memory_write_packet_config
);
435 show_memory_write_packet_size (char *args
, int from_tty
)
437 show_memory_packet_size (&memory_write_packet_config
);
441 get_memory_write_packet_size (void)
443 return get_memory_packet_size (&memory_write_packet_config
);
446 static struct memory_packet_config memory_read_packet_config
=
448 "memory-read-packet-size",
452 set_memory_read_packet_size (char *args
, int from_tty
)
454 set_memory_packet_size (args
, &memory_read_packet_config
);
458 show_memory_read_packet_size (char *args
, int from_tty
)
460 show_memory_packet_size (&memory_read_packet_config
);
464 get_memory_read_packet_size (void)
466 long size
= get_memory_packet_size (&memory_read_packet_config
);
467 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
468 extra buffer size argument before the memory read size can be
469 increased beyond PBUFSIZ. */
475 /* Register packet size initialization. Since the bounds change when
476 the architecture changes (namely REGISTER_BYTES) this all needs to
480 register_remote_packet_sizes (void)
482 REGISTER_GDBARCH_SWAP (remote_packet_size
);
483 REGISTER_GDBARCH_SWAP (actual_register_packet_size
);
487 build_remote_packet_sizes (void)
489 /* Default maximum number of characters in a packet body. Many
490 remote stubs have a hardwired buffer size of 400 bytes
491 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
492 as the maximum packet-size to ensure that the packet and an extra
493 NUL character can always fit in the buffer. This stops GDB
494 trashing stubs that try to squeeze an extra NUL into what is
495 already a full buffer (As of 1999-12-04 that was most stubs. */
496 remote_packet_size
= 400 - 1;
497 /* Should REGISTER_BYTES needs more space than the default, adjust
498 the size accordingly. Remember that each byte is encoded as two
499 characters. 32 is the overhead for the packet header /
500 footer. NOTE: cagney/1999-10-26: I suspect that 8
501 (``$NN:G...#NN'') is a better guess, the below has been padded a
503 if (REGISTER_BYTES
> ((remote_packet_size
- 32) / 2))
504 remote_packet_size
= (REGISTER_BYTES
* 2 + 32);
506 /* This one is filled in when a ``g'' packet is received. */
507 actual_register_packet_size
= 0;
510 /* Generic configuration support for packets the stub optionally
511 supports. Allows the user to specify the use of the packet as well
512 as allowing GDB to auto-detect support in the remote stub. */
516 PACKET_SUPPORT_UNKNOWN
= 0,
523 PACKET_AUTO_DETECT
= 0,
532 enum packet_detect detect
;
533 enum packet_support support
;
536 static const char packet_support_auto
[] = "auto";
537 static const char packet_enable
[] = "enable";
538 static const char packet_disable
[] = "disable";
539 static const char *packet_support_enums
[] =
548 set_packet_config_cmd (struct packet_config
*config
, struct cmd_list_element
*c
)
550 if (config
->state
== packet_enable
)
552 config
->detect
= PACKET_MANUAL_DETECT
;
553 config
->support
= PACKET_ENABLE
;
555 else if (config
->state
== packet_disable
)
557 config
->detect
= PACKET_MANUAL_DETECT
;
558 config
->support
= PACKET_DISABLE
;
560 else if (config
->state
== packet_support_auto
)
562 config
->detect
= PACKET_AUTO_DETECT
;
563 config
->support
= PACKET_SUPPORT_UNKNOWN
;
566 internal_error ("Bad enum value");
570 show_packet_config_cmd (struct packet_config
*config
)
572 char *support
= "internal-error";
573 switch (config
->support
)
579 support
= "disabled";
581 case PACKET_SUPPORT_UNKNOWN
:
585 switch (config
->detect
)
587 case PACKET_AUTO_DETECT
:
588 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
589 config
->name
, config
->title
, support
);
591 case PACKET_MANUAL_DETECT
:
592 printf_filtered ("Support for remote protocol `%s' (%s) is currently %s.\n",
593 config
->name
, config
->title
, support
);
598 add_packet_config_cmd (config
, name
, title
, set_func
, show_func
,
600 struct packet_config
*config
;
603 void (*set_func
) (char *args
, int from_tty
, struct cmd_list_element
* c
);
604 void (*show_func
) (char *name
, int from_tty
);
605 struct cmd_list_element
**setlist
;
606 struct cmd_list_element
**showlist
;
608 struct cmd_list_element
*c
;
613 config
->title
= title
;
614 asprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
616 asprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
618 asprintf (&full_name
, "%s-packet", name
);
619 c
= add_set_enum_cmd (full_name
,
620 class_obscure
, packet_support_enums
,
623 c
->function
.sfunc
= set_func
;
624 add_cmd (full_name
, class_obscure
, show_func
, show_doc
, showlist
);
628 init_packet_config (struct packet_config
*config
)
630 switch (config
->detect
)
632 case PACKET_AUTO_DETECT
:
633 config
->support
= PACKET_SUPPORT_UNKNOWN
;
635 case PACKET_MANUAL_DETECT
:
636 /* let the user beware */
641 /* Should we try the 'P' (set register) request? */
643 static struct packet_config remote_protocol_P
;
646 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
647 struct cmd_list_element
*c
)
649 set_packet_config_cmd (&remote_protocol_P
, c
);
653 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
)
655 show_packet_config_cmd (&remote_protocol_P
);
658 /* Should we try the 'Z' (set breakpoint) request? */
660 static struct packet_config remote_protocol_Z
;
663 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
664 struct cmd_list_element
*c
)
666 set_packet_config_cmd (&remote_protocol_Z
, c
);
670 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
)
672 show_packet_config_cmd (&remote_protocol_Z
);
675 /* Should we try the 'X' (remote binary download) packet?
677 This variable (available to the user via "set remote X-packet")
678 dictates whether downloads are sent in binary (via the 'X' packet).
679 We assume that the stub can, and attempt to do it. This will be
680 cleared if the stub does not understand it. This switch is still
681 needed, though in cases when the packet is supported in the stub,
682 but the connection does not allow it (i.e., 7-bit serial connection
685 static struct packet_config remote_protocol_binary_download
;
687 /* Should we try the 'ThreadInfo' query packet?
689 This variable (NOT available to the user: auto-detect only!)
690 determines whether GDB will use the new, simpler "ThreadInfo"
691 query or the older, more complex syntax for thread queries.
692 This is an auto-detect variable (set to true at each connect,
693 and set to false when the target fails to recognize it). */
695 static int use_threadinfo_query
;
696 static int use_threadextra_query
;
699 set_remote_protocol_binary_download_cmd (char *args
,
701 struct cmd_list_element
*c
)
703 set_packet_config_cmd (&remote_protocol_binary_download
, c
);
707 show_remote_protocol_binary_download_cmd (char *args
,
710 show_packet_config_cmd (&remote_protocol_binary_download
);
714 /* Tokens for use by the asynchronous signal handlers for SIGINT */
715 PTR sigint_remote_twice_token
;
716 PTR sigint_remote_token
;
718 /* These are pointers to hook functions that may be set in order to
719 modify resume/wait behavior for a particular architecture. */
721 void (*target_resume_hook
) (void);
722 void (*target_wait_loop_hook
) (void);
726 /* These are the threads which we last sent to the remote system.
727 -1 for all or -2 for not sent yet. */
728 static int general_thread
;
729 static int continue_thread
;
731 /* Call this function as a result of
732 1) A halt indication (T packet) containing a thread id
733 2) A direct query of currthread
734 3) Successful execution of set thread
738 record_currthread (int currthread
)
740 general_thread
= currthread
;
742 /* If this is a new thread, add it to GDB's thread list.
743 If we leave it up to WFI to do this, bad things will happen. */
744 if (!in_thread_list (currthread
))
746 add_thread (currthread
);
748 ui_out_text (uiout
, "[New ");
749 ui_out_text (uiout
, target_pid_to_str (currthread
));
750 ui_out_text (uiout
, "]\n");
752 printf_filtered ("[New %s]\n", target_pid_to_str (currthread
));
757 #define MAGIC_NULL_PID 42000
760 set_thread (int th
, int gen
)
762 char *buf
= alloca (PBUFSIZ
);
763 int state
= gen
? general_thread
: continue_thread
;
769 buf
[1] = gen
? 'g' : 'c';
770 if (th
== MAGIC_NULL_PID
)
776 sprintf (&buf
[2], "-%x", -th
);
778 sprintf (&buf
[2], "%x", th
);
780 getpkt (buf
, PBUFSIZ
, 0);
784 continue_thread
= th
;
787 /* Return nonzero if the thread TH is still alive on the remote system. */
790 remote_thread_alive (int tid
)
795 sprintf (buf
, "T-%08x", -tid
);
797 sprintf (buf
, "T%08x", tid
);
799 getpkt (buf
, sizeof (buf
), 0);
800 return (buf
[0] == 'O' && buf
[1] == 'K');
803 /* About these extended threadlist and threadinfo packets. They are
804 variable length packets but, the fields within them are often fixed
805 length. They are redundent enough to send over UDP as is the
806 remote protocol in general. There is a matching unit test module
809 #define OPAQUETHREADBYTES 8
811 /* a 64 bit opaque identifier */
812 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
814 /* WARNING: This threadref data structure comes from the remote O.S., libstub
815 protocol encoding, and remote.c. it is not particularly changable */
817 /* Right now, the internal structure is int. We want it to be bigger.
821 typedef int gdb_threadref
; /* internal GDB thread reference */
823 /* gdb_ext_thread_info is an internal GDB data structure which is
824 equivalint to the reply of the remote threadinfo packet */
826 struct gdb_ext_thread_info
828 threadref threadid
; /* External form of thread reference */
829 int active
; /* Has state interesting to GDB? , regs, stack */
830 char display
[256]; /* Brief state display, name, blocked/syspended */
831 char shortname
[32]; /* To be used to name threads */
832 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
835 /* The volume of remote transfers can be limited by submitting
836 a mask containing bits specifying the desired information.
837 Use a union of these values as the 'selection' parameter to
838 get_thread_info. FIXME: Make these TAG names more thread specific.
841 #define TAG_THREADID 1
843 #define TAG_DISPLAY 4
844 #define TAG_THREADNAME 8
845 #define TAG_MOREDISPLAY 16
847 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
849 char *unpack_varlen_hex (char *buff
, int *result
);
851 static char *unpack_nibble (char *buf
, int *val
);
853 static char *pack_nibble (char *buf
, int nibble
);
855 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
857 static char *unpack_byte (char *buf
, int *value
);
859 static char *pack_int (char *buf
, int value
);
861 static char *unpack_int (char *buf
, int *value
);
863 static char *unpack_string (char *src
, char *dest
, int length
);
865 static char *pack_threadid (char *pkt
, threadref
* id
);
867 static char *unpack_threadid (char *inbuf
, threadref
* id
);
869 void int_to_threadref (threadref
* id
, int value
);
871 static int threadref_to_int (threadref
* ref
);
873 static void copy_threadref (threadref
* dest
, threadref
* src
);
875 static int threadmatch (threadref
* dest
, threadref
* src
);
877 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
879 static int remote_unpack_thread_info_response (char *pkt
,
880 threadref
* expectedref
,
881 struct gdb_ext_thread_info
885 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
886 struct gdb_ext_thread_info
*info
);
888 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
890 struct gdb_ext_thread_info
*info
);
892 static char *pack_threadlist_request (char *pkt
, int startflag
,
894 threadref
* nextthread
);
896 static int parse_threadlist_response (char *pkt
,
898 threadref
* original_echo
,
899 threadref
* resultlist
, int *doneflag
);
901 static int remote_get_threadlist (int startflag
,
902 threadref
* nextthread
,
905 int *result_count
, threadref
* threadlist
);
907 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
909 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
910 void *context
, int looplimit
);
912 static int remote_newthread_step (threadref
* ref
, void *context
);
914 /* encode 64 bits in 16 chars of hex */
916 static const char hexchars
[] = "0123456789abcdef";
919 ishex (int ch
, int *val
)
921 if ((ch
>= 'a') && (ch
<= 'f'))
923 *val
= ch
- 'a' + 10;
926 if ((ch
>= 'A') && (ch
<= 'F'))
928 *val
= ch
- 'A' + 10;
931 if ((ch
>= '0') && (ch
<= '9'))
942 if (ch
>= 'a' && ch
<= 'f')
943 return ch
- 'a' + 10;
944 if (ch
>= '0' && ch
<= '9')
946 if (ch
>= 'A' && ch
<= 'F')
947 return ch
- 'A' + 10;
952 stub_unpack_int (char *buff
, int fieldlength
)
959 nibble
= stubhex (*buff
++);
963 retval
= retval
<< 4;
969 unpack_varlen_hex (char *buff
, /* packet to parse */
975 while (ishex (*buff
, &nibble
))
978 retval
= retval
<< 4;
979 retval
|= nibble
& 0x0f;
986 unpack_nibble (char *buf
, int *val
)
993 pack_nibble (char *buf
, int nibble
)
995 *buf
++ = hexchars
[(nibble
& 0x0f)];
1000 pack_hex_byte (char *pkt
, int byte
)
1002 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1003 *pkt
++ = hexchars
[(byte
& 0xf)];
1008 unpack_byte (char *buf
, int *value
)
1010 *value
= stub_unpack_int (buf
, 2);
1015 pack_int (char *buf
, int value
)
1017 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1018 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1019 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1020 buf
= pack_hex_byte (buf
, (value
& 0xff));
1025 unpack_int (char *buf
, int *value
)
1027 *value
= stub_unpack_int (buf
, 8);
1031 #if 0 /* currently unused, uncomment when needed */
1032 static char *pack_string (char *pkt
, char *string
);
1035 pack_string (char *pkt
, char *string
)
1040 len
= strlen (string
);
1042 len
= 200; /* Bigger than most GDB packets, junk??? */
1043 pkt
= pack_hex_byte (pkt
, len
);
1047 if ((ch
== '\0') || (ch
== '#'))
1048 ch
= '*'; /* Protect encapsulation */
1053 #endif /* 0 (unused) */
1056 unpack_string (char *src
, char *dest
, int length
)
1065 pack_threadid (char *pkt
, threadref
*id
)
1068 unsigned char *altid
;
1070 altid
= (unsigned char *) id
;
1071 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1073 pkt
= pack_hex_byte (pkt
, *altid
++);
1079 unpack_threadid (char *inbuf
, threadref
*id
)
1082 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1085 altref
= (char *) id
;
1087 while (inbuf
< limit
)
1089 x
= stubhex (*inbuf
++);
1090 y
= stubhex (*inbuf
++);
1091 *altref
++ = (x
<< 4) | y
;
1096 /* Externally, threadrefs are 64 bits but internally, they are still
1097 ints. This is due to a mismatch of specifications. We would like
1098 to use 64bit thread references internally. This is an adapter
1102 int_to_threadref (threadref
*id
, int value
)
1104 unsigned char *scan
;
1106 scan
= (unsigned char *) id
;
1112 *scan
++ = (value
>> 24) & 0xff;
1113 *scan
++ = (value
>> 16) & 0xff;
1114 *scan
++ = (value
>> 8) & 0xff;
1115 *scan
++ = (value
& 0xff);
1119 threadref_to_int (threadref
*ref
)
1122 unsigned char *scan
;
1124 scan
= (char *) ref
;
1128 value
= (value
<< 8) | ((*scan
++) & 0xff);
1133 copy_threadref (threadref
*dest
, threadref
*src
)
1136 unsigned char *csrc
, *cdest
;
1138 csrc
= (unsigned char *) src
;
1139 cdest
= (unsigned char *) dest
;
1146 threadmatch (threadref
*dest
, threadref
*src
)
1148 /* things are broken right now, so just assume we got a match */
1150 unsigned char *srcp
, *destp
;
1152 srcp
= (char *) src
;
1153 destp
= (char *) dest
;
1157 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1164 threadid:1, # always request threadid
1171 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1174 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1176 *pkt
++ = 'q'; /* Info Query */
1177 *pkt
++ = 'P'; /* process or thread info */
1178 pkt
= pack_int (pkt
, mode
); /* mode */
1179 pkt
= pack_threadid (pkt
, id
); /* threadid */
1180 *pkt
= '\0'; /* terminate */
1184 /* These values tag the fields in a thread info response packet */
1185 /* Tagging the fields allows us to request specific fields and to
1186 add more fields as time goes by */
1188 #define TAG_THREADID 1 /* Echo the thread identifier */
1189 #define TAG_EXISTS 2 /* Is this process defined enough to
1190 fetch registers and its stack */
1191 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1192 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1193 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1197 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1198 struct gdb_ext_thread_info
*info
)
1203 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
1206 /* info->threadid = 0; FIXME: implement zero_threadref */
1208 info
->display
[0] = '\0';
1209 info
->shortname
[0] = '\0';
1210 info
->more_display
[0] = '\0';
1212 /* Assume the characters indicating the packet type have been stripped */
1213 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1214 pkt
= unpack_threadid (pkt
, &ref
);
1217 warning ("Incomplete response to threadinfo request\n");
1218 if (!threadmatch (&ref
, expectedref
))
1219 { /* This is an answer to a different request */
1220 warning ("ERROR RMT Thread info mismatch\n");
1223 copy_threadref (&info
->threadid
, &ref
);
1225 /* Loop on tagged fields , try to bail if somthing goes wrong */
1227 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1229 pkt
= unpack_int (pkt
, &tag
); /* tag */
1230 pkt
= unpack_byte (pkt
, &length
); /* length */
1231 if (!(tag
& mask
)) /* tags out of synch with mask */
1233 warning ("ERROR RMT: threadinfo tag mismatch\n");
1237 if (tag
== TAG_THREADID
)
1241 warning ("ERROR RMT: length of threadid is not 16\n");
1245 pkt
= unpack_threadid (pkt
, &ref
);
1246 mask
= mask
& ~TAG_THREADID
;
1249 if (tag
== TAG_EXISTS
)
1251 info
->active
= stub_unpack_int (pkt
, length
);
1253 mask
= mask
& ~(TAG_EXISTS
);
1256 warning ("ERROR RMT: 'exists' length too long\n");
1262 if (tag
== TAG_THREADNAME
)
1264 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1265 mask
= mask
& ~TAG_THREADNAME
;
1268 if (tag
== TAG_DISPLAY
)
1270 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1271 mask
= mask
& ~TAG_DISPLAY
;
1274 if (tag
== TAG_MOREDISPLAY
)
1276 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1277 mask
= mask
& ~TAG_MOREDISPLAY
;
1280 warning ("ERROR RMT: unknown thread info tag\n");
1281 break; /* Not a tag we know about */
1287 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1288 struct gdb_ext_thread_info
*info
)
1291 char *threadinfo_pkt
= alloca (PBUFSIZ
);
1293 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1294 putpkt (threadinfo_pkt
);
1295 getpkt (threadinfo_pkt
, PBUFSIZ
, 0);
1296 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1301 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1302 representation of a threadid. */
1305 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1306 struct gdb_ext_thread_info
*info
)
1310 int_to_threadref (&lclref
, *ref
);
1311 return remote_get_threadinfo (&lclref
, selection
, info
);
1314 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1317 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1318 threadref
*nextthread
)
1320 *pkt
++ = 'q'; /* info query packet */
1321 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1322 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1323 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1324 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1329 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1332 parse_threadlist_response (char *pkt
, int result_limit
,
1333 threadref
*original_echo
, threadref
*resultlist
,
1337 int count
, resultcount
, done
;
1340 /* Assume the 'q' and 'M chars have been stripped. */
1341 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1342 pkt
= unpack_byte (pkt
, &count
); /* count field */
1343 pkt
= unpack_nibble (pkt
, &done
);
1344 /* The first threadid is the argument threadid. */
1345 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1346 while ((count
-- > 0) && (pkt
< limit
))
1348 pkt
= unpack_threadid (pkt
, resultlist
++);
1349 if (resultcount
++ >= result_limit
)
1358 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1359 int *done
, int *result_count
, threadref
*threadlist
)
1361 static threadref echo_nextthread
;
1362 char *threadlist_packet
= alloca (PBUFSIZ
);
1363 char *t_response
= alloca (PBUFSIZ
);
1366 /* Trancate result limit to be smaller than the packet size */
1367 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1368 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1370 pack_threadlist_request (threadlist_packet
,
1371 startflag
, result_limit
, nextthread
);
1372 putpkt (threadlist_packet
);
1373 getpkt (t_response
, PBUFSIZ
, 0);
1376 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1379 if (!threadmatch (&echo_nextthread
, nextthread
))
1381 /* FIXME: This is a good reason to drop the packet */
1382 /* Possably, there is a duplicate response */
1384 retransmit immediatly - race conditions
1385 retransmit after timeout - yes
1387 wait for packet, then exit
1389 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1390 return 0; /* I choose simply exiting */
1392 if (*result_count
<= 0)
1396 warning ("RMT ERROR : failed to get remote thread list\n");
1399 return result
; /* break; */
1401 if (*result_count
> result_limit
)
1404 warning ("RMT ERROR: threadlist response longer than requested\n");
1410 /* This is the interface between remote and threads, remotes upper interface */
1412 /* remote_find_new_threads retrieves the thread list and for each
1413 thread in the list, looks up the thread in GDB's internal list,
1414 ading the thread if it does not already exist. This involves
1415 getting partial thread lists from the remote target so, polling the
1416 quit_flag is required. */
1419 /* About this many threadisds fit in a packet. */
1421 #define MAXTHREADLISTRESULTS 32
1424 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1427 int done
, i
, result_count
;
1431 static threadref nextthread
;
1432 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1437 if (loopcount
++ > looplimit
)
1440 warning ("Remote fetch threadlist -infinite loop-\n");
1443 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1444 &done
, &result_count
, resultthreadlist
))
1449 /* clear for later iterations */
1451 /* Setup to resume next batch of thread references, set nextthread. */
1452 if (result_count
>= 1)
1453 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1455 while (result_count
--)
1456 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1463 remote_newthread_step (threadref
*ref
, void *context
)
1467 pid
= threadref_to_int (ref
);
1468 if (!in_thread_list (pid
))
1470 return 1; /* continue iterator */
1473 #define CRAZY_MAX_THREADS 1000
1476 remote_current_thread (int oldpid
)
1478 char *buf
= alloca (PBUFSIZ
);
1481 getpkt (buf
, PBUFSIZ
, 0);
1482 if (buf
[0] == 'Q' && buf
[1] == 'C')
1483 return strtol (&buf
[2], NULL
, 16);
1488 /* Find new threads for info threads command.
1489 * Original version, using John Metzler's thread protocol.
1493 remote_find_new_threads (void)
1495 remote_threadlist_iterator (remote_newthread_step
, 0,
1497 if (inferior_pid
== MAGIC_NULL_PID
) /* ack ack ack */
1498 inferior_pid
= remote_current_thread (inferior_pid
);
1502 * Find all threads for info threads command.
1503 * Uses new thread protocol contributed by Cisco.
1504 * Falls back and attempts to use the older method (above)
1505 * if the target doesn't respond to the new method.
1509 remote_threads_info (void)
1511 char *buf
= alloca (PBUFSIZ
);
1515 if (remote_desc
== 0) /* paranoia */
1516 error ("Command can only be used when connected to the remote target.");
1518 if (use_threadinfo_query
)
1520 putpkt ("qfThreadInfo");
1522 getpkt (bufp
, PBUFSIZ
, 0);
1523 if (bufp
[0] != '\0') /* q packet recognized */
1525 while (*bufp
++ == 'm') /* reply contains one or more TID */
1529 tid
= strtol (bufp
, &bufp
, 16);
1530 if (tid
!= 0 && !in_thread_list (tid
))
1533 while (*bufp
++ == ','); /* comma-separated list */
1534 putpkt ("qsThreadInfo");
1536 getpkt (bufp
, PBUFSIZ
, 0);
1542 /* Else fall back to old method based on jmetzler protocol. */
1543 use_threadinfo_query
= 0;
1544 remote_find_new_threads ();
1549 * Collect a descriptive string about the given thread.
1550 * The target may say anything it wants to about the thread
1551 * (typically info about its blocked / runnable state, name, etc.).
1552 * This string will appear in the info threads display.
1554 * Optional: targets are not required to implement this function.
1558 remote_threads_extra_info (struct thread_info
*tp
)
1563 struct gdb_ext_thread_info threadinfo
;
1564 static char display_buf
[100]; /* arbitrary... */
1565 char *bufp
= alloca (PBUFSIZ
);
1566 int n
= 0; /* position in display_buf */
1568 if (remote_desc
== 0) /* paranoia */
1569 internal_error ("remote_threads_extra_info");
1571 if (use_threadextra_query
)
1573 sprintf (bufp
, "qThreadExtraInfo,%x", tp
->pid
);
1575 getpkt (bufp
, PBUFSIZ
, 0);
1580 for (p
= display_buf
;
1581 p
< display_buf
+ sizeof(display_buf
) - 1 &&
1586 *p
= fromhex (bufp
[0]) * 16 + fromhex (bufp
[1]);
1593 /* If the above query fails, fall back to the old method. */
1594 use_threadextra_query
= 0;
1595 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1596 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1597 int_to_threadref (&id
, tp
->pid
);
1598 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1599 if (threadinfo
.active
)
1601 if (*threadinfo
.shortname
)
1602 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1603 if (*threadinfo
.display
)
1604 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1605 if (*threadinfo
.more_display
)
1606 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1607 threadinfo
.more_display
);
1611 /* for purely cosmetic reasons, clear up trailing commas */
1612 if (',' == display_buf
[n
-1])
1613 display_buf
[n
-1] = ' ';
1622 /* Restart the remote side; this is an extended protocol operation. */
1625 extended_remote_restart (void)
1627 char *buf
= alloca (PBUFSIZ
);
1629 /* Send the restart command; for reasons I don't understand the
1630 remote side really expects a number after the "R". */
1632 sprintf (&buf
[1], "%x", 0);
1635 /* Now query for status so this looks just like we restarted
1636 gdbserver from scratch. */
1638 getpkt (buf
, PBUFSIZ
, 0);
1641 /* Clean up connection to a remote debugger. */
1645 remote_close (int quitting
)
1648 SERIAL_CLOSE (remote_desc
);
1652 /* Query the remote side for the text, data and bss offsets. */
1657 char *buf
= alloca (PBUFSIZ
);
1660 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1661 struct section_offsets
*offs
;
1663 putpkt ("qOffsets");
1665 getpkt (buf
, PBUFSIZ
, 0);
1667 if (buf
[0] == '\000')
1668 return; /* Return silently. Stub doesn't support
1672 warning ("Remote failure reply: %s", buf
);
1676 /* Pick up each field in turn. This used to be done with scanf, but
1677 scanf will make trouble if CORE_ADDR size doesn't match
1678 conversion directives correctly. The following code will work
1679 with any size of CORE_ADDR. */
1680 text_addr
= data_addr
= bss_addr
= 0;
1684 if (strncmp (ptr
, "Text=", 5) == 0)
1687 /* Don't use strtol, could lose on big values. */
1688 while (*ptr
&& *ptr
!= ';')
1689 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1694 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1697 while (*ptr
&& *ptr
!= ';')
1698 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1703 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1706 while (*ptr
&& *ptr
!= ';')
1707 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1713 error ("Malformed response to offset query, %s", buf
);
1715 if (symfile_objfile
== NULL
)
1718 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1719 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1721 ANOFFSET (offs
, SECT_OFF_TEXT (symfile_objfile
)) = text_addr
;
1723 /* This is a temporary kludge to force data and bss to use the same offsets
1724 because that's what nlmconv does now. The real solution requires changes
1725 to the stub and remote.c that I don't have time to do right now. */
1727 ANOFFSET (offs
, SECT_OFF_DATA (symfile_objfile
)) = data_addr
;
1728 ANOFFSET (offs
, SECT_OFF_BSS (symfile_objfile
)) = data_addr
;
1730 objfile_relocate (symfile_objfile
, offs
);
1734 * Cisco version of section offsets:
1736 * Instead of having GDB query the target for the section offsets,
1737 * Cisco lets the target volunteer the information! It's also in
1738 * a different format, so here are the functions that will decode
1739 * a section offset packet from a Cisco target.
1743 * Function: remote_cisco_section_offsets
1745 * Returns: zero for success, non-zero for failure
1749 remote_cisco_section_offsets (bfd_vma text_addr
,
1752 bfd_signed_vma
*text_offs
,
1753 bfd_signed_vma
*data_offs
,
1754 bfd_signed_vma
*bss_offs
)
1756 bfd_vma text_base
, data_base
, bss_base
;
1757 struct minimal_symbol
*start
;
1763 if (symfile_objfile
== NULL
)
1764 return -1; /* no can do nothin' */
1766 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
1768 return -1; /* Can't find "_start" symbol */
1770 data_base
= bss_base
= 0;
1771 text_base
= SYMBOL_VALUE_ADDRESS (start
);
1773 abfd
= symfile_objfile
->obfd
;
1774 for (sect
= abfd
->sections
;
1778 p
= (unsigned char *) bfd_get_section_name (abfd
, sect
);
1780 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
1781 if (data_base
== 0 ||
1782 data_base
> bfd_get_section_vma (abfd
, sect
))
1783 data_base
= bfd_get_section_vma (abfd
, sect
);
1784 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
1785 if (bss_base
== 0 ||
1786 bss_base
> bfd_get_section_vma (abfd
, sect
))
1787 bss_base
= bfd_get_section_vma (abfd
, sect
);
1789 *text_offs
= text_addr
- text_base
;
1790 *data_offs
= data_addr
- data_base
;
1791 *bss_offs
= bss_addr
- bss_base
;
1796 sprintf (tmp
, "VMA: text = 0x");
1797 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
1798 sprintf (tmp
+ strlen (tmp
), " data = 0x");
1799 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
1800 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
1801 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
1802 fprintf_filtered (gdb_stdlog
, tmp
);
1803 fprintf_filtered (gdb_stdlog
,
1804 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
1805 paddr_nz (*text_offs
),
1806 paddr_nz (*data_offs
),
1807 paddr_nz (*bss_offs
));
1814 * Function: remote_cisco_objfile_relocate
1816 * Relocate the symbol file for a remote target.
1820 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
1821 bfd_signed_vma bss_off
)
1823 struct section_offsets
*offs
;
1825 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
1827 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1828 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1829 simple canonical representation for this stuff. */
1831 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1832 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1834 ANOFFSET (offs
, SECT_OFF_TEXT (symfile_objfile
)) = text_off
;
1835 ANOFFSET (offs
, SECT_OFF_DATA (symfile_objfile
)) = data_off
;
1836 ANOFFSET (offs
, SECT_OFF_BSS (symfile_objfile
)) = bss_off
;
1838 /* First call the standard objfile_relocate. */
1839 objfile_relocate (symfile_objfile
, offs
);
1841 /* Now we need to fix up the section entries already attached to
1842 the exec target. These entries will control memory transfers
1843 from the exec file. */
1845 exec_set_section_offsets (text_off
, data_off
, bss_off
);
1849 /* Stub for catch_errors. */
1852 remote_start_remote_dummy (void *dummy
)
1854 start_remote (); /* Initialize gdb process mechanisms */
1859 remote_start_remote (PTR dummy
)
1861 immediate_quit
= 1; /* Allow user to interrupt it */
1863 /* Ack any packet which the remote side has already sent. */
1864 SERIAL_WRITE (remote_desc
, "+", 1);
1866 /* Let the stub know that we want it to return the thread. */
1869 inferior_pid
= remote_current_thread (inferior_pid
);
1871 get_offsets (); /* Get text, data & bss offsets */
1873 putpkt ("?"); /* initiate a query from remote machine */
1876 return remote_start_remote_dummy (dummy
);
1879 /* Open a connection to a remote debugger.
1880 NAME is the filename used for communication. */
1883 remote_open (char *name
, int from_tty
)
1885 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
1888 /* Just like remote_open, but with asynchronous support. */
1890 remote_async_open (char *name
, int from_tty
)
1892 remote_async_open_1 (name
, from_tty
, &remote_async_ops
, 0);
1895 /* Open a connection to a remote debugger using the extended
1896 remote gdb protocol. NAME is the filename used for communication. */
1899 extended_remote_open (char *name
, int from_tty
)
1901 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */ );
1904 /* Just like extended_remote_open, but with asynchronous support. */
1906 extended_remote_async_open (char *name
, int from_tty
)
1908 remote_async_open_1 (name
, from_tty
, &extended_async_remote_ops
, 1 /*extended_p */ );
1911 /* Generic code for opening a connection to a remote target. */
1913 static DCACHE
*remote_dcache
;
1916 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
1920 error ("To open a remote debug connection, you need to specify what\n\
1921 serial device is attached to the remote system\n\
1922 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
1924 /* See FIXME above */
1925 wait_forever_enabled_p
= 1;
1927 target_preopen (from_tty
);
1929 unpush_target (target
);
1931 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1933 remote_desc
= SERIAL_OPEN (name
);
1935 perror_with_name (name
);
1937 if (baud_rate
!= -1)
1939 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1941 SERIAL_CLOSE (remote_desc
);
1942 perror_with_name (name
);
1946 SERIAL_RAW (remote_desc
);
1948 /* If there is something sitting in the buffer we might take it as a
1949 response to a command, which would be bad. */
1950 SERIAL_FLUSH_INPUT (remote_desc
);
1954 puts_filtered ("Remote debugging using ");
1955 puts_filtered (name
);
1956 puts_filtered ("\n");
1958 push_target (target
); /* Switch to using remote target now */
1960 init_packet_config (&remote_protocol_P
);
1961 init_packet_config (&remote_protocol_Z
);
1963 general_thread
= -2;
1964 continue_thread
= -2;
1966 /* Force remote_write_bytes to check whether target supports
1967 binary downloading. */
1968 init_packet_config (&remote_protocol_binary_download
);
1970 /* Probe for ability to use "ThreadInfo" query, as required. */
1971 use_threadinfo_query
= 1;
1972 use_threadextra_query
= 1;
1974 /* Without this, some commands which require an active target (such
1975 as kill) won't work. This variable serves (at least) double duty
1976 as both the pid of the target process (if it has such), and as a
1977 flag indicating that a target is active. These functions should
1978 be split out into seperate variables, especially since GDB will
1979 someday have a notion of debugging several processes. */
1981 inferior_pid
= MAGIC_NULL_PID
;
1982 /* Start the remote connection; if error (0), discard this target.
1983 In particular, if the user quits, be sure to discard it
1984 (we'd be in an inconsistent state otherwise). */
1985 if (!catch_errors (remote_start_remote
, NULL
,
1986 "Couldn't establish connection to remote target\n",
1995 /* tell the remote that we're using the extended protocol. */
1996 char *buf
= alloca (PBUFSIZ
);
1998 getpkt (buf
, PBUFSIZ
, 0);
2002 /* Just like remote_open but with asynchronous support. */
2004 remote_async_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2008 error ("To open a remote debug connection, you need to specify what\n\
2009 serial device is attached to the remote system\n\
2010 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2012 target_preopen (from_tty
);
2014 unpush_target (target
);
2016 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
2018 remote_desc
= SERIAL_OPEN (name
);
2020 perror_with_name (name
);
2022 if (baud_rate
!= -1)
2024 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
2026 SERIAL_CLOSE (remote_desc
);
2027 perror_with_name (name
);
2031 SERIAL_RAW (remote_desc
);
2033 /* If there is something sitting in the buffer we might take it as a
2034 response to a command, which would be bad. */
2035 SERIAL_FLUSH_INPUT (remote_desc
);
2039 puts_filtered ("Remote debugging using ");
2040 puts_filtered (name
);
2041 puts_filtered ("\n");
2044 push_target (target
); /* Switch to using remote target now */
2046 init_packet_config (&remote_protocol_P
);
2047 init_packet_config (&remote_protocol_Z
);
2049 general_thread
= -2;
2050 continue_thread
= -2;
2052 /* Force remote_write_bytes to check whether target supports
2053 binary downloading. */
2054 init_packet_config (&remote_protocol_binary_download
);
2056 /* Probe for ability to use "ThreadInfo" query, as required. */
2057 use_threadinfo_query
= 1;
2058 use_threadextra_query
= 1;
2060 /* Without this, some commands which require an active target (such
2061 as kill) won't work. This variable serves (at least) double duty
2062 as both the pid of the target process (if it has such), and as a
2063 flag indicating that a target is active. These functions should
2064 be split out into seperate variables, especially since GDB will
2065 someday have a notion of debugging several processes. */
2066 inferior_pid
= MAGIC_NULL_PID
;
2068 /* With this target we start out by owning the terminal. */
2069 remote_async_terminal_ours_p
= 1;
2071 /* FIXME: cagney/1999-09-23: During the initial connection it is
2072 assumed that the target is already ready and able to respond to
2073 requests. Unfortunatly remote_start_remote() eventually calls
2074 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2075 around this. Eventually a mechanism that allows
2076 wait_for_inferior() to expect/get timeouts will be
2078 wait_forever_enabled_p
= 0;
2080 /* Start the remote connection; if error (0), discard this target.
2081 In particular, if the user quits, be sure to discard it
2082 (we'd be in an inconsistent state otherwise). */
2083 if (!catch_errors (remote_start_remote
, NULL
,
2084 "Couldn't establish connection to remote target\n",
2088 wait_forever_enabled_p
= 1;
2092 wait_forever_enabled_p
= 1;
2096 /* tell the remote that we're using the extended protocol. */
2097 char *buf
= alloca (PBUFSIZ
);
2099 getpkt (buf
, PBUFSIZ
, 0);
2103 /* This takes a program previously attached to and detaches it. After
2104 this is done, GDB can be used to debug some other program. We
2105 better not have left any breakpoints in the target program or it'll
2106 die when it hits one. */
2109 remote_detach (char *args
, int from_tty
)
2111 char *buf
= alloca (PBUFSIZ
);
2114 error ("Argument given to \"detach\" when remotely debugging.");
2116 /* Tell the remote target to detach. */
2118 remote_send (buf
, PBUFSIZ
);
2120 target_mourn_inferior ();
2122 puts_filtered ("Ending remote debugging.\n");
2126 /* Same as remote_detach, but with async support. */
2128 remote_async_detach (char *args
, int from_tty
)
2130 char *buf
= alloca (PBUFSIZ
);
2133 error ("Argument given to \"detach\" when remotely debugging.");
2135 /* Tell the remote target to detach. */
2137 remote_send (buf
, PBUFSIZ
);
2139 /* Unregister the file descriptor from the event loop. */
2140 if (target_is_async_p ())
2141 SERIAL_ASYNC (remote_desc
, NULL
, 0);
2143 target_mourn_inferior ();
2145 puts_filtered ("Ending remote debugging.\n");
2148 /* Convert hex digit A to a number. */
2153 if (a
>= '0' && a
<= '9')
2155 else if (a
>= 'a' && a
<= 'f')
2156 return a
- 'a' + 10;
2157 else if (a
>= 'A' && a
<= 'F')
2158 return a
- 'A' + 10;
2160 error ("Reply contains invalid hex digit %d", a
);
2163 /* Convert number NIB to a hex digit. */
2171 return 'a' + nib
- 10;
2174 /* Tell the remote machine to resume. */
2176 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2178 static int last_sent_step
;
2181 remote_resume (int pid
, int step
, enum target_signal siggnal
)
2183 char *buf
= alloca (PBUFSIZ
);
2186 set_thread (0, 0); /* run any thread */
2188 set_thread (pid
, 0); /* run this thread */
2190 dcache_flush (remote_dcache
);
2192 last_sent_signal
= siggnal
;
2193 last_sent_step
= step
;
2195 /* A hook for when we need to do something at the last moment before
2197 if (target_resume_hook
)
2198 (*target_resume_hook
) ();
2200 if (siggnal
!= TARGET_SIGNAL_0
)
2202 buf
[0] = step
? 'S' : 'C';
2203 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2204 buf
[2] = tohex ((int) siggnal
& 0xf);
2208 strcpy (buf
, step
? "s" : "c");
2213 /* Same as remote_resume, but with async support. */
2215 remote_async_resume (int pid
, int step
, enum target_signal siggnal
)
2217 char *buf
= alloca (PBUFSIZ
);
2220 set_thread (0, 0); /* run any thread */
2222 set_thread (pid
, 0); /* run this thread */
2224 dcache_flush (remote_dcache
);
2226 last_sent_signal
= siggnal
;
2227 last_sent_step
= step
;
2229 /* A hook for when we need to do something at the last moment before
2231 if (target_resume_hook
)
2232 (*target_resume_hook
) ();
2234 if (siggnal
!= TARGET_SIGNAL_0
)
2236 buf
[0] = step
? 'S' : 'C';
2237 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2238 buf
[2] = tohex ((int) siggnal
& 0xf);
2242 strcpy (buf
, step
? "s" : "c");
2244 /* We are about to start executing the inferior, let's register it
2245 with the event loop. NOTE: this is the one place where all the
2246 execution commands end up. We could alternatively do this in each
2247 of the execution commands in infcmd.c.*/
2248 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2249 into infcmd.c in order to allow inferior function calls to work
2250 NOT asynchronously. */
2251 if (event_loop_p
&& target_can_async_p ())
2252 target_async (inferior_event_handler
, 0);
2253 /* Tell the world that the target is now executing. */
2254 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2255 this? Instead, should the client of target just assume (for
2256 async targets) that the target is going to start executing? Is
2257 this information already found in the continuation block? */
2258 if (target_is_async_p ())
2259 target_executing
= 1;
2264 /* Set up the signal handler for SIGINT, while the target is
2265 executing, ovewriting the 'regular' SIGINT signal handler. */
2267 initialize_sigint_signal_handler (void)
2269 sigint_remote_token
=
2270 create_async_signal_handler (async_remote_interrupt
, NULL
);
2271 signal (SIGINT
, handle_remote_sigint
);
2274 /* Signal handler for SIGINT, while the target is executing. */
2276 handle_remote_sigint (int sig
)
2278 signal (sig
, handle_remote_sigint_twice
);
2279 sigint_remote_twice_token
=
2280 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2281 mark_async_signal_handler_wrapper (sigint_remote_token
);
2284 /* Signal handler for SIGINT, installed after SIGINT has already been
2285 sent once. It will take effect the second time that the user sends
2288 handle_remote_sigint_twice (int sig
)
2290 signal (sig
, handle_sigint
);
2291 sigint_remote_twice_token
=
2292 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2293 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2296 /* Perform the real interruption of the target execution, in response
2299 async_remote_interrupt (gdb_client_data arg
)
2302 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2307 /* Perform interrupt, if the first attempt did not succeed. Just give
2308 up on the target alltogether. */
2310 async_remote_interrupt_twice (gdb_client_data arg
)
2313 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2314 /* Do something only if the target was not killed by the previous
2316 if (target_executing
)
2319 signal (SIGINT
, handle_remote_sigint
);
2323 /* Reinstall the usual SIGINT handlers, after the target has
2326 cleanup_sigint_signal_handler (void *dummy
)
2328 signal (SIGINT
, handle_sigint
);
2329 if (sigint_remote_twice_token
)
2330 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2331 if (sigint_remote_token
)
2332 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2335 /* Send ^C to target to halt it. Target will respond, and send us a
2337 static void (*ofunc
) (int);
2339 /* The command line interface's stop routine. This function is installed
2340 as a signal handler for SIGINT. The first time a user requests a
2341 stop, we call remote_stop to send a break or ^C. If there is no
2342 response from the target (it didn't stop when the user requested it),
2343 we ask the user if he'd like to detach from the target. */
2345 remote_interrupt (int signo
)
2347 /* If this doesn't work, try more severe steps. */
2348 signal (signo
, remote_interrupt_twice
);
2351 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2356 /* The user typed ^C twice. */
2359 remote_interrupt_twice (int signo
)
2361 signal (signo
, ofunc
);
2363 signal (signo
, remote_interrupt
);
2366 /* This is the generic stop called via the target vector. When a target
2367 interrupt is requested, either by the command line or the GUI, we
2368 will eventually end up here. */
2372 /* Send a break or a ^C, depending on user preference. */
2374 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2377 SERIAL_SEND_BREAK (remote_desc
);
2379 SERIAL_WRITE (remote_desc
, "\003", 1);
2382 /* Ask the user what to do when an interrupt is received. */
2385 interrupt_query (void)
2387 target_terminal_ours ();
2389 if (query ("Interrupted while waiting for the program.\n\
2390 Give up (and stop debugging it)? "))
2392 target_mourn_inferior ();
2393 return_to_top_level (RETURN_QUIT
);
2396 target_terminal_inferior ();
2399 /* Enable/disable target terminal ownership. Most targets can use
2400 terminal groups to control terminal ownership. Remote targets are
2401 different in that explicit transfer of ownership to/from GDB/target
2405 remote_async_terminal_inferior (void)
2407 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2408 sync_execution here. This function should only be called when
2409 GDB is resuming the inferior in the forground. A background
2410 resume (``run&'') should leave GDB in control of the terminal and
2411 consequently should not call this code. */
2412 if (!sync_execution
)
2414 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2415 calls target_terminal_*() idenpotent. The event-loop GDB talking
2416 to an asynchronous target with a synchronous command calls this
2417 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2418 stops trying to transfer the terminal to the target when it
2419 shouldn't this guard can go away. */
2420 if (!remote_async_terminal_ours_p
)
2422 delete_file_handler (input_fd
);
2423 remote_async_terminal_ours_p
= 0;
2424 initialize_sigint_signal_handler ();
2425 /* NOTE: At this point we could also register our selves as the
2426 recipient of all input. Any characters typed could then be
2427 passed on down to the target. */
2431 remote_async_terminal_ours (void)
2433 /* See FIXME in remote_async_terminal_inferior. */
2434 if (!sync_execution
)
2436 /* See FIXME in remote_async_terminal_inferior. */
2437 if (remote_async_terminal_ours_p
)
2439 cleanup_sigint_signal_handler (NULL
);
2440 add_file_handler (input_fd
, stdin_event_handler
, 0);
2441 remote_async_terminal_ours_p
= 1;
2444 /* If nonzero, ignore the next kill. */
2449 remote_console_output (char *msg
)
2453 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2456 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2459 fputs_unfiltered (tb
, gdb_stdtarg
);
2461 gdb_flush (gdb_stdtarg
);
2464 /* Wait until the remote machine stops, then return,
2465 storing status in STATUS just as `wait' would.
2466 Returns "pid", which in the case of a multi-threaded
2467 remote OS, is the thread-id. */
2470 remote_wait (int pid
, struct target_waitstatus
*status
)
2472 unsigned char *buf
= alloca (PBUFSIZ
);
2473 int thread_num
= -1;
2475 status
->kind
= TARGET_WAITKIND_EXITED
;
2476 status
->value
.integer
= 0;
2482 ofunc
= signal (SIGINT
, remote_interrupt
);
2483 getpkt (buf
, PBUFSIZ
, 1);
2484 signal (SIGINT
, ofunc
);
2486 /* This is a hook for when we need to do something (perhaps the
2487 collection of trace data) every time the target stops. */
2488 if (target_wait_loop_hook
)
2489 (*target_wait_loop_hook
) ();
2493 case 'E': /* Error of some sort */
2494 warning ("Remote failure reply: %s", buf
);
2496 case 'T': /* Status with PC, SP, FP, ... */
2500 char regs
[MAX_REGISTER_RAW_SIZE
];
2502 /* Expedited reply, containing Signal, {regno, reg} repeat */
2503 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2505 n... = register number
2506 r... = register contents
2508 p
= &buf
[3]; /* after Txx */
2515 /* Read the register number */
2516 regno
= strtol ((const char *) p
, &p_temp
, 16);
2517 p1
= (unsigned char *) p_temp
;
2519 if (p1
== p
) /* No register number present here */
2521 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2523 warning ("Malformed packet(a) (missing colon): %s\n\
2526 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2528 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2529 record_currthread (thread_num
);
2530 p
= (unsigned char *) p_temp
;
2538 warning ("Malformed packet(b) (missing colon): %s\n\
2542 if (regno
>= NUM_REGS
)
2543 warning ("Remote sent bad register number %ld: %s\n\
2547 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2549 if (p
[0] == 0 || p
[1] == 0)
2550 warning ("Remote reply is too short: %s", buf
);
2551 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2554 supply_register (regno
, regs
);
2559 warning ("Remote register badly formatted: %s", buf
);
2560 warning (" here: %s", p
);
2565 case 'S': /* Old style status, just signal only */
2566 status
->kind
= TARGET_WAITKIND_STOPPED
;
2567 status
->value
.sig
= (enum target_signal
)
2568 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2572 /* Export Cisco kernel mode as a convenience variable
2573 (so that it can be used in the GDB prompt if desired). */
2575 if (cisco_kernel_mode
== 1)
2576 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2577 value_from_string ("PDEBUG-"));
2578 cisco_kernel_mode
= 0;
2579 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2580 record_currthread (thread_num
);
2582 else if (buf
[3] == 'k')
2584 /* Export Cisco kernel mode as a convenience variable
2585 (so that it can be used in the GDB prompt if desired). */
2587 if (cisco_kernel_mode
== 1)
2588 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2589 value_from_string ("KDEBUG-"));
2590 cisco_kernel_mode
= 1;
2593 case 'N': /* Cisco special: status and offsets */
2595 bfd_vma text_addr
, data_addr
, bss_addr
;
2596 bfd_signed_vma text_off
, data_off
, bss_off
;
2599 status
->kind
= TARGET_WAITKIND_STOPPED
;
2600 status
->value
.sig
= (enum target_signal
)
2601 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2603 if (symfile_objfile
== NULL
)
2605 warning ("Relocation packet received with no symbol file. \
2610 /* Relocate object file. Buffer format is NAATT;DD;BB
2611 * where AA is the signal number, TT is the new text
2612 * address, DD * is the new data address, and BB is the
2613 * new bss address. */
2616 text_addr
= strtoul (p
, (char **) &p1
, 16);
2617 if (p1
== p
|| *p1
!= ';')
2618 warning ("Malformed relocation packet: Packet '%s'", buf
);
2620 data_addr
= strtoul (p
, (char **) &p1
, 16);
2621 if (p1
== p
|| *p1
!= ';')
2622 warning ("Malformed relocation packet: Packet '%s'", buf
);
2624 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2626 warning ("Malformed relocation packet: Packet '%s'", buf
);
2628 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2629 &text_off
, &data_off
, &bss_off
)
2631 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2632 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2636 case 'W': /* Target exited */
2638 /* The remote process exited. */
2639 status
->kind
= TARGET_WAITKIND_EXITED
;
2640 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2644 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2645 status
->value
.sig
= (enum target_signal
)
2646 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2650 case 'O': /* Console output */
2651 remote_console_output (buf
+ 1);
2654 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2656 /* Zero length reply means that we tried 'S' or 'C' and
2657 the remote system doesn't support it. */
2658 target_terminal_ours_for_output ();
2660 ("Can't send signals to this remote system. %s not sent.\n",
2661 target_signal_to_name (last_sent_signal
));
2662 last_sent_signal
= TARGET_SIGNAL_0
;
2663 target_terminal_inferior ();
2665 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2666 putpkt ((char *) buf
);
2669 /* else fallthrough */
2671 warning ("Invalid remote reply: %s", buf
);
2676 if (thread_num
!= -1)
2680 return inferior_pid
;
2683 /* Async version of remote_wait. */
2685 remote_async_wait (int pid
, struct target_waitstatus
*status
)
2687 unsigned char *buf
= alloca (PBUFSIZ
);
2688 int thread_num
= -1;
2690 status
->kind
= TARGET_WAITKIND_EXITED
;
2691 status
->value
.integer
= 0;
2697 if (!target_is_async_p ())
2698 ofunc
= signal (SIGINT
, remote_interrupt
);
2699 /* FIXME: cagney/1999-09-27: If we're in async mode we should
2700 _never_ wait for ever -> test on target_is_async_p().
2701 However, before we do that we need to ensure that the caller
2702 knows how to take the target into/out of async mode. */
2703 getpkt (buf
, PBUFSIZ
, wait_forever_enabled_p
);
2704 if (!target_is_async_p ())
2705 signal (SIGINT
, ofunc
);
2707 /* This is a hook for when we need to do something (perhaps the
2708 collection of trace data) every time the target stops. */
2709 if (target_wait_loop_hook
)
2710 (*target_wait_loop_hook
) ();
2714 case 'E': /* Error of some sort */
2715 warning ("Remote failure reply: %s", buf
);
2717 case 'T': /* Status with PC, SP, FP, ... */
2721 char regs
[MAX_REGISTER_RAW_SIZE
];
2723 /* Expedited reply, containing Signal, {regno, reg} repeat */
2724 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2726 n... = register number
2727 r... = register contents
2729 p
= &buf
[3]; /* after Txx */
2736 /* Read the register number */
2737 regno
= strtol ((const char *) p
, &p_temp
, 16);
2738 p1
= (unsigned char *) p_temp
;
2740 if (p1
== p
) /* No register number present here */
2742 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2744 warning ("Malformed packet(a) (missing colon): %s\n\
2747 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2749 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2750 record_currthread (thread_num
);
2751 p
= (unsigned char *) p_temp
;
2759 warning ("Malformed packet(b) (missing colon): %s\n\
2763 if (regno
>= NUM_REGS
)
2764 warning ("Remote sent bad register number %ld: %s\n\
2768 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2770 if (p
[0] == 0 || p
[1] == 0)
2771 warning ("Remote reply is too short: %s", buf
);
2772 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2775 supply_register (regno
, regs
);
2780 warning ("Remote register badly formatted: %s", buf
);
2781 warning (" here: %s", p
);
2786 case 'S': /* Old style status, just signal only */
2787 status
->kind
= TARGET_WAITKIND_STOPPED
;
2788 status
->value
.sig
= (enum target_signal
)
2789 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2793 /* Export Cisco kernel mode as a convenience variable
2794 (so that it can be used in the GDB prompt if desired). */
2796 if (cisco_kernel_mode
== 1)
2797 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2798 value_from_string ("PDEBUG-"));
2799 cisco_kernel_mode
= 0;
2800 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2801 record_currthread (thread_num
);
2803 else if (buf
[3] == 'k')
2805 /* Export Cisco kernel mode as a convenience variable
2806 (so that it can be used in the GDB prompt if desired). */
2808 if (cisco_kernel_mode
== 1)
2809 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2810 value_from_string ("KDEBUG-"));
2811 cisco_kernel_mode
= 1;
2814 case 'N': /* Cisco special: status and offsets */
2816 bfd_vma text_addr
, data_addr
, bss_addr
;
2817 bfd_signed_vma text_off
, data_off
, bss_off
;
2820 status
->kind
= TARGET_WAITKIND_STOPPED
;
2821 status
->value
.sig
= (enum target_signal
)
2822 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2824 if (symfile_objfile
== NULL
)
2826 warning ("Relocation packet recieved with no symbol file. \
2831 /* Relocate object file. Buffer format is NAATT;DD;BB
2832 * where AA is the signal number, TT is the new text
2833 * address, DD * is the new data address, and BB is the
2834 * new bss address. */
2837 text_addr
= strtoul (p
, (char **) &p1
, 16);
2838 if (p1
== p
|| *p1
!= ';')
2839 warning ("Malformed relocation packet: Packet '%s'", buf
);
2841 data_addr
= strtoul (p
, (char **) &p1
, 16);
2842 if (p1
== p
|| *p1
!= ';')
2843 warning ("Malformed relocation packet: Packet '%s'", buf
);
2845 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2847 warning ("Malformed relocation packet: Packet '%s'", buf
);
2849 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2850 &text_off
, &data_off
, &bss_off
)
2852 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2853 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2857 case 'W': /* Target exited */
2859 /* The remote process exited. */
2860 status
->kind
= TARGET_WAITKIND_EXITED
;
2861 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2865 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2866 status
->value
.sig
= (enum target_signal
)
2867 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2871 case 'O': /* Console output */
2872 remote_console_output (buf
+ 1);
2873 /* Return immediately to the event loop. The event loop will
2874 still be waiting on the inferior afterwards. */
2875 status
->kind
= TARGET_WAITKIND_IGNORE
;
2878 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2880 /* Zero length reply means that we tried 'S' or 'C' and
2881 the remote system doesn't support it. */
2882 target_terminal_ours_for_output ();
2884 ("Can't send signals to this remote system. %s not sent.\n",
2885 target_signal_to_name (last_sent_signal
));
2886 last_sent_signal
= TARGET_SIGNAL_0
;
2887 target_terminal_inferior ();
2889 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2890 putpkt ((char *) buf
);
2893 /* else fallthrough */
2895 warning ("Invalid remote reply: %s", buf
);
2900 if (thread_num
!= -1)
2904 return inferior_pid
;
2907 /* Number of bytes of registers this stub implements. */
2909 static int register_bytes_found
;
2911 /* Read the remote registers into the block REGS. */
2912 /* Currently we just read all the registers, so we don't use regno. */
2916 remote_fetch_registers (int regno
)
2918 char *buf
= alloca (PBUFSIZ
);
2921 char regs
[REGISTER_BYTES
];
2923 set_thread (inferior_pid
, 1);
2926 remote_send (buf
, PBUFSIZ
);
2928 /* Save the size of the packet sent to us by the target. Its used
2929 as a heuristic when determining the max size of packets that the
2930 target can safely receive. */
2931 if (actual_register_packet_size
== 0)
2932 actual_register_packet_size
= strlen (buf
);
2934 /* Unimplemented registers read as all bits zero. */
2935 memset (regs
, 0, REGISTER_BYTES
);
2937 /* We can get out of synch in various cases. If the first character
2938 in the buffer is not a hex character, assume that has happened
2939 and try to fetch another packet to read. */
2940 while ((buf
[0] < '0' || buf
[0] > '9')
2941 && (buf
[0] < 'a' || buf
[0] > 'f')
2942 && buf
[0] != 'x') /* New: unavailable register value */
2945 fprintf_unfiltered (gdb_stdlog
,
2946 "Bad register packet; fetching a new packet\n");
2947 getpkt (buf
, PBUFSIZ
, 0);
2950 /* Reply describes registers byte by byte, each byte encoded as two
2951 hex characters. Suck them all up, then supply them to the
2952 register cacheing/storage mechanism. */
2955 for (i
= 0; i
< REGISTER_BYTES
; i
++)
2961 warning ("Remote reply is of odd length: %s", buf
);
2962 /* Don't change register_bytes_found in this case, and don't
2963 print a second warning. */
2966 if (p
[0] == 'x' && p
[1] == 'x')
2967 regs
[i
] = 0; /* 'x' */
2969 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2973 if (i
!= register_bytes_found
)
2975 register_bytes_found
= i
;
2976 #ifdef REGISTER_BYTES_OK
2977 if (!REGISTER_BYTES_OK (i
))
2978 warning ("Remote reply is too short: %s", buf
);
2983 for (i
= 0; i
< NUM_REGS
; i
++)
2985 supply_register (i
, ®s
[REGISTER_BYTE (i
)]);
2986 if (buf
[REGISTER_BYTE (i
) * 2] == 'x')
2987 register_valid
[i
] = -1; /* register value not available */
2991 /* Prepare to store registers. Since we may send them all (using a
2992 'G' request), we have to read out the ones we don't want to change
2996 remote_prepare_to_store (void)
2998 /* Make sure the entire registers array is valid. */
2999 switch (remote_protocol_P
.support
)
3001 case PACKET_DISABLE
:
3002 case PACKET_SUPPORT_UNKNOWN
:
3003 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
);
3010 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
3011 packet was not recognized. */
3014 store_register_using_P (int regno
)
3016 /* Try storing a single register. */
3017 char *buf
= alloca (PBUFSIZ
);
3022 sprintf (buf
, "P%x=", regno
);
3023 p
= buf
+ strlen (buf
);
3024 regp
= ®isters
[REGISTER_BYTE (regno
)];
3025 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
3027 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
3028 *p
++ = tohex (regp
[i
] & 0xf);
3031 remote_send (buf
, PBUFSIZ
);
3033 return buf
[0] != '\0';
3037 /* Store register REGNO, or all registers if REGNO == -1, from the contents
3038 of REGISTERS. FIXME: ignores errors. */
3041 remote_store_registers (int regno
)
3043 char *buf
= alloca (PBUFSIZ
);
3047 set_thread (inferior_pid
, 1);
3051 switch (remote_protocol_P
.support
)
3053 case PACKET_DISABLE
:
3056 if (store_register_using_P (regno
))
3059 error ("Protocol error: P packet not recognized by stub");
3060 case PACKET_SUPPORT_UNKNOWN
:
3061 if (store_register_using_P (regno
))
3063 /* The stub recognized the 'P' packet. Remember this. */
3064 remote_protocol_P
.support
= PACKET_ENABLE
;
3069 /* The stub does not support the 'P' packet. Use 'G'
3070 instead, and don't try using 'P' in the future (it
3071 will just waste our time). */
3072 remote_protocol_P
.support
= PACKET_DISABLE
;
3080 /* Command describes registers byte by byte,
3081 each byte encoded as two hex characters. */
3084 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3085 for (i
= 0; i
< register_bytes_found
; i
++)
3087 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
3088 *p
++ = tohex (registers
[i
] & 0xf);
3092 remote_send (buf
, PBUFSIZ
);
3096 /* Return the number of hex digits in num. */
3099 hexnumlen (ULONGEST num
)
3103 for (i
= 0; num
!= 0; i
++)
3109 /* Set BUF to the minimum number of hex digits representing NUM. */
3112 hexnumstr (char *buf
, ULONGEST num
)
3114 int len
= hexnumlen (num
);
3115 return hexnumnstr (buf
, num
, len
);
3119 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3122 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3128 for (i
= width
- 1; i
>= 0; i
--)
3130 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3137 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3140 remote_address_masked (CORE_ADDR addr
)
3142 if (remote_address_size
> 0
3143 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3145 /* Only create a mask when that mask can safely be constructed
3146 in a ULONGEST variable. */
3148 mask
= (mask
<< remote_address_size
) - 1;
3154 /* Determine whether the remote target supports binary downloading.
3155 This is accomplished by sending a no-op memory write of zero length
3156 to the target at the specified address. It does not suffice to send
3157 the whole packet, since many stubs strip the eighth bit and subsequently
3158 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3160 NOTE: This can still lose if the serial line is not eight-bit
3161 clean. In cases like this, the user should clear "remote
3165 check_binary_download (CORE_ADDR addr
)
3167 switch (remote_protocol_binary_download
.support
)
3169 case PACKET_DISABLE
:
3173 case PACKET_SUPPORT_UNKNOWN
:
3175 char *buf
= alloca (PBUFSIZ
);
3180 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3182 p
+= hexnumstr (p
, (ULONGEST
) 0);
3186 putpkt_binary (buf
, (int) (p
- buf
));
3187 getpkt (buf
, PBUFSIZ
, 0);
3192 fprintf_unfiltered (gdb_stdlog
,
3193 "binary downloading NOT suppported by target\n");
3194 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3199 fprintf_unfiltered (gdb_stdlog
,
3200 "binary downloading suppported by target\n");
3201 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3208 /* Write memory data directly to the remote machine.
3209 This does not inform the data cache; the data cache uses this.
3210 MEMADDR is the address in the remote memory space.
3211 MYADDR is the address of the buffer in our space.
3212 LEN is the number of bytes.
3214 Returns number of bytes transferred, or 0 (setting errno) for
3215 error. Only transfer a single packet. */
3218 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3221 int max_buf_size
; /* Max size of packet output buffer */
3223 unsigned char *plen
;
3229 /* Verify that the target can support a binary download */
3230 check_binary_download (memaddr
);
3232 /* Determine the max packet size. */
3233 max_buf_size
= get_memory_write_packet_size ();
3234 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3235 buf
= alloca (sizeof_buf
);
3237 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3238 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3240 /* construct "M"<memaddr>","<len>":" */
3241 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3244 /* Append [XM]. Compute a best guess of the number of bytes
3245 actually transfered. */
3246 switch (remote_protocol_binary_download
.support
)
3250 /* Best guess at number of bytes that will fit. */
3251 todo
= min (len
, max_buf_size
);
3253 case PACKET_DISABLE
:
3255 /* num bytes that will fit */
3256 todo
= min (len
, max_buf_size
/ 2);
3258 case PACKET_SUPPORT_UNKNOWN
:
3259 internal_error ("remote_write_bytes: bad switch");
3262 /* Append <memaddr> */
3263 memaddr
= remote_address_masked (memaddr
);
3264 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3267 /* Append <len>. Retain the location/size of <len>. It may
3268 need to be adjusted once the packet body has been created. */
3270 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3275 /* Append the packet body. */
3276 switch (remote_protocol_binary_download
.support
)
3279 /* Binary mode. Send target system values byte by byte, in
3280 increasing byte addresses. Only escape certain critical
3283 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3286 switch (myaddr
[nr_bytes
] & 0xff)
3291 /* These must be escaped */
3293 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3296 *p
++ = myaddr
[nr_bytes
] & 0xff;
3300 if (nr_bytes
< todo
)
3302 /* Escape chars have filled up the buffer prematurely,
3303 and we have actually sent fewer bytes than planned.
3304 Fix-up the length field of the packet. Use the same
3305 number of characters as before. */
3307 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3308 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3311 case PACKET_DISABLE
:
3312 /* Normal mode: Send target system values byte by byte, in
3313 increasing byte addresses. Each byte is encoded as a two hex
3315 for (nr_bytes
= 0; nr_bytes
< todo
; nr_bytes
++)
3317 *p
++ = tohex ((myaddr
[nr_bytes
] >> 4) & 0xf);
3318 *p
++ = tohex (myaddr
[nr_bytes
] & 0xf);
3322 case PACKET_SUPPORT_UNKNOWN
:
3323 internal_error ("remote_write_bytes: bad switch");
3326 putpkt_binary (buf
, (int) (p
- buf
));
3327 getpkt (buf
, sizeof_buf
, 0);
3331 /* There is no correspondance between what the remote protocol
3332 uses for errors and errno codes. We would like a cleaner way
3333 of representing errors (big enough to include errno codes,
3334 bfd_error codes, and others). But for now just return EIO. */
3339 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3340 bytes than we'd planned. */
3344 /* Read memory data directly from the remote machine.
3345 This does not use the data cache; the data cache uses this.
3346 MEMADDR is the address in the remote memory space.
3347 MYADDR is the address of the buffer in our space.
3348 LEN is the number of bytes.
3350 Returns number of bytes transferred, or 0 for error. */
3352 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3353 remote targets) shouldn't attempt to read the entire buffer.
3354 Instead it should read a single packet worth of data and then
3355 return the byte size of that packet to the caller. The caller (its
3356 caller and its callers caller ;-) already contains code for
3357 handling partial reads. */
3360 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3363 int max_buf_size
; /* Max size of packet output buffer */
3367 /* Create a buffer big enough for this packet. */
3368 max_buf_size
= get_memory_read_packet_size ();
3369 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3370 buf
= alloca (sizeof_buf
);
3379 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3381 /* construct "m"<memaddr>","<len>" */
3382 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3383 memaddr
= remote_address_masked (memaddr
);
3386 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3388 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3392 getpkt (buf
, sizeof_buf
, 0);
3396 /* There is no correspondance between what the remote protocol uses
3397 for errors and errno codes. We would like a cleaner way of
3398 representing errors (big enough to include errno codes, bfd_error
3399 codes, and others). But for now just return EIO. */
3404 /* Reply describes memory byte by byte,
3405 each byte encoded as two hex characters. */
3408 for (i
= 0; i
< todo
; i
++)
3410 if (p
[0] == 0 || p
[1] == 0)
3411 /* Reply is short. This means that we were able to read
3412 only part of what we wanted to. */
3413 return i
+ (origlen
- len
);
3414 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3424 /* Read or write LEN bytes from inferior memory at MEMADDR,
3425 transferring to or from debugger address BUFFER. Write to inferior if
3426 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3431 remote_xfer_memory (mem_addr
, buffer
, mem_len
, should_write
, target
)
3436 struct target_ops
*target
; /* ignored */
3438 CORE_ADDR targ_addr
;
3440 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3444 return dcache_xfer_memory (remote_dcache
, targ_addr
, buffer
,
3445 targ_len
, should_write
);
3450 /* Enable after 4.12. */
3453 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
3454 addr_found
, data_found
)
3458 CORE_ADDR startaddr
;
3462 CORE_ADDR
*addr_found
;
3465 if (increment
== -4 && len
== 4)
3467 long mask_long
, data_long
;
3468 long data_found_long
;
3469 CORE_ADDR addr_we_found
;
3470 char *buf
= alloca (PBUFSIZ
);
3471 long returned_long
[2];
3474 mask_long
= extract_unsigned_integer (mask
, len
);
3475 data_long
= extract_unsigned_integer (data
, len
);
3476 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
3478 getpkt (buf
, PBUFSIZ
, 0);
3481 /* The stub doesn't support the 't' request. We might want to
3482 remember this fact, but on the other hand the stub could be
3483 switched on us. Maybe we should remember it only until
3484 the next "target remote". */
3485 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3486 hirange
, addr_found
, data_found
);
3491 /* There is no correspondance between what the remote protocol uses
3492 for errors and errno codes. We would like a cleaner way of
3493 representing errors (big enough to include errno codes, bfd_error
3494 codes, and others). But for now just use EIO. */
3495 memory_error (EIO
, startaddr
);
3498 while (*p
!= '\0' && *p
!= ',')
3499 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
3501 error ("Protocol error: short return for search");
3503 data_found_long
= 0;
3504 while (*p
!= '\0' && *p
!= ',')
3505 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
3506 /* Ignore anything after this comma, for future extensions. */
3508 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
3514 *addr_found
= addr_we_found
;
3515 *data_found
= store_unsigned_integer (data_we_found
, len
);
3518 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3519 hirange
, addr_found
, data_found
);
3524 remote_files_info (struct target_ops
*ignore
)
3526 puts_filtered ("Debugging a target over a serial line.\n");
3529 /* Stuff for dealing with the packets which are part of this protocol.
3530 See comment at top of file for details. */
3532 /* Read a single character from the remote end, masking it down to 7 bits. */
3535 readchar (int timeout
)
3539 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
3544 switch ((enum serial_rc
) ch
)
3547 target_mourn_inferior ();
3548 error ("Remote connection closed");
3551 perror_with_name ("Remote communication error");
3553 case SERIAL_TIMEOUT
:
3559 /* Send the command in BUF to the remote machine, and read the reply
3560 into BUF. Report an error if we get an error reply. */
3563 remote_send (char *buf
,
3567 getpkt (buf
, sizeof_buf
, 0);
3570 error ("Remote failure reply: %s", buf
);
3573 /* Display a null-terminated packet on stdout, for debugging, using C
3577 print_packet (char *buf
)
3579 puts_filtered ("\"");
3580 fputstr_filtered (buf
, '"', gdb_stdout
);
3581 puts_filtered ("\"");
3587 return putpkt_binary (buf
, strlen (buf
));
3590 /* Send a packet to the remote machine, with error checking. The data
3591 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3592 to account for the $, # and checksum, and for a possible /0 if we are
3593 debugging (remote_debug) and want to print the sent packet as a string */
3596 putpkt_binary (char *buf
, int cnt
)
3599 unsigned char csum
= 0;
3600 char *buf2
= alloca (cnt
+ 6);
3601 long sizeof_junkbuf
= PBUFSIZ
;
3602 char *junkbuf
= alloca (sizeof_junkbuf
);
3608 /* Copy the packet into buffer BUF2, encapsulating it
3609 and giving it a checksum. */
3614 for (i
= 0; i
< cnt
; i
++)
3620 *p
++ = tohex ((csum
>> 4) & 0xf);
3621 *p
++ = tohex (csum
& 0xf);
3623 /* Send it over and over until we get a positive ack. */
3627 int started_error_output
= 0;
3632 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
3633 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
3634 fprintf_unfiltered (gdb_stdlog
, "...");
3635 gdb_flush (gdb_stdlog
);
3637 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
3638 perror_with_name ("putpkt: write failed");
3640 /* read until either a timeout occurs (-2) or '+' is read */
3643 ch
= readchar (remote_timeout
);
3651 case SERIAL_TIMEOUT
:
3653 if (started_error_output
)
3655 putchar_unfiltered ('\n');
3656 started_error_output
= 0;
3665 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
3669 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
3670 case SERIAL_TIMEOUT
:
3674 break; /* Retransmit buffer */
3677 /* It's probably an old response, and we're out of sync.
3678 Just gobble up the packet and ignore it. */
3679 getpkt (junkbuf
, sizeof_junkbuf
, 0);
3680 continue; /* Now, go look for + */
3685 if (!started_error_output
)
3687 started_error_output
= 1;
3688 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
3690 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
3694 break; /* Here to retransmit */
3698 /* This is wrong. If doing a long backtrace, the user should be
3699 able to get out next time we call QUIT, without anything as
3700 violent as interrupt_query. If we want to provide a way out of
3701 here without getting to the next QUIT, it should be based on
3702 hitting ^C twice as in remote_wait. */
3712 static int remote_cisco_mode
;
3714 /* Come here after finding the start of the frame. Collect the rest
3715 into BUF, verifying the checksum, length, and handling run-length
3716 compression. No more than sizeof_buf-1 characters are read so that
3717 the buffer can be NUL terminated.
3719 Returns -1 on error, number of characters in buffer (ignoring the
3720 trailing NULL) on success. (could be extended to return one of the
3721 SERIAL status indications). */
3724 read_frame (char *buf
,
3736 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
3737 c
= readchar (remote_timeout
);
3740 case SERIAL_TIMEOUT
:
3742 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
3746 fputs_filtered ("Saw new packet start in middle of old one\n",
3748 return -1; /* Start a new packet, count retries */
3751 unsigned char pktcsum
;
3755 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
3756 pktcsum
|= fromhex (readchar (remote_timeout
));
3758 if (csum
== pktcsum
)
3763 fprintf_filtered (gdb_stdlog
,
3764 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3766 fputs_filtered (buf
, gdb_stdlog
);
3767 fputs_filtered ("\n", gdb_stdlog
);
3769 /* Number of characters in buffer ignoring trailing
3773 case '*': /* Run length encoding */
3778 if (remote_cisco_mode
== 0)
3780 c
= readchar (remote_timeout
);
3782 repeat
= c
- ' ' + 3; /* Compute repeat count */
3786 /* Cisco's run-length encoding variant uses two
3787 hex chars to represent the repeat count. */
3789 c
= readchar (remote_timeout
);
3791 repeat
= fromhex (c
) << 4;
3792 c
= readchar (remote_timeout
);
3794 repeat
+= fromhex (c
);
3797 /* The character before ``*'' is repeated. */
3799 if (repeat
> 0 && repeat
<= 255
3801 && bc
+ repeat
< sizeof_buf
- 1)
3803 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
3809 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
3810 puts_filtered (buf
);
3811 puts_filtered ("\n");
3815 if (bc
< sizeof_buf
- 1)
3823 puts_filtered ("Remote packet too long: ");
3824 puts_filtered (buf
);
3825 puts_filtered ("\n");
3832 /* Read a packet from the remote machine, with error checking, and
3833 store it in BUF. If FOREVER, wait forever rather than timing out;
3834 this is used (in synchronous mode) to wait for a target that is is
3835 executing user code to stop. */
3836 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
3837 don't have to change all the calls to getpkt to deal with the
3838 return value, because at the moment I don't know what the right
3839 thing to do it for those. */
3847 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
3851 /* Read a packet from the remote machine, with error checking, and
3852 store it in BUF. If FOREVER, wait forever rather than timing out;
3853 this is used (in synchronous mode) to wait for a target that is is
3854 executing user code to stop. If FOREVER == 0, this function is
3855 allowed to time out gracefully and return an indication of this to
3858 getpkt_sane (char *buf
,
3867 strcpy (buf
, "timeout");
3871 timeout
= watchdog
> 0 ? watchdog
: -1;
3875 timeout
= remote_timeout
;
3879 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
3881 /* This can loop forever if the remote side sends us characters
3882 continuously, but if it pauses, we'll get a zero from readchar
3883 because of timeout. Then we'll count that as a retry. */
3885 /* Note that we will only wait forever prior to the start of a packet.
3886 After that, we expect characters to arrive at a brisk pace. They
3887 should show up within remote_timeout intervals. */
3891 c
= readchar (timeout
);
3893 if (c
== SERIAL_TIMEOUT
)
3895 if (forever
) /* Watchdog went off? Kill the target. */
3898 target_mourn_inferior ();
3899 error ("Watchdog has expired. Target detached.\n");
3902 fputs_filtered ("Timed out.\n", gdb_stdlog
);
3908 /* We've found the start of a packet, now collect the data. */
3910 val
= read_frame (buf
, sizeof_buf
);
3916 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
3917 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
3918 fprintf_unfiltered (gdb_stdlog
, "\n");
3920 SERIAL_WRITE (remote_desc
, "+", 1);
3924 /* Try the whole thing again. */
3926 SERIAL_WRITE (remote_desc
, "-", 1);
3929 /* We have tried hard enough, and just can't receive the packet. Give up. */
3931 printf_unfiltered ("Ignoring packet error, continuing...\n");
3932 SERIAL_WRITE (remote_desc
, "+", 1);
3939 /* For some mysterious reason, wait_for_inferior calls kill instead of
3940 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3944 target_mourn_inferior ();
3948 /* Use catch_errors so the user can quit from gdb even when we aren't on
3949 speaking terms with the remote system. */
3950 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
3952 /* Don't wait for it to die. I'm not really sure it matters whether
3953 we do or not. For the existing stubs, kill is a noop. */
3954 target_mourn_inferior ();
3957 /* Async version of remote_kill. */
3959 remote_async_kill (void)
3961 /* Unregister the file descriptor from the event loop. */
3962 if (target_is_async_p ())
3963 SERIAL_ASYNC (remote_desc
, NULL
, 0);
3965 /* For some mysterious reason, wait_for_inferior calls kill instead of
3966 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3970 target_mourn_inferior ();
3974 /* Use catch_errors so the user can quit from gdb even when we aren't on
3975 speaking terms with the remote system. */
3976 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
3978 /* Don't wait for it to die. I'm not really sure it matters whether
3979 we do or not. For the existing stubs, kill is a noop. */
3980 target_mourn_inferior ();
3986 remote_mourn_1 (&remote_ops
);
3990 remote_async_mourn (void)
3992 remote_mourn_1 (&remote_async_ops
);
3996 extended_remote_mourn (void)
3998 /* We do _not_ want to mourn the target like this; this will
3999 remove the extended remote target from the target stack,
4000 and the next time the user says "run" it'll fail.
4002 FIXME: What is the right thing to do here? */
4004 remote_mourn_1 (&extended_remote_ops
);
4008 /* Worker function for remote_mourn. */
4010 remote_mourn_1 (struct target_ops
*target
)
4012 unpush_target (target
);
4013 generic_mourn_inferior ();
4016 /* In the extended protocol we want to be able to do things like
4017 "run" and have them basically work as expected. So we need
4018 a special create_inferior function.
4020 FIXME: One day add support for changing the exec file
4021 we're debugging, arguments and an environment. */
4024 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4026 /* Rip out the breakpoints; we'll reinsert them after restarting
4027 the remote server. */
4028 remove_breakpoints ();
4030 /* Now restart the remote server. */
4031 extended_remote_restart ();
4033 /* Now put the breakpoints back in. This way we're safe if the
4034 restart function works via a unix fork on the remote side. */
4035 insert_breakpoints ();
4037 /* Clean up from the last time we were running. */
4038 clear_proceed_status ();
4040 /* Let the remote process run. */
4041 proceed (-1, TARGET_SIGNAL_0
, 0);
4044 /* Async version of extended_remote_create_inferior. */
4046 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4048 /* Rip out the breakpoints; we'll reinsert them after restarting
4049 the remote server. */
4050 remove_breakpoints ();
4052 /* If running asynchronously, register the target file descriptor
4053 with the event loop. */
4054 if (event_loop_p
&& target_can_async_p ())
4055 target_async (inferior_event_handler
, 0);
4057 /* Now restart the remote server. */
4058 extended_remote_restart ();
4060 /* Now put the breakpoints back in. This way we're safe if the
4061 restart function works via a unix fork on the remote side. */
4062 insert_breakpoints ();
4064 /* Clean up from the last time we were running. */
4065 clear_proceed_status ();
4067 /* Let the remote process run. */
4068 proceed (-1, TARGET_SIGNAL_0
, 0);
4072 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4073 than other targets; in those use REMOTE_BREAKPOINT instead of just
4074 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4075 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4076 the standard routines that are in mem-break.c. */
4078 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4079 the choice of breakpoint instruction affects target program design and
4080 vice versa, and by making it user-tweakable, the special code here
4081 goes away and we need fewer special GDB configurations. */
4083 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4084 #define REMOTE_BREAKPOINT
4087 #ifdef REMOTE_BREAKPOINT
4089 /* If the target isn't bi-endian, just pretend it is. */
4090 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4091 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4092 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4095 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
4096 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
4098 #endif /* REMOTE_BREAKPOINT */
4100 /* Insert a breakpoint on targets that don't have any better breakpoint
4101 support. We read the contents of the target location and stash it,
4102 then overwrite it with a breakpoint instruction. ADDR is the target
4103 location in the target machine. CONTENTS_CACHE is a pointer to
4104 memory allocated for saving the target contents. It is guaranteed
4105 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4106 is accomplished via BREAKPOINT_MAX). */
4109 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4111 #ifdef REMOTE_BREAKPOINT
4116 /* Try the "Z" packet if it is not already disabled.
4117 If it succeeds, then set the support to PACKET_ENABLE.
4118 If it fails, and the user has explicitly requested the Z support
4119 then report an error, otherwise, mark it disabled and go on. */
4121 if ((remote_protocol_Z
.support
== PACKET_ENABLE
)
4122 || (remote_protocol_Z
.support
== PACKET_SUPPORT_UNKNOWN
))
4124 char *buf
= alloca (PBUFSIZ
);
4127 addr
= remote_address_masked (addr
);
4131 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4132 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4133 sprintf (p
, ",%d", bp_size
);
4136 getpkt (buf
, PBUFSIZ
, 0);
4140 remote_protocol_Z
.support
= PACKET_ENABLE
;
4141 return (buf
[0] == 'E');
4144 /* The stub does not support the 'Z' request. If the user has
4145 explicitly requested the Z support, or if the stub previously
4146 said it supported the packet, this is an error,
4147 otherwise, mark it disabled. */
4149 else if (remote_protocol_Z
.support
== PACKET_ENABLE
)
4151 error ("Protocol error: Z packet not recognized by stub");
4155 remote_protocol_Z
.support
= PACKET_DISABLE
;
4159 #ifdef REMOTE_BREAKPOINT
4160 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4164 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
4165 val
= target_write_memory (addr
, (char *) big_break_insn
,
4166 sizeof big_break_insn
);
4168 val
= target_write_memory (addr
, (char *) little_break_insn
,
4169 sizeof little_break_insn
);
4174 return memory_insert_breakpoint (addr
, contents_cache
);
4175 #endif /* REMOTE_BREAKPOINT */
4179 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4183 if ((remote_protocol_Z
.support
== PACKET_ENABLE
)
4184 || (remote_protocol_Z
.support
== PACKET_SUPPORT_UNKNOWN
))
4186 char *buf
= alloca (PBUFSIZ
);
4193 addr
= remote_address_masked (addr
);
4194 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4195 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4196 sprintf (p
, ",%d", bp_size
);
4199 getpkt (buf
, PBUFSIZ
, 0);
4201 return (buf
[0] == 'E');
4204 #ifdef REMOTE_BREAKPOINT
4205 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4207 return memory_remove_breakpoint (addr
, contents_cache
);
4208 #endif /* REMOTE_BREAKPOINT */
4211 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
4213 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4215 char *buf
= alloca (PBUFSIZ
);
4218 if (remote_protocol_Z
.support
== PACKET_DISABLE
)
4219 error ("Can't set hardware watchpoints without the 'Z' packet\n");
4221 sprintf (buf
, "Z%x,", type
+ 2 );
4222 p
= strchr (buf
, '\0');
4223 addr
= remote_address_masked (addr
);
4224 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4225 sprintf (p
, ",%x", len
);
4228 getpkt (buf
, PBUFSIZ
, 0);
4230 if (buf
[0] == '\0' || buf
[0] == 'E')
4237 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4239 char *buf
= alloca (PBUFSIZ
);
4242 sprintf (buf
, "z%x,", type
+ 2 );
4243 p
= strchr (buf
, '\0');
4244 addr
= remote_address_masked (addr
);
4245 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4246 sprintf (p
, ",%x", len
);
4248 getpkt (buf
, PBUFSIZ
, 0);
4250 if (buf
[0] == '\0' || buf
[0] == 'E')
4257 remote_insert_hw_breakpoint (CORE_ADDR addr
, int len
)
4259 char *buf
= alloca (PBUFSIZ
);
4262 if (remote_protocol_Z
.support
== PACKET_DISABLE
)
4263 error ("Can't set hardware breakpoints without the 'Z' packet\n");
4269 addr
= remote_address_masked (addr
);
4270 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4274 getpkt (buf
, PBUFSIZ
, 0);
4276 if (buf
[0] == '\0' || buf
[0] == 'E')
4283 remote_remove_hw_breakpoint (CORE_ADDR addr
, int len
)
4285 char *buf
= alloca (PBUFSIZ
);
4292 addr
= remote_address_masked (addr
);
4293 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4297 getpkt (buf
, PBUFSIZ
, 0);
4299 if (buf
[0] == '\0' || buf
[0] == 'E')
4306 /* Some targets are only capable of doing downloads, and afterwards
4307 they switch to the remote serial protocol. This function provides
4308 a clean way to get from the download target to the remote target.
4309 It's basically just a wrapper so that we don't have to expose any
4310 of the internal workings of remote.c.
4312 Prior to calling this routine, you should shutdown the current
4313 target code, else you will get the "A program is being debugged
4314 already..." message. Usually a call to pop_target() suffices. */
4317 push_remote_target (char *name
, int from_tty
)
4319 printf_filtered ("Switching to remote protocol\n");
4320 remote_open (name
, from_tty
);
4323 /* Other targets want to use the entire remote serial module but with
4324 certain remote_ops overridden. */
4327 open_remote_target (char *name
, int from_tty
, struct target_ops
*target
,
4330 printf_filtered ("Selecting the %sremote protocol\n",
4331 (extended_p
? "extended-" : ""));
4332 remote_open_1 (name
, from_tty
, target
, extended_p
);
4335 /* Table used by the crc32 function to calcuate the checksum. */
4337 static unsigned long crc32_table
[256] =
4340 static unsigned long
4341 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4343 if (!crc32_table
[1])
4345 /* Initialize the CRC table and the decoding table. */
4349 for (i
= 0; i
< 256; i
++)
4351 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4352 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4359 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4365 /* compare-sections command
4367 With no arguments, compares each loadable section in the exec bfd
4368 with the same memory range on the target, and reports mismatches.
4369 Useful for verifying the image on the target against the exec file.
4370 Depends on the target understanding the new "qCRC:" request. */
4372 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4373 target method (target verify memory) and generic version of the
4374 actual command. This will allow other high-level code (especially
4375 generic_load()) to make use of this target functionality. */
4378 compare_sections_command (char *args
, int from_tty
)
4381 unsigned long host_crc
, target_crc
;
4382 extern bfd
*exec_bfd
;
4383 struct cleanup
*old_chain
;
4387 char *buf
= alloca (PBUFSIZ
);
4394 error ("command cannot be used without an exec file");
4395 if (!current_target
.to_shortname
||
4396 strcmp (current_target
.to_shortname
, "remote") != 0)
4397 error ("command can only be used with remote target");
4399 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4401 if (!(s
->flags
& SEC_LOAD
))
4402 continue; /* skip non-loadable section */
4404 size
= bfd_get_section_size_before_reloc (s
);
4406 continue; /* skip zero-length section */
4408 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
4409 if (args
&& strcmp (args
, sectname
) != 0)
4410 continue; /* not the section selected by user */
4412 matched
= 1; /* do this section */
4414 /* FIXME: assumes lma can fit into long */
4415 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
4418 /* be clever; compute the host_crc before waiting for target reply */
4419 sectdata
= xmalloc (size
);
4420 old_chain
= make_cleanup (free
, sectdata
);
4421 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4422 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4424 getpkt (buf
, PBUFSIZ
, 0);
4426 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4427 sectname
, lma
, lma
+ size
);
4429 error ("remote target does not support this operation");
4431 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4432 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4434 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4435 sectname
, paddr (lma
), paddr (lma
+ size
));
4436 if (host_crc
== target_crc
)
4437 printf_filtered ("matched.\n");
4440 printf_filtered ("MIS-MATCHED!\n");
4444 do_cleanups (old_chain
);
4447 warning ("One or more sections of the remote executable does not match\n\
4448 the loaded file\n");
4449 if (args
&& !matched
)
4450 printf_filtered ("No loaded section named '%s'.\n", args
);
4454 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
4457 char *buf2
= alloca (PBUFSIZ
);
4458 char *p2
= &buf2
[0];
4461 error ("null pointer to remote bufer size specified");
4463 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4464 the caller know and return what the minimum size is */
4465 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4466 if (*bufsiz
< PBUFSIZ
)
4472 /* except for querying the minimum buffer size, target must be open */
4474 error ("remote query is only available after target open");
4476 /* we only take uppercase letters as query types, at least for now */
4477 if ((query_type
< 'A') || (query_type
> 'Z'))
4478 error ("invalid remote query type");
4481 error ("null remote query specified");
4484 error ("remote query requires a buffer to receive data");
4491 /* we used one buffer char for the remote protocol q command and another
4492 for the query type. As the remote protocol encapsulation uses 4 chars
4493 plus one extra in case we are debugging (remote_debug),
4494 we have PBUFZIZ - 7 left to pack the query string */
4496 while (buf
[i
] && (i
< (PBUFSIZ
- 8)))
4498 /* bad caller may have sent forbidden characters */
4499 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
4500 error ("illegal characters in query string");
4508 error ("query larger than available buffer");
4514 getpkt (outbuf
, *bufsiz
, 0);
4520 remote_rcmd (char *command
,
4521 struct ui_file
*outbuf
)
4524 char *buf
= alloca (PBUFSIZ
);
4528 error ("remote rcmd is only available after target open");
4530 /* Send a NULL command across as an empty command */
4531 if (command
== NULL
)
4534 /* The query prefix */
4535 strcpy (buf
, "qRcmd,");
4536 p
= strchr (buf
, '\0');
4538 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > PBUFSIZ
)
4539 error ("\"monitor\" command ``%s'' is too long\n", command
);
4541 /* Encode the actual command */
4542 for (i
= 0; command
[i
]; i
++)
4544 *p
++ = tohex ((command
[i
] >> 4) & 0xf);
4545 *p
++ = tohex (command
[i
] & 0xf);
4549 if (putpkt (buf
) < 0)
4550 error ("Communication problem with target\n");
4552 /* get/display the response */
4555 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4557 getpkt (buf
, PBUFSIZ
, 0);
4559 error ("Target does not support this command\n");
4560 if (buf
[0] == 'O' && buf
[1] != 'K')
4562 remote_console_output (buf
+ 1); /* 'O' message from stub */
4565 if (strcmp (buf
, "OK") == 0)
4567 if (strlen (buf
) == 3 && buf
[0] == 'E'
4568 && isdigit (buf
[1]) && isdigit (buf
[2]))
4570 error ("Protocol error with Rcmd");
4572 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
4574 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
4575 fputc_unfiltered (c
, outbuf
);
4582 packet_command (char *args
, int from_tty
)
4584 char *buf
= alloca (PBUFSIZ
);
4587 error ("command can only be used with remote target");
4590 error ("remote-packet command requires packet text as argument");
4592 puts_filtered ("sending: ");
4593 print_packet (args
);
4594 puts_filtered ("\n");
4597 getpkt (buf
, PBUFSIZ
, 0);
4598 puts_filtered ("received: ");
4600 puts_filtered ("\n");
4604 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4606 static void display_thread_info (struct gdb_ext_thread_info
*info
);
4608 static void threadset_test_cmd (char *cmd
, int tty
);
4610 static void threadalive_test (char *cmd
, int tty
);
4612 static void threadlist_test_cmd (char *cmd
, int tty
);
4614 int get_and_display_threadinfo (threadref
* ref
);
4616 static void threadinfo_test_cmd (char *cmd
, int tty
);
4618 static int thread_display_step (threadref
* ref
, void *context
);
4620 static void threadlist_update_test_cmd (char *cmd
, int tty
);
4622 static void init_remote_threadtests (void);
4624 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4627 threadset_test_cmd (char *cmd
, int tty
)
4629 int sample_thread
= SAMPLE_THREAD
;
4631 printf_filtered ("Remote threadset test\n");
4632 set_thread (sample_thread
, 1);
4637 threadalive_test (char *cmd
, int tty
)
4639 int sample_thread
= SAMPLE_THREAD
;
4641 if (remote_thread_alive (sample_thread
))
4642 printf_filtered ("PASS: Thread alive test\n");
4644 printf_filtered ("FAIL: Thread alive test\n");
4647 void output_threadid (char *title
, threadref
* ref
);
4650 output_threadid (char *title
, threadref
*ref
)
4654 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
4656 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
4660 threadlist_test_cmd (char *cmd
, int tty
)
4663 threadref nextthread
;
4664 int done
, result_count
;
4665 threadref threadlist
[3];
4667 printf_filtered ("Remote Threadlist test\n");
4668 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
4669 &result_count
, &threadlist
[0]))
4670 printf_filtered ("FAIL: threadlist test\n");
4673 threadref
*scan
= threadlist
;
4674 threadref
*limit
= scan
+ result_count
;
4676 while (scan
< limit
)
4677 output_threadid (" thread ", scan
++);
4682 display_thread_info (struct gdb_ext_thread_info
*info
)
4684 output_threadid ("Threadid: ", &info
->threadid
);
4685 printf_filtered ("Name: %s\n ", info
->shortname
);
4686 printf_filtered ("State: %s\n", info
->display
);
4687 printf_filtered ("other: %s\n\n", info
->more_display
);
4691 get_and_display_threadinfo (threadref
*ref
)
4695 struct gdb_ext_thread_info threadinfo
;
4697 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
4698 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
4699 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
4700 display_thread_info (&threadinfo
);
4705 threadinfo_test_cmd (char *cmd
, int tty
)
4707 int athread
= SAMPLE_THREAD
;
4711 int_to_threadref (&thread
, athread
);
4712 printf_filtered ("Remote Threadinfo test\n");
4713 if (!get_and_display_threadinfo (&thread
))
4714 printf_filtered ("FAIL cannot get thread info\n");
4718 thread_display_step (threadref
*ref
, void *context
)
4720 /* output_threadid(" threadstep ",ref); *//* simple test */
4721 return get_and_display_threadinfo (ref
);
4725 threadlist_update_test_cmd (char *cmd
, int tty
)
4727 printf_filtered ("Remote Threadlist update test\n");
4728 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
4732 init_remote_threadtests (void)
4734 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
4735 "Fetch and print the remote list of thread identifiers, one pkt only");
4736 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
4737 "Fetch and display info about one thread");
4738 add_com ("tset", class_obscure
, threadset_test_cmd
,
4739 "Test setting to a different thread");
4740 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
4741 "Iterate through updating all remote thread info");
4742 add_com ("talive", class_obscure
, threadalive_test
,
4743 " Remote thread alive test ");
4749 init_remote_ops (void)
4751 remote_ops
.to_shortname
= "remote";
4752 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
4754 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4755 Specify the serial device it is connected to\n\
4756 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
4757 remote_ops
.to_open
= remote_open
;
4758 remote_ops
.to_close
= remote_close
;
4759 remote_ops
.to_detach
= remote_detach
;
4760 remote_ops
.to_resume
= remote_resume
;
4761 remote_ops
.to_wait
= remote_wait
;
4762 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
4763 remote_ops
.to_store_registers
= remote_store_registers
;
4764 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
4765 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
4766 remote_ops
.to_files_info
= remote_files_info
;
4767 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
4768 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
4769 remote_ops
.to_kill
= remote_kill
;
4770 remote_ops
.to_load
= generic_load
;
4771 remote_ops
.to_mourn_inferior
= remote_mourn
;
4772 remote_ops
.to_thread_alive
= remote_thread_alive
;
4773 remote_ops
.to_find_new_threads
= remote_threads_info
;
4774 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
4775 remote_ops
.to_stop
= remote_stop
;
4776 remote_ops
.to_query
= remote_query
;
4777 remote_ops
.to_rcmd
= remote_rcmd
;
4778 remote_ops
.to_stratum
= process_stratum
;
4779 remote_ops
.to_has_all_memory
= 1;
4780 remote_ops
.to_has_memory
= 1;
4781 remote_ops
.to_has_stack
= 1;
4782 remote_ops
.to_has_registers
= 1;
4783 remote_ops
.to_has_execution
= 1;
4784 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
4785 remote_ops
.to_magic
= OPS_MAGIC
;
4788 /* Set up the extended remote vector by making a copy of the standard
4789 remote vector and adding to it. */
4792 init_extended_remote_ops (void)
4794 extended_remote_ops
= remote_ops
;
4796 extended_remote_ops
.to_shortname
= "extended-remote";
4797 extended_remote_ops
.to_longname
=
4798 "Extended remote serial target in gdb-specific protocol";
4799 extended_remote_ops
.to_doc
=
4800 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4801 Specify the serial device it is connected to (e.g. /dev/ttya).",
4802 extended_remote_ops
.to_open
= extended_remote_open
;
4803 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
4804 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
4808 * Command: info remote-process
4810 * This implements Cisco's version of the "info proc" command.
4812 * This query allows the target stub to return an arbitrary string
4813 * (or strings) giving arbitrary information about the target process.
4814 * This is optional; the target stub isn't required to implement it.
4816 * Syntax: qfProcessInfo request first string
4817 * qsProcessInfo request subsequent string
4818 * reply: 'O'<hex-encoded-string>
4819 * 'l' last reply (empty)
4823 remote_info_process (char *args
, int from_tty
)
4825 char *buf
= alloca (PBUFSIZ
);
4827 if (remote_desc
== 0)
4828 error ("Command can only be used when connected to the remote target.");
4830 putpkt ("qfProcessInfo");
4831 getpkt (buf
, PBUFSIZ
, 0);
4833 return; /* Silently: target does not support this feature. */
4836 error ("info proc: target error.");
4838 while (buf
[0] == 'O') /* Capitol-O packet */
4840 remote_console_output (&buf
[1]);
4841 putpkt ("qsProcessInfo");
4842 getpkt (buf
, PBUFSIZ
, 0);
4851 remote_cisco_open (char *name
, int from_tty
)
4855 "To open a remote debug connection, you need to specify what \n\
4856 device is attached to the remote system (e.g. host:port).");
4858 /* See FIXME above */
4859 wait_forever_enabled_p
= 1;
4861 target_preopen (from_tty
);
4863 unpush_target (&remote_cisco_ops
);
4865 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
4867 remote_desc
= SERIAL_OPEN (name
);
4869 perror_with_name (name
);
4872 * If a baud rate was specified on the gdb command line it will
4873 * be greater than the initial value of -1. If it is, use it otherwise
4877 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
4878 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
4880 SERIAL_CLOSE (remote_desc
);
4881 perror_with_name (name
);
4884 SERIAL_RAW (remote_desc
);
4886 /* If there is something sitting in the buffer we might take it as a
4887 response to a command, which would be bad. */
4888 SERIAL_FLUSH_INPUT (remote_desc
);
4892 puts_filtered ("Remote debugging using ");
4893 puts_filtered (name
);
4894 puts_filtered ("\n");
4897 remote_cisco_mode
= 1;
4899 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
4901 init_packet_config (&remote_protocol_P
);
4902 init_packet_config (&remote_protocol_Z
);
4904 general_thread
= -2;
4905 continue_thread
= -2;
4907 /* Force remote_write_bytes to check whether target supports
4908 binary downloading. */
4909 init_packet_config (&remote_protocol_binary_download
);
4911 /* Probe for ability to use "ThreadInfo" query, as required. */
4912 use_threadinfo_query
= 1;
4913 use_threadextra_query
= 1;
4915 /* Without this, some commands which require an active target (such
4916 as kill) won't work. This variable serves (at least) double duty
4917 as both the pid of the target process (if it has such), and as a
4918 flag indicating that a target is active. These functions should
4919 be split out into seperate variables, especially since GDB will
4920 someday have a notion of debugging several processes. */
4921 inferior_pid
= MAGIC_NULL_PID
;
4923 /* Start the remote connection; if error (0), discard this target. */
4925 if (!catch_errors (remote_start_remote_dummy
, (char *) 0,
4926 "Couldn't establish connection to remote target\n",
4935 remote_cisco_close (int quitting
)
4937 remote_cisco_mode
= 0;
4938 remote_close (quitting
);
4942 remote_cisco_mourn (void)
4944 remote_mourn_1 (&remote_cisco_ops
);
4956 /* shared between readsocket() and readtty() */
4957 static char *tty_input
;
4959 static int escape_count
;
4960 static int echo_check
;
4961 extern int quit_flag
;
4968 /* Loop until the socket doesn't have any more data */
4970 while ((data
= readchar (0)) >= 0)
4972 /* Check for the escape sequence */
4975 /* If this is the fourth escape, get out */
4976 if (++escape_count
== 4)
4981 { /* This is a '|', but not the fourth in a row.
4982 Continue without echoing it. If it isn't actually
4983 one of four in a row, it'll be echoed later. */
4990 /* Ensure any pending '|'s are flushed. */
4992 for (; escape_count
> 0; escape_count
--)
4996 if (data
== '\r') /* If this is a return character, */
4997 continue; /* - just supress it. */
4999 if (echo_check
!= -1) /* Check for echo of user input. */
5001 if (tty_input
[echo_check
] == data
)
5003 echo_check
++; /* Character matched user input: */
5004 continue; /* Continue without echoing it. */
5006 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5007 { /* End of the line (and of echo checking). */
5008 echo_check
= -1; /* No more echo supression */
5009 continue; /* Continue without echoing. */
5012 { /* Failed check for echo of user input.
5013 We now have some suppressed output to flush! */
5016 for (j
= 0; j
< echo_check
; j
++)
5017 putchar (tty_input
[j
]);
5021 putchar (data
); /* Default case: output the char. */
5024 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5025 return READ_MORE
; /* Try to read some more */
5027 return FATAL_ERROR
; /* Trouble, bail out */
5035 /* First, read a buffer full from the terminal */
5036 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5037 if (tty_bytecount
== -1)
5039 perror ("readtty: read failed");
5043 /* Remove a quoted newline. */
5044 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5045 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5047 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5048 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5051 /* Turn trailing newlines into returns */
5052 if (tty_input
[tty_bytecount
- 1] == '\n')
5053 tty_input
[tty_bytecount
- 1] = '\r';
5055 /* If the line consists of a ~, enter debugging mode. */
5056 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5059 /* Make this a zero terminated string and write it out */
5060 tty_input
[tty_bytecount
] = 0;
5061 if (SERIAL_WRITE (remote_desc
, tty_input
, tty_bytecount
))
5063 perror_with_name ("readtty: write failed");
5073 fd_set input
; /* file descriptors for select */
5074 int tablesize
; /* max number of FDs for select */
5078 extern int escape_count
; /* global shared by readsocket */
5079 extern int echo_check
; /* ditto */
5084 tablesize
= 8 * sizeof (input
);
5088 /* Check for anything from our socket - doesn't block. Note that
5089 this must be done *before* the select as there may be
5090 buffered I/O waiting to be processed. */
5092 if ((status
= readsocket ()) == FATAL_ERROR
)
5094 error ("Debugging terminated by communications error");
5096 else if (status
!= READ_MORE
)
5101 fflush (stdout
); /* Flush output before blocking */
5103 /* Now block on more socket input or TTY input */
5106 FD_SET (fileno (stdin
), &input
);
5107 FD_SET (DEPRECATED_SERIAL_FD (remote_desc
), &input
);
5109 status
= select (tablesize
, &input
, 0, 0, 0);
5110 if ((status
== -1) && (errno
!= EINTR
))
5112 error ("Communications error on select %d", errno
);
5115 /* Handle Control-C typed */
5119 if ((++quit_count
) == 2)
5121 if (query ("Interrupt GDB? "))
5123 printf_filtered ("Interrupted by user.\n");
5124 return_to_top_level (RETURN_QUIT
);
5131 SERIAL_SEND_BREAK (remote_desc
);
5133 SERIAL_WRITE (remote_desc
, "\003", 1);
5138 /* Handle console input */
5140 if (FD_ISSET (fileno (stdin
), &input
))
5144 status
= readtty ();
5145 if (status
== READ_MORE
)
5148 return status
; /* telnet session ended */
5154 remote_cisco_wait (int pid
, struct target_waitstatus
*status
)
5156 if (minitelnet () != ENTER_DEBUG
)
5158 error ("Debugging session terminated by protocol error");
5161 return remote_wait (pid
, status
);
5165 init_remote_cisco_ops (void)
5167 remote_cisco_ops
.to_shortname
= "cisco";
5168 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5169 remote_cisco_ops
.to_doc
=
5170 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5171 Specify the serial device it is connected to (e.g. host:2020).";
5172 remote_cisco_ops
.to_open
= remote_cisco_open
;
5173 remote_cisco_ops
.to_close
= remote_cisco_close
;
5174 remote_cisco_ops
.to_detach
= remote_detach
;
5175 remote_cisco_ops
.to_resume
= remote_resume
;
5176 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5177 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5178 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5179 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5180 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5181 remote_cisco_ops
.to_files_info
= remote_files_info
;
5182 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5183 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5184 remote_cisco_ops
.to_kill
= remote_kill
;
5185 remote_cisco_ops
.to_load
= generic_load
;
5186 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5187 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5188 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5189 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5190 remote_cisco_ops
.to_stratum
= process_stratum
;
5191 remote_cisco_ops
.to_has_all_memory
= 1;
5192 remote_cisco_ops
.to_has_memory
= 1;
5193 remote_cisco_ops
.to_has_stack
= 1;
5194 remote_cisco_ops
.to_has_registers
= 1;
5195 remote_cisco_ops
.to_has_execution
= 1;
5196 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5200 remote_can_async_p (void)
5202 /* We're async whenever the serial device is. */
5203 return (current_target
.to_async_mask_value
) && SERIAL_CAN_ASYNC_P (remote_desc
);
5207 remote_is_async_p (void)
5209 /* We're async whenever the serial device is. */
5210 return (current_target
.to_async_mask_value
) && SERIAL_IS_ASYNC_P (remote_desc
);
5213 /* Pass the SERIAL event on and up to the client. One day this code
5214 will be able to delay notifying the client of an event until the
5215 point where an entire packet has been received. */
5217 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5218 static void *async_client_context
;
5219 static serial_event_ftype remote_async_serial_handler
;
5222 remote_async_serial_handler (serial_t scb
, void *context
)
5224 /* Don't propogate error information up to the client. Instead let
5225 the client find out about the error by querying the target. */
5226 async_client_callback (INF_REG_EVENT
, async_client_context
);
5230 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5232 if (current_target
.to_async_mask_value
== 0)
5233 internal_error ("Calling remote_async when async is masked");
5235 if (callback
!= NULL
)
5237 SERIAL_ASYNC (remote_desc
, remote_async_serial_handler
, NULL
);
5238 async_client_callback
= callback
;
5239 async_client_context
= context
;
5242 SERIAL_ASYNC (remote_desc
, NULL
, NULL
);
5245 /* Target async and target extended-async.
5247 This are temporary targets, until it is all tested. Eventually
5248 async support will be incorporated int the usual 'remote'
5252 init_remote_async_ops (void)
5254 remote_async_ops
.to_shortname
= "async";
5255 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5256 remote_async_ops
.to_doc
=
5257 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5258 Specify the serial device it is connected to (e.g. /dev/ttya).";
5259 remote_async_ops
.to_open
= remote_async_open
;
5260 remote_async_ops
.to_close
= remote_close
;
5261 remote_async_ops
.to_detach
= remote_async_detach
;
5262 remote_async_ops
.to_resume
= remote_async_resume
;
5263 remote_async_ops
.to_wait
= remote_async_wait
;
5264 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5265 remote_async_ops
.to_store_registers
= remote_store_registers
;
5266 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5267 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5268 remote_async_ops
.to_files_info
= remote_files_info
;
5269 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5270 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5271 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5272 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5273 remote_async_ops
.to_kill
= remote_async_kill
;
5274 remote_async_ops
.to_load
= generic_load
;
5275 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5276 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5277 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5278 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5279 remote_async_ops
.to_stop
= remote_stop
;
5280 remote_async_ops
.to_query
= remote_query
;
5281 remote_async_ops
.to_rcmd
= remote_rcmd
;
5282 remote_async_ops
.to_stratum
= process_stratum
;
5283 remote_async_ops
.to_has_all_memory
= 1;
5284 remote_async_ops
.to_has_memory
= 1;
5285 remote_async_ops
.to_has_stack
= 1;
5286 remote_async_ops
.to_has_registers
= 1;
5287 remote_async_ops
.to_has_execution
= 1;
5288 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5289 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5290 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5291 remote_async_ops
.to_async
= remote_async
;
5292 remote_async_ops
.to_async_mask_value
= 1;
5293 remote_async_ops
.to_magic
= OPS_MAGIC
;
5296 /* Set up the async extended remote vector by making a copy of the standard
5297 remote vector and adding to it. */
5300 init_extended_async_remote_ops (void)
5302 extended_async_remote_ops
= remote_async_ops
;
5304 extended_async_remote_ops
.to_shortname
= "extended-async";
5305 extended_async_remote_ops
.to_longname
=
5306 "Extended remote serial target in async gdb-specific protocol";
5307 extended_async_remote_ops
.to_doc
=
5308 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5309 Specify the serial device it is connected to (e.g. /dev/ttya).",
5310 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5311 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5312 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5316 set_remote_cmd (char *args
, int from_tty
)
5323 build_remote_gdbarch_data (void)
5325 build_remote_packet_sizes ();
5328 tty_input
= xmalloc (PBUFSIZ
);
5329 remote_address_size
= TARGET_PTR_BIT
;
5333 _initialize_remote (void)
5335 static struct cmd_list_element
*remote_set_cmdlist
;
5336 static struct cmd_list_element
*remote_show_cmdlist
;
5337 struct cmd_list_element
*tmpcmd
;
5339 /* architecture specific data */
5340 build_remote_gdbarch_data ();
5341 register_gdbarch_swap (&tty_input
, sizeof (&tty_input
), NULL
);
5342 register_remote_packet_sizes ();
5343 register_gdbarch_swap (&remote_address_size
,
5344 sizeof (&remote_address_size
), NULL
);
5345 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5348 add_target (&remote_ops
);
5350 init_extended_remote_ops ();
5351 add_target (&extended_remote_ops
);
5353 init_remote_async_ops ();
5354 add_target (&remote_async_ops
);
5356 init_extended_async_remote_ops ();
5357 add_target (&extended_async_remote_ops
);
5359 init_remote_cisco_ops ();
5360 add_target (&remote_cisco_ops
);
5363 init_remote_threadtests ();
5366 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5367 Remote protocol specific variables\n\
5368 Configure various remote-protocol specific variables such as\n\
5369 the packets being used",
5370 &remote_set_cmdlist
, "set remote ",
5371 0/*allow-unknown*/, &setlist
);
5372 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5373 Remote protocol specific variables\n\
5374 Configure various remote-protocol specific variables such as\n\
5375 the packets being used",
5376 &remote_show_cmdlist
, "show remote ",
5377 0/*allow-unknown*/, &showlist
);
5379 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
5380 "Compare section data on target to the exec file.\n\
5381 Argument is a single section name (default: all loaded sections).",
5384 add_cmd ("packet", class_maintenance
, packet_command
,
5385 "Send an arbitrary packet to a remote target.\n\
5386 maintenance packet TEXT\n\
5387 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5388 this command sends the string TEXT to the inferior, and displays the\n\
5389 response packet. GDB supplies the initial `$' character, and the\n\
5390 terminating `#' character and checksum.",
5394 (add_set_cmd ("remotebreak", no_class
,
5395 var_boolean
, (char *) &remote_break
,
5396 "Set whether to send break if interrupted.\n",
5400 /* Install commands for configuring memory read/write packets. */
5402 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
5403 "Set the maximum number of bytes per memory write packet (deprecated).\n",
5405 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
5406 "Show the maximum number of bytes per memory write packet (deprecated).\n",
5408 add_cmd ("memory-write-packet-size", no_class
,
5409 set_memory_write_packet_size
,
5410 "Set the maximum number of bytes per memory-write packet.\n"
5411 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5412 "default packet size. The actual limit is further reduced\n"
5413 "dependent on the target. Specify ``fixed'' to disable the\n"
5414 "further restriction and ``limit'' to enable that restriction\n",
5415 &remote_set_cmdlist
);
5416 add_cmd ("memory-read-packet-size", no_class
,
5417 set_memory_read_packet_size
,
5418 "Set the maximum number of bytes per memory-read packet.\n"
5419 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5420 "default packet size. The actual limit is further reduced\n"
5421 "dependent on the target. Specify ``fixed'' to disable the\n"
5422 "further restriction and ``limit'' to enable that restriction\n",
5423 &remote_set_cmdlist
);
5424 add_cmd ("memory-write-packet-size", no_class
,
5425 show_memory_write_packet_size
,
5426 "Show the maximum number of bytes per memory-write packet.\n",
5427 &remote_show_cmdlist
);
5428 add_cmd ("memory-read-packet-size", no_class
,
5429 show_memory_read_packet_size
,
5430 "Show the maximum number of bytes per memory-read packet.\n",
5431 &remote_show_cmdlist
);
5434 (add_set_cmd ("remoteaddresssize", class_obscure
,
5435 var_integer
, (char *) &remote_address_size
,
5436 "Set the maximum size of the address (in bits) \
5437 in a memory packet.\n",
5441 add_packet_config_cmd (&remote_protocol_binary_download
,
5442 "X", "binary-download",
5443 set_remote_protocol_binary_download_cmd
,
5444 show_remote_protocol_binary_download_cmd
,
5445 &remote_set_cmdlist
, &remote_show_cmdlist
);
5447 /* XXXX - should ``set remotebinarydownload'' be retained for
5450 (add_set_cmd ("remotebinarydownload", no_class
,
5451 var_boolean
, (char *) &remote_binary_download
,
5452 "Set binary downloads.\n", &setlist
),
5456 add_info ("remote-process", remote_info_process
,
5457 "Query the remote system for process info.");
5459 add_packet_config_cmd (&remote_protocol_P
, "P", "set-register",
5460 set_remote_protocol_P_packet_cmd
,
5461 show_remote_protocol_P_packet_cmd
,
5462 &remote_set_cmdlist
, &remote_show_cmdlist
);
5464 add_packet_config_cmd (&remote_protocol_Z
, "Z", "breakpoint",
5465 set_remote_protocol_Z_packet_cmd
,
5466 show_remote_protocol_Z_packet_cmd
,
5467 &remote_set_cmdlist
, &remote_show_cmdlist
);