1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* See the GDB User Guide for details of the GDB remote protocol. */
25 #include "gdb_string.h"
32 /*#include "terminal.h" */
35 #include "gdb-stabs.h"
36 #include "gdbthread.h"
43 #include <sys/types.h>
46 #include "event-loop.h"
47 #include "event-top.h"
53 /* Prototypes for local functions */
54 static void cleanup_sigint_signal_handler (void *dummy
);
55 static void initialize_sigint_signal_handler (void);
56 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
58 static void handle_remote_sigint (int);
59 static void handle_remote_sigint_twice (int);
60 static void async_remote_interrupt (gdb_client_data
);
61 void async_remote_interrupt_twice (gdb_client_data
);
63 static void build_remote_gdbarch_data (void);
65 static int remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
67 static int remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
69 static void remote_files_info (struct target_ops
*ignore
);
71 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
72 int len
, int should_write
,
73 struct mem_attrib
*attrib
,
74 struct target_ops
*target
);
76 static void remote_prepare_to_store (void);
78 static void remote_fetch_registers (int regno
);
80 static void remote_resume (int pid
, int step
, enum target_signal siggnal
);
81 static void remote_async_resume (int pid
, int step
,
82 enum target_signal siggnal
);
83 static int remote_start_remote (PTR
);
85 static void remote_open (char *name
, int from_tty
);
86 static void remote_async_open (char *name
, int from_tty
);
88 static void extended_remote_open (char *name
, int from_tty
);
89 static void extended_remote_async_open (char *name
, int from_tty
);
91 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
92 static void remote_async_open_1 (char *, int, struct target_ops
*,
95 static void remote_close (int quitting
);
97 static void remote_store_registers (int regno
);
99 static void remote_mourn (void);
100 static void remote_async_mourn (void);
102 static void extended_remote_restart (void);
104 static void extended_remote_mourn (void);
106 static void extended_remote_create_inferior (char *, char *, char **);
107 static void extended_remote_async_create_inferior (char *, char *, char **);
109 static void remote_mourn_1 (struct target_ops
*);
111 static void remote_send (char *buf
, long sizeof_buf
);
113 static int readchar (int timeout
);
115 static int remote_wait (int pid
, struct target_waitstatus
*status
);
116 static int remote_async_wait (int pid
, struct target_waitstatus
*status
);
118 static void remote_kill (void);
119 static void remote_async_kill (void);
121 static int tohex (int nib
);
123 static void remote_detach (char *args
, int from_tty
);
124 static void remote_async_detach (char *args
, int from_tty
);
126 static void remote_interrupt (int signo
);
128 static void remote_interrupt_twice (int signo
);
130 static void interrupt_query (void);
132 static void set_thread (int, int);
134 static int remote_thread_alive (int);
136 static void get_offsets (void);
138 static long read_frame (char *buf
, long sizeof_buf
);
140 static int remote_insert_breakpoint (CORE_ADDR
, char *);
142 static int remote_remove_breakpoint (CORE_ADDR
, char *);
144 static int hexnumlen (ULONGEST num
);
146 static void init_remote_ops (void);
148 static void init_extended_remote_ops (void);
150 static void init_remote_cisco_ops (void);
152 static struct target_ops remote_cisco_ops
;
154 static void remote_stop (void);
156 static int ishex (int ch
, int *val
);
158 static int stubhex (int ch
);
160 static int remote_query (int /*char */ , char *, char *, int *);
162 static int hexnumstr (char *, ULONGEST
);
164 static int hexnumnstr (char *, ULONGEST
, int);
166 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
168 static void print_packet (char *);
170 static unsigned long crc32 (unsigned char *, int, unsigned int);
172 static void compare_sections_command (char *, int);
174 static void packet_command (char *, int);
176 static int stub_unpack_int (char *buff
, int fieldlength
);
178 static int remote_current_thread (int oldpid
);
180 static void remote_find_new_threads (void);
182 static void record_currthread (int currthread
);
184 /* exported functions */
186 extern int fromhex (int a
);
188 static int putpkt_binary (char *buf
, int cnt
);
190 static void check_binary_download (CORE_ADDR addr
);
192 struct packet_config
;
194 static void show_packet_config_cmd (struct packet_config
*config
);
196 static void update_packet_config (struct packet_config
*config
);
198 /* Define the target subroutine names */
200 void open_remote_target (char *, int, struct target_ops
*, int);
202 void _initialize_remote (void);
206 static struct target_ops remote_ops
;
208 static struct target_ops extended_remote_ops
;
210 /* Temporary target ops. Just like the remote_ops and
211 extended_remote_ops, but with asynchronous support. */
212 static struct target_ops remote_async_ops
;
214 static struct target_ops extended_async_remote_ops
;
216 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
217 ``forever'' still use the normal timeout mechanism. This is
218 currently used by the ASYNC code to guarentee that target reads
219 during the initial connect always time-out. Once getpkt has been
220 modified to return a timeout indication and, in turn
221 remote_wait()/wait_for_inferior() have gained a timeout parameter
223 static int wait_forever_enabled_p
= 1;
226 /* This variable chooses whether to send a ^C or a break when the user
227 requests program interruption. Although ^C is usually what remote
228 systems expect, and that is the default here, sometimes a break is
229 preferable instead. */
231 static int remote_break
;
233 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
234 remote_open knows that we don't have a file open when the program
236 static serial_t remote_desc
= NULL
;
238 /* This is set by the target (thru the 'S' message)
239 to denote that the target is in kernel mode. */
240 static int cisco_kernel_mode
= 0;
242 /* This variable sets the number of bits in an address that are to be
243 sent in a memory ("M" or "m") packet. Normally, after stripping
244 leading zeros, the entire address would be sent. This variable
245 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
246 initial implementation of remote.c restricted the address sent in
247 memory packets to ``host::sizeof long'' bytes - (typically 32
248 bits). Consequently, for 64 bit targets, the upper 32 bits of an
249 address was never sent. Since fixing this bug may cause a break in
250 some remote targets this variable is principly provided to
251 facilitate backward compatibility. */
253 static int remote_address_size
;
255 /* Tempoary to track who currently owns the terminal. See
256 target_async_terminal_* for more details. */
258 static int remote_async_terminal_ours_p
;
261 /* This is the size (in chars) of the first response to the ``g''
262 packet. It is used as a heuristic when determining the maximum
263 size of memory-read and memory-write packets. A target will
264 typically only reserve a buffer large enough to hold the ``g''
265 packet. The size does not include packet overhead (headers and
268 static long actual_register_packet_size
;
270 /* This is the maximum size (in chars) of a non read/write packet. It
271 is also used as a cap on the size of read/write packets. */
273 static long remote_packet_size
;
275 #define PBUFSIZ (remote_packet_size)
277 /* User configurable variables for the number of characters in a
278 memory read/write packet. MIN (PBUFSIZ, g-packet-size) is the
279 default. Some targets need smaller values (fifo overruns, et.al.)
280 and some users need larger values (speed up transfers). The
281 variables ``preferred_*'' (the user request), ``current_*'' (what
282 was actually set) and ``forced_*'' (Positive - a soft limit,
283 negative - a hard limit). */
285 struct memory_packet_config
292 /* Compute the current size of a read/write packet. Since this makes
293 use of ``actual_register_packet_size'' the computation is dynamic. */
296 get_memory_packet_size (struct memory_packet_config
*config
)
298 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
299 law?) that some hosts don't cope very well with large alloca()
300 calls. Eventually the alloca() code will be replaced by calls to
301 xmalloc() and make_cleanups() allowing this restriction to either
302 be lifted or removed. */
303 #ifndef MAX_REMOTE_PACKET_SIZE
304 #define MAX_REMOTE_PACKET_SIZE 16384
306 /* NOTE: 16 is just chosen at random. */
307 #ifndef MIN_REMOTE_PACKET_SIZE
308 #define MIN_REMOTE_PACKET_SIZE 16
313 if (config
->size
<= 0)
314 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
316 what_they_get
= config
->size
;
320 what_they_get
= remote_packet_size
;
321 /* Limit the packet to the size specified by the user. */
323 && what_they_get
> config
->size
)
324 what_they_get
= config
->size
;
325 /* Limit it to the size of the targets ``g'' response. */
326 if (actual_register_packet_size
> 0
327 && what_they_get
> actual_register_packet_size
)
328 what_they_get
= actual_register_packet_size
;
330 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
331 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
332 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
333 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
334 return what_they_get
;
337 /* Update the size of a read/write packet. If they user wants
338 something really big then do a sanity check. */
341 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
343 int fixed_p
= config
->fixed_p
;
344 long size
= config
->size
;
346 error ("Argument required (integer, `fixed' or `limited').");
347 else if (strcmp (args
, "hard") == 0
348 || strcmp (args
, "fixed") == 0)
350 else if (strcmp (args
, "soft") == 0
351 || strcmp (args
, "limit") == 0)
356 size
= strtoul (args
, &end
, 0);
358 error ("Invalid %s (bad syntax).", config
->name
);
360 /* Instead of explicitly capping the size of a packet to
361 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
362 instead allowed to set the size to something arbitrarily
364 if (size
> MAX_REMOTE_PACKET_SIZE
)
365 error ("Invalid %s (too large).", config
->name
);
369 if (fixed_p
&& !config
->fixed_p
)
371 if (! query ("The target may not be able to correctly handle a %s\n"
372 "of %ld bytes. Change the packet size? ",
374 error ("Packet size not changed.");
376 /* Update the config. */
377 config
->fixed_p
= fixed_p
;
382 show_memory_packet_size (struct memory_packet_config
*config
)
384 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
386 printf_filtered ("Packets are fixed at %ld bytes.\n",
387 get_memory_packet_size (config
));
389 printf_filtered ("Packets are limited to %ld bytes.\n",
390 get_memory_packet_size (config
));
393 static struct memory_packet_config memory_write_packet_config
=
395 "memory-write-packet-size",
399 set_memory_write_packet_size (char *args
, int from_tty
)
401 set_memory_packet_size (args
, &memory_write_packet_config
);
405 show_memory_write_packet_size (char *args
, int from_tty
)
407 show_memory_packet_size (&memory_write_packet_config
);
411 get_memory_write_packet_size (void)
413 return get_memory_packet_size (&memory_write_packet_config
);
416 static struct memory_packet_config memory_read_packet_config
=
418 "memory-read-packet-size",
422 set_memory_read_packet_size (char *args
, int from_tty
)
424 set_memory_packet_size (args
, &memory_read_packet_config
);
428 show_memory_read_packet_size (char *args
, int from_tty
)
430 show_memory_packet_size (&memory_read_packet_config
);
434 get_memory_read_packet_size (void)
436 long size
= get_memory_packet_size (&memory_read_packet_config
);
437 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
438 extra buffer size argument before the memory read size can be
439 increased beyond PBUFSIZ. */
445 /* Register packet size initialization. Since the bounds change when
446 the architecture changes (namely REGISTER_BYTES) this all needs to
450 register_remote_packet_sizes (void)
452 REGISTER_GDBARCH_SWAP (remote_packet_size
);
453 REGISTER_GDBARCH_SWAP (actual_register_packet_size
);
457 build_remote_packet_sizes (void)
459 /* Default maximum number of characters in a packet body. Many
460 remote stubs have a hardwired buffer size of 400 bytes
461 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
462 as the maximum packet-size to ensure that the packet and an extra
463 NUL character can always fit in the buffer. This stops GDB
464 trashing stubs that try to squeeze an extra NUL into what is
465 already a full buffer (As of 1999-12-04 that was most stubs. */
466 remote_packet_size
= 400 - 1;
467 /* Should REGISTER_BYTES needs more space than the default, adjust
468 the size accordingly. Remember that each byte is encoded as two
469 characters. 32 is the overhead for the packet header /
470 footer. NOTE: cagney/1999-10-26: I suspect that 8
471 (``$NN:G...#NN'') is a better guess, the below has been padded a
473 if (REGISTER_BYTES
> ((remote_packet_size
- 32) / 2))
474 remote_packet_size
= (REGISTER_BYTES
* 2 + 32);
476 /* This one is filled in when a ``g'' packet is received. */
477 actual_register_packet_size
= 0;
480 /* Generic configuration support for packets the stub optionally
481 supports. Allows the user to specify the use of the packet as well
482 as allowing GDB to auto-detect support in the remote stub. */
486 PACKET_SUPPORT_UNKNOWN
= 0,
495 enum cmd_auto_boolean detect
;
496 enum packet_support support
;
499 /* Analyze a packet's return value and update the packet config
510 update_packet_config (struct packet_config
*config
)
512 switch (config
->detect
)
514 case CMD_AUTO_BOOLEAN_TRUE
:
515 config
->support
= PACKET_ENABLE
;
517 case CMD_AUTO_BOOLEAN_FALSE
:
518 config
->support
= PACKET_DISABLE
;
520 case CMD_AUTO_BOOLEAN_AUTO
:
521 config
->support
= PACKET_SUPPORT_UNKNOWN
;
527 show_packet_config_cmd (struct packet_config
*config
)
529 char *support
= "internal-error";
530 switch (config
->support
)
536 support
= "disabled";
538 case PACKET_SUPPORT_UNKNOWN
:
542 switch (config
->detect
)
544 case CMD_AUTO_BOOLEAN_AUTO
:
545 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
546 config
->name
, config
->title
, support
);
548 case CMD_AUTO_BOOLEAN_TRUE
:
549 case CMD_AUTO_BOOLEAN_FALSE
:
550 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
551 config
->name
, config
->title
, support
);
557 add_packet_config_cmd (struct packet_config
*config
,
560 void (*set_func
) (char *args
, int from_tty
,
561 struct cmd_list_element
*
563 void (*show_func
) (char *name
,
565 struct cmd_list_element
**set_remote_list
,
566 struct cmd_list_element
**show_remote_list
,
569 struct cmd_list_element
*set_cmd
;
570 struct cmd_list_element
*show_cmd
;
575 config
->title
= title
;
576 config
->detect
= CMD_AUTO_BOOLEAN_AUTO
;
577 config
->support
= PACKET_SUPPORT_UNKNOWN
;
578 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
580 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
582 /* set/show TITLE-packet {auto,on,off} */
583 xasprintf (&cmd_name
, "%s-packet", title
);
584 set_cmd
= add_set_auto_boolean_cmd (cmd_name
, class_obscure
,
585 &config
->detect
, set_doc
,
587 set_cmd
->function
.sfunc
= set_func
;
588 show_cmd
= add_cmd (cmd_name
, class_obscure
, show_func
, show_doc
,
590 /* set/show remote NAME-packet {auto,on,off} -- legacy */
594 xasprintf (&legacy_name
, "%s-packet", name
);
595 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
597 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
602 static enum packet_result
603 packet_ok (const char *buf
, struct packet_config
*config
)
607 /* The stub recognized the packet request. Check that the
608 operation succeeded. */
609 switch (config
->support
)
611 case PACKET_SUPPORT_UNKNOWN
:
613 fprintf_unfiltered (gdb_stdlog
,
614 "Packet %s (%s) is supported\n",
615 config
->name
, config
->title
);
616 config
->support
= PACKET_ENABLE
;
619 internal_error (__FILE__
, __LINE__
,
620 "packet_ok: attempt to use a disabled packet");
625 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
626 /* "OK" - definitly OK. */
629 && isxdigit (buf
[1]) && isxdigit (buf
[2])
631 /* "Enn" - definitly an error. */
633 /* The packet may or may not be OK. Just assume it is */
638 /* The stub does not support the packet. */
639 switch (config
->support
)
642 if (config
->detect
== CMD_AUTO_BOOLEAN_AUTO
)
643 /* If the stub previously indicated that the packet was
644 supported then there is a protocol error.. */
645 error ("Protocol error: %s (%s) conflicting enabled responses.",
646 config
->name
, config
->title
);
648 /* The user set it wrong. */
649 error ("Enabled packet %s (%s) not recognized by stub",
650 config
->name
, config
->title
);
652 case PACKET_SUPPORT_UNKNOWN
:
654 fprintf_unfiltered (gdb_stdlog
,
655 "Packet %s (%s) is NOT supported\n",
656 config
->name
, config
->title
);
657 config
->support
= PACKET_DISABLE
;
662 return PACKET_UNKNOWN
;
666 /* Should we try the 'P' (set register) request? */
668 static struct packet_config remote_protocol_P
;
671 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
672 struct cmd_list_element
*c
)
674 update_packet_config (&remote_protocol_P
);
678 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
)
680 show_packet_config_cmd (&remote_protocol_P
);
683 /* Should we try one of the 'Z' requests? */
687 Z_PACKET_SOFTWARE_BP
,
688 Z_PACKET_HARDWARE_BP
,
695 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
697 /* FIXME: Instead of having all these boiler plate functions, the
698 command callback should include a context argument. */
701 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
702 struct cmd_list_element
*c
)
704 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
708 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
)
710 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
714 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
715 struct cmd_list_element
*c
)
717 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
721 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
)
723 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
727 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
728 struct cmd_list_element
*c
)
730 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
734 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
)
736 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
740 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
741 struct cmd_list_element
*c
)
743 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
747 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
)
749 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
753 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
754 struct cmd_list_element
*c
)
756 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
760 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
)
762 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
765 /* For compatibility with older distributions. Provide a ``set remote
766 Z-packet ...'' command that updates all the Z packet types. */
768 static enum cmd_auto_boolean remote_Z_packet_detect
;
771 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
772 struct cmd_list_element
*c
)
775 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
777 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
778 update_packet_config (&remote_protocol_Z
[i
]);
783 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
)
786 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
788 show_packet_config_cmd (&remote_protocol_Z
[i
]);
792 /* Should we try the 'X' (remote binary download) packet?
794 This variable (available to the user via "set remote X-packet")
795 dictates whether downloads are sent in binary (via the 'X' packet).
796 We assume that the stub can, and attempt to do it. This will be
797 cleared if the stub does not understand it. This switch is still
798 needed, though in cases when the packet is supported in the stub,
799 but the connection does not allow it (i.e., 7-bit serial connection
802 static struct packet_config remote_protocol_binary_download
;
804 /* Should we try the 'ThreadInfo' query packet?
806 This variable (NOT available to the user: auto-detect only!)
807 determines whether GDB will use the new, simpler "ThreadInfo"
808 query or the older, more complex syntax for thread queries.
809 This is an auto-detect variable (set to true at each connect,
810 and set to false when the target fails to recognize it). */
812 static int use_threadinfo_query
;
813 static int use_threadextra_query
;
816 set_remote_protocol_binary_download_cmd (char *args
,
818 struct cmd_list_element
*c
)
820 update_packet_config (&remote_protocol_binary_download
);
824 show_remote_protocol_binary_download_cmd (char *args
,
827 show_packet_config_cmd (&remote_protocol_binary_download
);
831 /* Tokens for use by the asynchronous signal handlers for SIGINT */
832 PTR sigint_remote_twice_token
;
833 PTR sigint_remote_token
;
835 /* These are pointers to hook functions that may be set in order to
836 modify resume/wait behavior for a particular architecture. */
838 void (*target_resume_hook
) (void);
839 void (*target_wait_loop_hook
) (void);
843 /* These are the threads which we last sent to the remote system.
844 -1 for all or -2 for not sent yet. */
845 static int general_thread
;
846 static int continue_thread
;
848 /* Call this function as a result of
849 1) A halt indication (T packet) containing a thread id
850 2) A direct query of currthread
851 3) Successful execution of set thread
855 record_currthread (int currthread
)
857 general_thread
= currthread
;
859 /* If this is a new thread, add it to GDB's thread list.
860 If we leave it up to WFI to do this, bad things will happen. */
861 if (!in_thread_list (currthread
))
863 add_thread (currthread
);
865 ui_out_text (uiout
, "[New ");
866 ui_out_text (uiout
, target_pid_to_str (currthread
));
867 ui_out_text (uiout
, "]\n");
869 printf_filtered ("[New %s]\n", target_pid_to_str (currthread
));
874 #define MAGIC_NULL_PID 42000
877 set_thread (int th
, int gen
)
879 char *buf
= alloca (PBUFSIZ
);
880 int state
= gen
? general_thread
: continue_thread
;
886 buf
[1] = gen
? 'g' : 'c';
887 if (th
== MAGIC_NULL_PID
)
893 sprintf (&buf
[2], "-%x", -th
);
895 sprintf (&buf
[2], "%x", th
);
897 getpkt (buf
, PBUFSIZ
, 0);
901 continue_thread
= th
;
904 /* Return nonzero if the thread TH is still alive on the remote system. */
907 remote_thread_alive (int tid
)
912 sprintf (buf
, "T-%08x", -tid
);
914 sprintf (buf
, "T%08x", tid
);
916 getpkt (buf
, sizeof (buf
), 0);
917 return (buf
[0] == 'O' && buf
[1] == 'K');
920 /* About these extended threadlist and threadinfo packets. They are
921 variable length packets but, the fields within them are often fixed
922 length. They are redundent enough to send over UDP as is the
923 remote protocol in general. There is a matching unit test module
926 #define OPAQUETHREADBYTES 8
928 /* a 64 bit opaque identifier */
929 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
931 /* WARNING: This threadref data structure comes from the remote O.S., libstub
932 protocol encoding, and remote.c. it is not particularly changable */
934 /* Right now, the internal structure is int. We want it to be bigger.
938 typedef int gdb_threadref
; /* internal GDB thread reference */
940 /* gdb_ext_thread_info is an internal GDB data structure which is
941 equivalint to the reply of the remote threadinfo packet */
943 struct gdb_ext_thread_info
945 threadref threadid
; /* External form of thread reference */
946 int active
; /* Has state interesting to GDB? , regs, stack */
947 char display
[256]; /* Brief state display, name, blocked/syspended */
948 char shortname
[32]; /* To be used to name threads */
949 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
952 /* The volume of remote transfers can be limited by submitting
953 a mask containing bits specifying the desired information.
954 Use a union of these values as the 'selection' parameter to
955 get_thread_info. FIXME: Make these TAG names more thread specific.
958 #define TAG_THREADID 1
960 #define TAG_DISPLAY 4
961 #define TAG_THREADNAME 8
962 #define TAG_MOREDISPLAY 16
964 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
966 char *unpack_varlen_hex (char *buff
, int *result
);
968 static char *unpack_nibble (char *buf
, int *val
);
970 static char *pack_nibble (char *buf
, int nibble
);
972 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
974 static char *unpack_byte (char *buf
, int *value
);
976 static char *pack_int (char *buf
, int value
);
978 static char *unpack_int (char *buf
, int *value
);
980 static char *unpack_string (char *src
, char *dest
, int length
);
982 static char *pack_threadid (char *pkt
, threadref
* id
);
984 static char *unpack_threadid (char *inbuf
, threadref
* id
);
986 void int_to_threadref (threadref
* id
, int value
);
988 static int threadref_to_int (threadref
* ref
);
990 static void copy_threadref (threadref
* dest
, threadref
* src
);
992 static int threadmatch (threadref
* dest
, threadref
* src
);
994 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
996 static int remote_unpack_thread_info_response (char *pkt
,
997 threadref
* expectedref
,
998 struct gdb_ext_thread_info
1002 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1003 struct gdb_ext_thread_info
*info
);
1005 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1007 struct gdb_ext_thread_info
*info
);
1009 static char *pack_threadlist_request (char *pkt
, int startflag
,
1011 threadref
* nextthread
);
1013 static int parse_threadlist_response (char *pkt
,
1015 threadref
* original_echo
,
1016 threadref
* resultlist
, int *doneflag
);
1018 static int remote_get_threadlist (int startflag
,
1019 threadref
* nextthread
,
1022 int *result_count
, threadref
* threadlist
);
1024 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1026 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1027 void *context
, int looplimit
);
1029 static int remote_newthread_step (threadref
* ref
, void *context
);
1031 /* encode 64 bits in 16 chars of hex */
1033 static const char hexchars
[] = "0123456789abcdef";
1036 ishex (int ch
, int *val
)
1038 if ((ch
>= 'a') && (ch
<= 'f'))
1040 *val
= ch
- 'a' + 10;
1043 if ((ch
>= 'A') && (ch
<= 'F'))
1045 *val
= ch
- 'A' + 10;
1048 if ((ch
>= '0') && (ch
<= '9'))
1059 if (ch
>= 'a' && ch
<= 'f')
1060 return ch
- 'a' + 10;
1061 if (ch
>= '0' && ch
<= '9')
1063 if (ch
>= 'A' && ch
<= 'F')
1064 return ch
- 'A' + 10;
1069 stub_unpack_int (char *buff
, int fieldlength
)
1076 nibble
= stubhex (*buff
++);
1080 retval
= retval
<< 4;
1086 unpack_varlen_hex (char *buff
, /* packet to parse */
1092 while (ishex (*buff
, &nibble
))
1095 retval
= retval
<< 4;
1096 retval
|= nibble
& 0x0f;
1103 unpack_nibble (char *buf
, int *val
)
1105 ishex (*buf
++, val
);
1110 pack_nibble (char *buf
, int nibble
)
1112 *buf
++ = hexchars
[(nibble
& 0x0f)];
1117 pack_hex_byte (char *pkt
, int byte
)
1119 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1120 *pkt
++ = hexchars
[(byte
& 0xf)];
1125 unpack_byte (char *buf
, int *value
)
1127 *value
= stub_unpack_int (buf
, 2);
1132 pack_int (char *buf
, int value
)
1134 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1135 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1136 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1137 buf
= pack_hex_byte (buf
, (value
& 0xff));
1142 unpack_int (char *buf
, int *value
)
1144 *value
= stub_unpack_int (buf
, 8);
1148 #if 0 /* currently unused, uncomment when needed */
1149 static char *pack_string (char *pkt
, char *string
);
1152 pack_string (char *pkt
, char *string
)
1157 len
= strlen (string
);
1159 len
= 200; /* Bigger than most GDB packets, junk??? */
1160 pkt
= pack_hex_byte (pkt
, len
);
1164 if ((ch
== '\0') || (ch
== '#'))
1165 ch
= '*'; /* Protect encapsulation */
1170 #endif /* 0 (unused) */
1173 unpack_string (char *src
, char *dest
, int length
)
1182 pack_threadid (char *pkt
, threadref
*id
)
1185 unsigned char *altid
;
1187 altid
= (unsigned char *) id
;
1188 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1190 pkt
= pack_hex_byte (pkt
, *altid
++);
1196 unpack_threadid (char *inbuf
, threadref
*id
)
1199 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1202 altref
= (char *) id
;
1204 while (inbuf
< limit
)
1206 x
= stubhex (*inbuf
++);
1207 y
= stubhex (*inbuf
++);
1208 *altref
++ = (x
<< 4) | y
;
1213 /* Externally, threadrefs are 64 bits but internally, they are still
1214 ints. This is due to a mismatch of specifications. We would like
1215 to use 64bit thread references internally. This is an adapter
1219 int_to_threadref (threadref
*id
, int value
)
1221 unsigned char *scan
;
1223 scan
= (unsigned char *) id
;
1229 *scan
++ = (value
>> 24) & 0xff;
1230 *scan
++ = (value
>> 16) & 0xff;
1231 *scan
++ = (value
>> 8) & 0xff;
1232 *scan
++ = (value
& 0xff);
1236 threadref_to_int (threadref
*ref
)
1239 unsigned char *scan
;
1241 scan
= (char *) ref
;
1245 value
= (value
<< 8) | ((*scan
++) & 0xff);
1250 copy_threadref (threadref
*dest
, threadref
*src
)
1253 unsigned char *csrc
, *cdest
;
1255 csrc
= (unsigned char *) src
;
1256 cdest
= (unsigned char *) dest
;
1263 threadmatch (threadref
*dest
, threadref
*src
)
1265 /* things are broken right now, so just assume we got a match */
1267 unsigned char *srcp
, *destp
;
1269 srcp
= (char *) src
;
1270 destp
= (char *) dest
;
1274 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1281 threadid:1, # always request threadid
1288 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1291 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1293 *pkt
++ = 'q'; /* Info Query */
1294 *pkt
++ = 'P'; /* process or thread info */
1295 pkt
= pack_int (pkt
, mode
); /* mode */
1296 pkt
= pack_threadid (pkt
, id
); /* threadid */
1297 *pkt
= '\0'; /* terminate */
1301 /* These values tag the fields in a thread info response packet */
1302 /* Tagging the fields allows us to request specific fields and to
1303 add more fields as time goes by */
1305 #define TAG_THREADID 1 /* Echo the thread identifier */
1306 #define TAG_EXISTS 2 /* Is this process defined enough to
1307 fetch registers and its stack */
1308 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1309 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1310 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1314 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1315 struct gdb_ext_thread_info
*info
)
1320 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
1323 /* info->threadid = 0; FIXME: implement zero_threadref */
1325 info
->display
[0] = '\0';
1326 info
->shortname
[0] = '\0';
1327 info
->more_display
[0] = '\0';
1329 /* Assume the characters indicating the packet type have been stripped */
1330 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1331 pkt
= unpack_threadid (pkt
, &ref
);
1334 warning ("Incomplete response to threadinfo request\n");
1335 if (!threadmatch (&ref
, expectedref
))
1336 { /* This is an answer to a different request */
1337 warning ("ERROR RMT Thread info mismatch\n");
1340 copy_threadref (&info
->threadid
, &ref
);
1342 /* Loop on tagged fields , try to bail if somthing goes wrong */
1344 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1346 pkt
= unpack_int (pkt
, &tag
); /* tag */
1347 pkt
= unpack_byte (pkt
, &length
); /* length */
1348 if (!(tag
& mask
)) /* tags out of synch with mask */
1350 warning ("ERROR RMT: threadinfo tag mismatch\n");
1354 if (tag
== TAG_THREADID
)
1358 warning ("ERROR RMT: length of threadid is not 16\n");
1362 pkt
= unpack_threadid (pkt
, &ref
);
1363 mask
= mask
& ~TAG_THREADID
;
1366 if (tag
== TAG_EXISTS
)
1368 info
->active
= stub_unpack_int (pkt
, length
);
1370 mask
= mask
& ~(TAG_EXISTS
);
1373 warning ("ERROR RMT: 'exists' length too long\n");
1379 if (tag
== TAG_THREADNAME
)
1381 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1382 mask
= mask
& ~TAG_THREADNAME
;
1385 if (tag
== TAG_DISPLAY
)
1387 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1388 mask
= mask
& ~TAG_DISPLAY
;
1391 if (tag
== TAG_MOREDISPLAY
)
1393 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1394 mask
= mask
& ~TAG_MOREDISPLAY
;
1397 warning ("ERROR RMT: unknown thread info tag\n");
1398 break; /* Not a tag we know about */
1404 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1405 struct gdb_ext_thread_info
*info
)
1408 char *threadinfo_pkt
= alloca (PBUFSIZ
);
1410 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1411 putpkt (threadinfo_pkt
);
1412 getpkt (threadinfo_pkt
, PBUFSIZ
, 0);
1413 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1418 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1419 representation of a threadid. */
1422 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1423 struct gdb_ext_thread_info
*info
)
1427 int_to_threadref (&lclref
, *ref
);
1428 return remote_get_threadinfo (&lclref
, selection
, info
);
1431 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1434 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1435 threadref
*nextthread
)
1437 *pkt
++ = 'q'; /* info query packet */
1438 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1439 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1440 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1441 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1446 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1449 parse_threadlist_response (char *pkt
, int result_limit
,
1450 threadref
*original_echo
, threadref
*resultlist
,
1454 int count
, resultcount
, done
;
1457 /* Assume the 'q' and 'M chars have been stripped. */
1458 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1459 pkt
= unpack_byte (pkt
, &count
); /* count field */
1460 pkt
= unpack_nibble (pkt
, &done
);
1461 /* The first threadid is the argument threadid. */
1462 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1463 while ((count
-- > 0) && (pkt
< limit
))
1465 pkt
= unpack_threadid (pkt
, resultlist
++);
1466 if (resultcount
++ >= result_limit
)
1475 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1476 int *done
, int *result_count
, threadref
*threadlist
)
1478 static threadref echo_nextthread
;
1479 char *threadlist_packet
= alloca (PBUFSIZ
);
1480 char *t_response
= alloca (PBUFSIZ
);
1483 /* Trancate result limit to be smaller than the packet size */
1484 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1485 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1487 pack_threadlist_request (threadlist_packet
,
1488 startflag
, result_limit
, nextthread
);
1489 putpkt (threadlist_packet
);
1490 getpkt (t_response
, PBUFSIZ
, 0);
1493 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1496 if (!threadmatch (&echo_nextthread
, nextthread
))
1498 /* FIXME: This is a good reason to drop the packet */
1499 /* Possably, there is a duplicate response */
1501 retransmit immediatly - race conditions
1502 retransmit after timeout - yes
1504 wait for packet, then exit
1506 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1507 return 0; /* I choose simply exiting */
1509 if (*result_count
<= 0)
1513 warning ("RMT ERROR : failed to get remote thread list\n");
1516 return result
; /* break; */
1518 if (*result_count
> result_limit
)
1521 warning ("RMT ERROR: threadlist response longer than requested\n");
1527 /* This is the interface between remote and threads, remotes upper interface */
1529 /* remote_find_new_threads retrieves the thread list and for each
1530 thread in the list, looks up the thread in GDB's internal list,
1531 ading the thread if it does not already exist. This involves
1532 getting partial thread lists from the remote target so, polling the
1533 quit_flag is required. */
1536 /* About this many threadisds fit in a packet. */
1538 #define MAXTHREADLISTRESULTS 32
1541 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1544 int done
, i
, result_count
;
1548 static threadref nextthread
;
1549 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1554 if (loopcount
++ > looplimit
)
1557 warning ("Remote fetch threadlist -infinite loop-\n");
1560 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1561 &done
, &result_count
, resultthreadlist
))
1566 /* clear for later iterations */
1568 /* Setup to resume next batch of thread references, set nextthread. */
1569 if (result_count
>= 1)
1570 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1572 while (result_count
--)
1573 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1580 remote_newthread_step (threadref
*ref
, void *context
)
1584 pid
= threadref_to_int (ref
);
1585 if (!in_thread_list (pid
))
1587 return 1; /* continue iterator */
1590 #define CRAZY_MAX_THREADS 1000
1593 remote_current_thread (int oldpid
)
1595 char *buf
= alloca (PBUFSIZ
);
1598 getpkt (buf
, PBUFSIZ
, 0);
1599 if (buf
[0] == 'Q' && buf
[1] == 'C')
1600 return strtol (&buf
[2], NULL
, 16);
1605 /* Find new threads for info threads command.
1606 * Original version, using John Metzler's thread protocol.
1610 remote_find_new_threads (void)
1612 remote_threadlist_iterator (remote_newthread_step
, 0,
1614 if (inferior_pid
== MAGIC_NULL_PID
) /* ack ack ack */
1615 inferior_pid
= remote_current_thread (inferior_pid
);
1619 * Find all threads for info threads command.
1620 * Uses new thread protocol contributed by Cisco.
1621 * Falls back and attempts to use the older method (above)
1622 * if the target doesn't respond to the new method.
1626 remote_threads_info (void)
1628 char *buf
= alloca (PBUFSIZ
);
1632 if (remote_desc
== 0) /* paranoia */
1633 error ("Command can only be used when connected to the remote target.");
1635 if (use_threadinfo_query
)
1637 putpkt ("qfThreadInfo");
1639 getpkt (bufp
, PBUFSIZ
, 0);
1640 if (bufp
[0] != '\0') /* q packet recognized */
1642 while (*bufp
++ == 'm') /* reply contains one or more TID */
1646 tid
= strtol (bufp
, &bufp
, 16);
1647 if (tid
!= 0 && !in_thread_list (tid
))
1650 while (*bufp
++ == ','); /* comma-separated list */
1651 putpkt ("qsThreadInfo");
1653 getpkt (bufp
, PBUFSIZ
, 0);
1659 /* Else fall back to old method based on jmetzler protocol. */
1660 use_threadinfo_query
= 0;
1661 remote_find_new_threads ();
1666 * Collect a descriptive string about the given thread.
1667 * The target may say anything it wants to about the thread
1668 * (typically info about its blocked / runnable state, name, etc.).
1669 * This string will appear in the info threads display.
1671 * Optional: targets are not required to implement this function.
1675 remote_threads_extra_info (struct thread_info
*tp
)
1680 struct gdb_ext_thread_info threadinfo
;
1681 static char display_buf
[100]; /* arbitrary... */
1682 char *bufp
= alloca (PBUFSIZ
);
1683 int n
= 0; /* position in display_buf */
1685 if (remote_desc
== 0) /* paranoia */
1686 internal_error (__FILE__
, __LINE__
,
1687 "remote_threads_extra_info");
1689 if (use_threadextra_query
)
1691 sprintf (bufp
, "qThreadExtraInfo,%x", tp
->pid
);
1693 getpkt (bufp
, PBUFSIZ
, 0);
1698 for (p
= display_buf
;
1699 p
< display_buf
+ sizeof(display_buf
) - 1 &&
1704 *p
= fromhex (bufp
[0]) * 16 + fromhex (bufp
[1]);
1711 /* If the above query fails, fall back to the old method. */
1712 use_threadextra_query
= 0;
1713 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1714 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1715 int_to_threadref (&id
, tp
->pid
);
1716 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1717 if (threadinfo
.active
)
1719 if (*threadinfo
.shortname
)
1720 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1721 if (*threadinfo
.display
)
1722 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1723 if (*threadinfo
.more_display
)
1724 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1725 threadinfo
.more_display
);
1729 /* for purely cosmetic reasons, clear up trailing commas */
1730 if (',' == display_buf
[n
-1])
1731 display_buf
[n
-1] = ' ';
1740 /* Restart the remote side; this is an extended protocol operation. */
1743 extended_remote_restart (void)
1745 char *buf
= alloca (PBUFSIZ
);
1747 /* Send the restart command; for reasons I don't understand the
1748 remote side really expects a number after the "R". */
1750 sprintf (&buf
[1], "%x", 0);
1753 /* Now query for status so this looks just like we restarted
1754 gdbserver from scratch. */
1756 getpkt (buf
, PBUFSIZ
, 0);
1759 /* Clean up connection to a remote debugger. */
1763 remote_close (int quitting
)
1766 SERIAL_CLOSE (remote_desc
);
1770 /* Query the remote side for the text, data and bss offsets. */
1775 char *buf
= alloca (PBUFSIZ
);
1778 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1779 struct section_offsets
*offs
;
1781 putpkt ("qOffsets");
1783 getpkt (buf
, PBUFSIZ
, 0);
1785 if (buf
[0] == '\000')
1786 return; /* Return silently. Stub doesn't support
1790 warning ("Remote failure reply: %s", buf
);
1794 /* Pick up each field in turn. This used to be done with scanf, but
1795 scanf will make trouble if CORE_ADDR size doesn't match
1796 conversion directives correctly. The following code will work
1797 with any size of CORE_ADDR. */
1798 text_addr
= data_addr
= bss_addr
= 0;
1802 if (strncmp (ptr
, "Text=", 5) == 0)
1805 /* Don't use strtol, could lose on big values. */
1806 while (*ptr
&& *ptr
!= ';')
1807 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1812 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1815 while (*ptr
&& *ptr
!= ';')
1816 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1821 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1824 while (*ptr
&& *ptr
!= ';')
1825 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1831 error ("Malformed response to offset query, %s", buf
);
1833 if (symfile_objfile
== NULL
)
1836 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1837 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1839 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1841 /* This is a temporary kludge to force data and bss to use the same offsets
1842 because that's what nlmconv does now. The real solution requires changes
1843 to the stub and remote.c that I don't have time to do right now. */
1845 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
1846 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
1848 objfile_relocate (symfile_objfile
, offs
);
1852 * Cisco version of section offsets:
1854 * Instead of having GDB query the target for the section offsets,
1855 * Cisco lets the target volunteer the information! It's also in
1856 * a different format, so here are the functions that will decode
1857 * a section offset packet from a Cisco target.
1861 * Function: remote_cisco_section_offsets
1863 * Returns: zero for success, non-zero for failure
1867 remote_cisco_section_offsets (bfd_vma text_addr
,
1870 bfd_signed_vma
*text_offs
,
1871 bfd_signed_vma
*data_offs
,
1872 bfd_signed_vma
*bss_offs
)
1874 bfd_vma text_base
, data_base
, bss_base
;
1875 struct minimal_symbol
*start
;
1880 if (symfile_objfile
== NULL
)
1881 return -1; /* no can do nothin' */
1883 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
1885 return -1; /* Can't find "_start" symbol */
1887 data_base
= bss_base
= 0;
1888 text_base
= SYMBOL_VALUE_ADDRESS (start
);
1890 abfd
= symfile_objfile
->obfd
;
1891 for (sect
= abfd
->sections
;
1895 const char *p
= bfd_get_section_name (abfd
, sect
);
1897 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
1898 if (data_base
== 0 ||
1899 data_base
> bfd_get_section_vma (abfd
, sect
))
1900 data_base
= bfd_get_section_vma (abfd
, sect
);
1901 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
1902 if (bss_base
== 0 ||
1903 bss_base
> bfd_get_section_vma (abfd
, sect
))
1904 bss_base
= bfd_get_section_vma (abfd
, sect
);
1906 *text_offs
= text_addr
- text_base
;
1907 *data_offs
= data_addr
- data_base
;
1908 *bss_offs
= bss_addr
- bss_base
;
1913 sprintf (tmp
, "VMA: text = 0x");
1914 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
1915 sprintf (tmp
+ strlen (tmp
), " data = 0x");
1916 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
1917 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
1918 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
1919 fprintf_filtered (gdb_stdlog
, tmp
);
1920 fprintf_filtered (gdb_stdlog
,
1921 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
1922 paddr_nz (*text_offs
),
1923 paddr_nz (*data_offs
),
1924 paddr_nz (*bss_offs
));
1931 * Function: remote_cisco_objfile_relocate
1933 * Relocate the symbol file for a remote target.
1937 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
1938 bfd_signed_vma bss_off
)
1940 struct section_offsets
*offs
;
1942 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
1944 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1945 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1946 simple canonical representation for this stuff. */
1948 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1949 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1951 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
1952 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
1953 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
1955 /* First call the standard objfile_relocate. */
1956 objfile_relocate (symfile_objfile
, offs
);
1958 /* Now we need to fix up the section entries already attached to
1959 the exec target. These entries will control memory transfers
1960 from the exec file. */
1962 exec_set_section_offsets (text_off
, data_off
, bss_off
);
1966 /* Stub for catch_errors. */
1969 remote_start_remote_dummy (void *dummy
)
1971 start_remote (); /* Initialize gdb process mechanisms */
1976 remote_start_remote (PTR dummy
)
1978 immediate_quit
++; /* Allow user to interrupt it */
1980 /* Ack any packet which the remote side has already sent. */
1981 SERIAL_WRITE (remote_desc
, "+", 1);
1983 /* Let the stub know that we want it to return the thread. */
1986 inferior_pid
= remote_current_thread (inferior_pid
);
1988 get_offsets (); /* Get text, data & bss offsets */
1990 putpkt ("?"); /* initiate a query from remote machine */
1993 return remote_start_remote_dummy (dummy
);
1996 /* Open a connection to a remote debugger.
1997 NAME is the filename used for communication. */
2000 remote_open (char *name
, int from_tty
)
2002 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
2005 /* Just like remote_open, but with asynchronous support. */
2007 remote_async_open (char *name
, int from_tty
)
2009 remote_async_open_1 (name
, from_tty
, &remote_async_ops
, 0);
2012 /* Open a connection to a remote debugger using the extended
2013 remote gdb protocol. NAME is the filename used for communication. */
2016 extended_remote_open (char *name
, int from_tty
)
2018 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */ );
2021 /* Just like extended_remote_open, but with asynchronous support. */
2023 extended_remote_async_open (char *name
, int from_tty
)
2025 remote_async_open_1 (name
, from_tty
, &extended_async_remote_ops
, 1 /*extended_p */ );
2028 /* Generic code for opening a connection to a remote target. */
2031 init_all_packet_configs (void)
2034 update_packet_config (&remote_protocol_P
);
2035 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2036 update_packet_config (&remote_protocol_Z
[i
]);
2037 /* Force remote_write_bytes to check whether target supports binary
2039 update_packet_config (&remote_protocol_binary_download
);
2043 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2047 error ("To open a remote debug connection, you need to specify what\n\
2048 serial device is attached to the remote system\n\
2049 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2051 /* See FIXME above */
2052 wait_forever_enabled_p
= 1;
2054 target_preopen (from_tty
);
2056 unpush_target (target
);
2058 remote_desc
= SERIAL_OPEN (name
);
2060 perror_with_name (name
);
2062 if (baud_rate
!= -1)
2064 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
2066 SERIAL_CLOSE (remote_desc
);
2067 perror_with_name (name
);
2071 SERIAL_RAW (remote_desc
);
2073 /* If there is something sitting in the buffer we might take it as a
2074 response to a command, which would be bad. */
2075 SERIAL_FLUSH_INPUT (remote_desc
);
2079 puts_filtered ("Remote debugging using ");
2080 puts_filtered (name
);
2081 puts_filtered ("\n");
2083 push_target (target
); /* Switch to using remote target now */
2085 init_all_packet_configs ();
2087 general_thread
= -2;
2088 continue_thread
= -2;
2090 /* Probe for ability to use "ThreadInfo" query, as required. */
2091 use_threadinfo_query
= 1;
2092 use_threadextra_query
= 1;
2094 /* Without this, some commands which require an active target (such
2095 as kill) won't work. This variable serves (at least) double duty
2096 as both the pid of the target process (if it has such), and as a
2097 flag indicating that a target is active. These functions should
2098 be split out into seperate variables, especially since GDB will
2099 someday have a notion of debugging several processes. */
2101 inferior_pid
= MAGIC_NULL_PID
;
2102 /* Start the remote connection; if error (0), discard this target.
2103 In particular, if the user quits, be sure to discard it
2104 (we'd be in an inconsistent state otherwise). */
2105 if (!catch_errors (remote_start_remote
, NULL
,
2106 "Couldn't establish connection to remote target\n",
2115 /* tell the remote that we're using the extended protocol. */
2116 char *buf
= alloca (PBUFSIZ
);
2118 getpkt (buf
, PBUFSIZ
, 0);
2122 /* Just like remote_open but with asynchronous support. */
2124 remote_async_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2128 error ("To open a remote debug connection, you need to specify what\n\
2129 serial device is attached to the remote system\n\
2130 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2132 target_preopen (from_tty
);
2134 unpush_target (target
);
2136 remote_desc
= SERIAL_OPEN (name
);
2138 perror_with_name (name
);
2140 if (baud_rate
!= -1)
2142 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
2144 SERIAL_CLOSE (remote_desc
);
2145 perror_with_name (name
);
2149 SERIAL_RAW (remote_desc
);
2151 /* If there is something sitting in the buffer we might take it as a
2152 response to a command, which would be bad. */
2153 SERIAL_FLUSH_INPUT (remote_desc
);
2157 puts_filtered ("Remote debugging using ");
2158 puts_filtered (name
);
2159 puts_filtered ("\n");
2162 push_target (target
); /* Switch to using remote target now */
2164 init_all_packet_configs ();
2166 general_thread
= -2;
2167 continue_thread
= -2;
2169 /* Probe for ability to use "ThreadInfo" query, as required. */
2170 use_threadinfo_query
= 1;
2171 use_threadextra_query
= 1;
2173 /* Without this, some commands which require an active target (such
2174 as kill) won't work. This variable serves (at least) double duty
2175 as both the pid of the target process (if it has such), and as a
2176 flag indicating that a target is active. These functions should
2177 be split out into seperate variables, especially since GDB will
2178 someday have a notion of debugging several processes. */
2179 inferior_pid
= MAGIC_NULL_PID
;
2181 /* With this target we start out by owning the terminal. */
2182 remote_async_terminal_ours_p
= 1;
2184 /* FIXME: cagney/1999-09-23: During the initial connection it is
2185 assumed that the target is already ready and able to respond to
2186 requests. Unfortunately remote_start_remote() eventually calls
2187 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2188 around this. Eventually a mechanism that allows
2189 wait_for_inferior() to expect/get timeouts will be
2191 wait_forever_enabled_p
= 0;
2193 /* Start the remote connection; if error (0), discard this target.
2194 In particular, if the user quits, be sure to discard it
2195 (we'd be in an inconsistent state otherwise). */
2196 if (!catch_errors (remote_start_remote
, NULL
,
2197 "Couldn't establish connection to remote target\n",
2201 wait_forever_enabled_p
= 1;
2205 wait_forever_enabled_p
= 1;
2209 /* tell the remote that we're using the extended protocol. */
2210 char *buf
= alloca (PBUFSIZ
);
2212 getpkt (buf
, PBUFSIZ
, 0);
2216 /* This takes a program previously attached to and detaches it. After
2217 this is done, GDB can be used to debug some other program. We
2218 better not have left any breakpoints in the target program or it'll
2219 die when it hits one. */
2222 remote_detach (char *args
, int from_tty
)
2224 char *buf
= alloca (PBUFSIZ
);
2227 error ("Argument given to \"detach\" when remotely debugging.");
2229 /* Tell the remote target to detach. */
2231 remote_send (buf
, PBUFSIZ
);
2233 target_mourn_inferior ();
2235 puts_filtered ("Ending remote debugging.\n");
2239 /* Same as remote_detach, but with async support. */
2241 remote_async_detach (char *args
, int from_tty
)
2243 char *buf
= alloca (PBUFSIZ
);
2246 error ("Argument given to \"detach\" when remotely debugging.");
2248 /* Tell the remote target to detach. */
2250 remote_send (buf
, PBUFSIZ
);
2252 /* Unregister the file descriptor from the event loop. */
2253 if (target_is_async_p ())
2254 SERIAL_ASYNC (remote_desc
, NULL
, 0);
2256 target_mourn_inferior ();
2258 puts_filtered ("Ending remote debugging.\n");
2261 /* Convert hex digit A to a number. */
2266 if (a
>= '0' && a
<= '9')
2268 else if (a
>= 'a' && a
<= 'f')
2269 return a
- 'a' + 10;
2270 else if (a
>= 'A' && a
<= 'F')
2271 return a
- 'A' + 10;
2273 error ("Reply contains invalid hex digit %d", a
);
2276 /* Convert number NIB to a hex digit. */
2284 return 'a' + nib
- 10;
2287 /* Tell the remote machine to resume. */
2289 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2291 static int last_sent_step
;
2294 remote_resume (int pid
, int step
, enum target_signal siggnal
)
2296 char *buf
= alloca (PBUFSIZ
);
2299 set_thread (0, 0); /* run any thread */
2301 set_thread (pid
, 0); /* run this thread */
2303 last_sent_signal
= siggnal
;
2304 last_sent_step
= step
;
2306 /* A hook for when we need to do something at the last moment before
2308 if (target_resume_hook
)
2309 (*target_resume_hook
) ();
2311 if (siggnal
!= TARGET_SIGNAL_0
)
2313 buf
[0] = step
? 'S' : 'C';
2314 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2315 buf
[2] = tohex ((int) siggnal
& 0xf);
2319 strcpy (buf
, step
? "s" : "c");
2324 /* Same as remote_resume, but with async support. */
2326 remote_async_resume (int pid
, int step
, enum target_signal siggnal
)
2328 char *buf
= alloca (PBUFSIZ
);
2331 set_thread (0, 0); /* run any thread */
2333 set_thread (pid
, 0); /* run this thread */
2335 last_sent_signal
= siggnal
;
2336 last_sent_step
= step
;
2338 /* A hook for when we need to do something at the last moment before
2340 if (target_resume_hook
)
2341 (*target_resume_hook
) ();
2343 if (siggnal
!= TARGET_SIGNAL_0
)
2345 buf
[0] = step
? 'S' : 'C';
2346 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2347 buf
[2] = tohex ((int) siggnal
& 0xf);
2351 strcpy (buf
, step
? "s" : "c");
2353 /* We are about to start executing the inferior, let's register it
2354 with the event loop. NOTE: this is the one place where all the
2355 execution commands end up. We could alternatively do this in each
2356 of the execution commands in infcmd.c.*/
2357 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2358 into infcmd.c in order to allow inferior function calls to work
2359 NOT asynchronously. */
2360 if (event_loop_p
&& target_can_async_p ())
2361 target_async (inferior_event_handler
, 0);
2362 /* Tell the world that the target is now executing. */
2363 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2364 this? Instead, should the client of target just assume (for
2365 async targets) that the target is going to start executing? Is
2366 this information already found in the continuation block? */
2367 if (target_is_async_p ())
2368 target_executing
= 1;
2373 /* Set up the signal handler for SIGINT, while the target is
2374 executing, ovewriting the 'regular' SIGINT signal handler. */
2376 initialize_sigint_signal_handler (void)
2378 sigint_remote_token
=
2379 create_async_signal_handler (async_remote_interrupt
, NULL
);
2380 signal (SIGINT
, handle_remote_sigint
);
2383 /* Signal handler for SIGINT, while the target is executing. */
2385 handle_remote_sigint (int sig
)
2387 signal (sig
, handle_remote_sigint_twice
);
2388 sigint_remote_twice_token
=
2389 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2390 mark_async_signal_handler_wrapper (sigint_remote_token
);
2393 /* Signal handler for SIGINT, installed after SIGINT has already been
2394 sent once. It will take effect the second time that the user sends
2397 handle_remote_sigint_twice (int sig
)
2399 signal (sig
, handle_sigint
);
2400 sigint_remote_twice_token
=
2401 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2402 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2405 /* Perform the real interruption of the target execution, in response
2408 async_remote_interrupt (gdb_client_data arg
)
2411 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2416 /* Perform interrupt, if the first attempt did not succeed. Just give
2417 up on the target alltogether. */
2419 async_remote_interrupt_twice (gdb_client_data arg
)
2422 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2423 /* Do something only if the target was not killed by the previous
2425 if (target_executing
)
2428 signal (SIGINT
, handle_remote_sigint
);
2432 /* Reinstall the usual SIGINT handlers, after the target has
2435 cleanup_sigint_signal_handler (void *dummy
)
2437 signal (SIGINT
, handle_sigint
);
2438 if (sigint_remote_twice_token
)
2439 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2440 if (sigint_remote_token
)
2441 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2444 /* Send ^C to target to halt it. Target will respond, and send us a
2446 static void (*ofunc
) (int);
2448 /* The command line interface's stop routine. This function is installed
2449 as a signal handler for SIGINT. The first time a user requests a
2450 stop, we call remote_stop to send a break or ^C. If there is no
2451 response from the target (it didn't stop when the user requested it),
2452 we ask the user if he'd like to detach from the target. */
2454 remote_interrupt (int signo
)
2456 /* If this doesn't work, try more severe steps. */
2457 signal (signo
, remote_interrupt_twice
);
2460 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2465 /* The user typed ^C twice. */
2468 remote_interrupt_twice (int signo
)
2470 signal (signo
, ofunc
);
2472 signal (signo
, remote_interrupt
);
2475 /* This is the generic stop called via the target vector. When a target
2476 interrupt is requested, either by the command line or the GUI, we
2477 will eventually end up here. */
2481 /* Send a break or a ^C, depending on user preference. */
2483 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2486 SERIAL_SEND_BREAK (remote_desc
);
2488 SERIAL_WRITE (remote_desc
, "\003", 1);
2491 /* Ask the user what to do when an interrupt is received. */
2494 interrupt_query (void)
2496 target_terminal_ours ();
2498 if (query ("Interrupted while waiting for the program.\n\
2499 Give up (and stop debugging it)? "))
2501 target_mourn_inferior ();
2502 return_to_top_level (RETURN_QUIT
);
2505 target_terminal_inferior ();
2508 /* Enable/disable target terminal ownership. Most targets can use
2509 terminal groups to control terminal ownership. Remote targets are
2510 different in that explicit transfer of ownership to/from GDB/target
2514 remote_async_terminal_inferior (void)
2516 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2517 sync_execution here. This function should only be called when
2518 GDB is resuming the inferior in the forground. A background
2519 resume (``run&'') should leave GDB in control of the terminal and
2520 consequently should not call this code. */
2521 if (!sync_execution
)
2523 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2524 calls target_terminal_*() idenpotent. The event-loop GDB talking
2525 to an asynchronous target with a synchronous command calls this
2526 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2527 stops trying to transfer the terminal to the target when it
2528 shouldn't this guard can go away. */
2529 if (!remote_async_terminal_ours_p
)
2531 delete_file_handler (input_fd
);
2532 remote_async_terminal_ours_p
= 0;
2533 initialize_sigint_signal_handler ();
2534 /* NOTE: At this point we could also register our selves as the
2535 recipient of all input. Any characters typed could then be
2536 passed on down to the target. */
2540 remote_async_terminal_ours (void)
2542 /* See FIXME in remote_async_terminal_inferior. */
2543 if (!sync_execution
)
2545 /* See FIXME in remote_async_terminal_inferior. */
2546 if (remote_async_terminal_ours_p
)
2548 cleanup_sigint_signal_handler (NULL
);
2549 add_file_handler (input_fd
, stdin_event_handler
, 0);
2550 remote_async_terminal_ours_p
= 1;
2553 /* If nonzero, ignore the next kill. */
2558 remote_console_output (char *msg
)
2562 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2565 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2568 fputs_unfiltered (tb
, gdb_stdtarg
);
2570 gdb_flush (gdb_stdtarg
);
2573 /* Wait until the remote machine stops, then return,
2574 storing status in STATUS just as `wait' would.
2575 Returns "pid", which in the case of a multi-threaded
2576 remote OS, is the thread-id. */
2579 remote_wait (int pid
, struct target_waitstatus
*status
)
2581 unsigned char *buf
= alloca (PBUFSIZ
);
2582 int thread_num
= -1;
2584 status
->kind
= TARGET_WAITKIND_EXITED
;
2585 status
->value
.integer
= 0;
2591 ofunc
= signal (SIGINT
, remote_interrupt
);
2592 getpkt (buf
, PBUFSIZ
, 1);
2593 signal (SIGINT
, ofunc
);
2595 /* This is a hook for when we need to do something (perhaps the
2596 collection of trace data) every time the target stops. */
2597 if (target_wait_loop_hook
)
2598 (*target_wait_loop_hook
) ();
2602 case 'E': /* Error of some sort */
2603 warning ("Remote failure reply: %s", buf
);
2605 case 'T': /* Status with PC, SP, FP, ... */
2609 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
2611 /* Expedited reply, containing Signal, {regno, reg} repeat */
2612 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2614 n... = register number
2615 r... = register contents
2617 p
= &buf
[3]; /* after Txx */
2624 /* Read the register number */
2625 regno
= strtol ((const char *) p
, &p_temp
, 16);
2626 p1
= (unsigned char *) p_temp
;
2628 if (p1
== p
) /* No register number present here */
2630 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2632 warning ("Malformed packet(a) (missing colon): %s\n\
2635 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2637 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2638 record_currthread (thread_num
);
2639 p
= (unsigned char *) p_temp
;
2647 warning ("Malformed packet(b) (missing colon): %s\n\
2651 if (regno
>= NUM_REGS
)
2652 warning ("Remote sent bad register number %ld: %s\n\
2656 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2658 if (p
[0] == 0 || p
[1] == 0)
2659 warning ("Remote reply is too short: %s", buf
);
2660 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2663 supply_register (regno
, regs
);
2668 warning ("Remote register badly formatted: %s", buf
);
2669 warning (" here: %s", p
);
2674 case 'S': /* Old style status, just signal only */
2675 status
->kind
= TARGET_WAITKIND_STOPPED
;
2676 status
->value
.sig
= (enum target_signal
)
2677 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2681 /* Export Cisco kernel mode as a convenience variable
2682 (so that it can be used in the GDB prompt if desired). */
2684 if (cisco_kernel_mode
== 1)
2685 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2686 value_from_string ("PDEBUG-"));
2687 cisco_kernel_mode
= 0;
2688 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2689 record_currthread (thread_num
);
2691 else if (buf
[3] == 'k')
2693 /* Export Cisco kernel mode as a convenience variable
2694 (so that it can be used in the GDB prompt if desired). */
2696 if (cisco_kernel_mode
== 1)
2697 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2698 value_from_string ("KDEBUG-"));
2699 cisco_kernel_mode
= 1;
2702 case 'N': /* Cisco special: status and offsets */
2704 bfd_vma text_addr
, data_addr
, bss_addr
;
2705 bfd_signed_vma text_off
, data_off
, bss_off
;
2708 status
->kind
= TARGET_WAITKIND_STOPPED
;
2709 status
->value
.sig
= (enum target_signal
)
2710 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2712 if (symfile_objfile
== NULL
)
2714 warning ("Relocation packet received with no symbol file. \
2719 /* Relocate object file. Buffer format is NAATT;DD;BB
2720 * where AA is the signal number, TT is the new text
2721 * address, DD * is the new data address, and BB is the
2722 * new bss address. */
2725 text_addr
= strtoul (p
, (char **) &p1
, 16);
2726 if (p1
== p
|| *p1
!= ';')
2727 warning ("Malformed relocation packet: Packet '%s'", buf
);
2729 data_addr
= strtoul (p
, (char **) &p1
, 16);
2730 if (p1
== p
|| *p1
!= ';')
2731 warning ("Malformed relocation packet: Packet '%s'", buf
);
2733 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2735 warning ("Malformed relocation packet: Packet '%s'", buf
);
2737 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2738 &text_off
, &data_off
, &bss_off
)
2740 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2741 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2745 case 'W': /* Target exited */
2747 /* The remote process exited. */
2748 status
->kind
= TARGET_WAITKIND_EXITED
;
2749 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2753 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2754 status
->value
.sig
= (enum target_signal
)
2755 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2759 case 'O': /* Console output */
2760 remote_console_output (buf
+ 1);
2763 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2765 /* Zero length reply means that we tried 'S' or 'C' and
2766 the remote system doesn't support it. */
2767 target_terminal_ours_for_output ();
2769 ("Can't send signals to this remote system. %s not sent.\n",
2770 target_signal_to_name (last_sent_signal
));
2771 last_sent_signal
= TARGET_SIGNAL_0
;
2772 target_terminal_inferior ();
2774 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2775 putpkt ((char *) buf
);
2778 /* else fallthrough */
2780 warning ("Invalid remote reply: %s", buf
);
2785 if (thread_num
!= -1)
2789 return inferior_pid
;
2792 /* Async version of remote_wait. */
2794 remote_async_wait (int pid
, struct target_waitstatus
*status
)
2796 unsigned char *buf
= alloca (PBUFSIZ
);
2797 int thread_num
= -1;
2799 status
->kind
= TARGET_WAITKIND_EXITED
;
2800 status
->value
.integer
= 0;
2806 if (!target_is_async_p ())
2807 ofunc
= signal (SIGINT
, remote_interrupt
);
2808 /* FIXME: cagney/1999-09-27: If we're in async mode we should
2809 _never_ wait for ever -> test on target_is_async_p().
2810 However, before we do that we need to ensure that the caller
2811 knows how to take the target into/out of async mode. */
2812 getpkt (buf
, PBUFSIZ
, wait_forever_enabled_p
);
2813 if (!target_is_async_p ())
2814 signal (SIGINT
, ofunc
);
2816 /* This is a hook for when we need to do something (perhaps the
2817 collection of trace data) every time the target stops. */
2818 if (target_wait_loop_hook
)
2819 (*target_wait_loop_hook
) ();
2823 case 'E': /* Error of some sort */
2824 warning ("Remote failure reply: %s", buf
);
2826 case 'T': /* Status with PC, SP, FP, ... */
2830 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
2832 /* Expedited reply, containing Signal, {regno, reg} repeat */
2833 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2835 n... = register number
2836 r... = register contents
2838 p
= &buf
[3]; /* after Txx */
2845 /* Read the register number */
2846 regno
= strtol ((const char *) p
, &p_temp
, 16);
2847 p1
= (unsigned char *) p_temp
;
2849 if (p1
== p
) /* No register number present here */
2851 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2853 warning ("Malformed packet(a) (missing colon): %s\n\
2856 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2858 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2859 record_currthread (thread_num
);
2860 p
= (unsigned char *) p_temp
;
2868 warning ("Malformed packet(b) (missing colon): %s\n\
2872 if (regno
>= NUM_REGS
)
2873 warning ("Remote sent bad register number %ld: %s\n\
2877 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2879 if (p
[0] == 0 || p
[1] == 0)
2880 warning ("Remote reply is too short: %s", buf
);
2881 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2884 supply_register (regno
, regs
);
2889 warning ("Remote register badly formatted: %s", buf
);
2890 warning (" here: %s", p
);
2895 case 'S': /* Old style status, just signal only */
2896 status
->kind
= TARGET_WAITKIND_STOPPED
;
2897 status
->value
.sig
= (enum target_signal
)
2898 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2902 /* Export Cisco kernel mode as a convenience variable
2903 (so that it can be used in the GDB prompt if desired). */
2905 if (cisco_kernel_mode
== 1)
2906 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2907 value_from_string ("PDEBUG-"));
2908 cisco_kernel_mode
= 0;
2909 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2910 record_currthread (thread_num
);
2912 else if (buf
[3] == 'k')
2914 /* Export Cisco kernel mode as a convenience variable
2915 (so that it can be used in the GDB prompt if desired). */
2917 if (cisco_kernel_mode
== 1)
2918 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2919 value_from_string ("KDEBUG-"));
2920 cisco_kernel_mode
= 1;
2923 case 'N': /* Cisco special: status and offsets */
2925 bfd_vma text_addr
, data_addr
, bss_addr
;
2926 bfd_signed_vma text_off
, data_off
, bss_off
;
2929 status
->kind
= TARGET_WAITKIND_STOPPED
;
2930 status
->value
.sig
= (enum target_signal
)
2931 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2933 if (symfile_objfile
== NULL
)
2935 warning ("Relocation packet recieved with no symbol file. \
2940 /* Relocate object file. Buffer format is NAATT;DD;BB
2941 * where AA is the signal number, TT is the new text
2942 * address, DD * is the new data address, and BB is the
2943 * new bss address. */
2946 text_addr
= strtoul (p
, (char **) &p1
, 16);
2947 if (p1
== p
|| *p1
!= ';')
2948 warning ("Malformed relocation packet: Packet '%s'", buf
);
2950 data_addr
= strtoul (p
, (char **) &p1
, 16);
2951 if (p1
== p
|| *p1
!= ';')
2952 warning ("Malformed relocation packet: Packet '%s'", buf
);
2954 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2956 warning ("Malformed relocation packet: Packet '%s'", buf
);
2958 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2959 &text_off
, &data_off
, &bss_off
)
2961 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2962 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2966 case 'W': /* Target exited */
2968 /* The remote process exited. */
2969 status
->kind
= TARGET_WAITKIND_EXITED
;
2970 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2974 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2975 status
->value
.sig
= (enum target_signal
)
2976 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2980 case 'O': /* Console output */
2981 remote_console_output (buf
+ 1);
2982 /* Return immediately to the event loop. The event loop will
2983 still be waiting on the inferior afterwards. */
2984 status
->kind
= TARGET_WAITKIND_IGNORE
;
2987 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2989 /* Zero length reply means that we tried 'S' or 'C' and
2990 the remote system doesn't support it. */
2991 target_terminal_ours_for_output ();
2993 ("Can't send signals to this remote system. %s not sent.\n",
2994 target_signal_to_name (last_sent_signal
));
2995 last_sent_signal
= TARGET_SIGNAL_0
;
2996 target_terminal_inferior ();
2998 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2999 putpkt ((char *) buf
);
3002 /* else fallthrough */
3004 warning ("Invalid remote reply: %s", buf
);
3009 if (thread_num
!= -1)
3013 return inferior_pid
;
3016 /* Number of bytes of registers this stub implements. */
3018 static int register_bytes_found
;
3020 /* Read the remote registers into the block REGS. */
3021 /* Currently we just read all the registers, so we don't use regno. */
3025 remote_fetch_registers (int regno
)
3027 char *buf
= alloca (PBUFSIZ
);
3030 char *regs
= alloca (REGISTER_BYTES
);
3032 set_thread (inferior_pid
, 1);
3035 remote_send (buf
, PBUFSIZ
);
3037 /* Save the size of the packet sent to us by the target. Its used
3038 as a heuristic when determining the max size of packets that the
3039 target can safely receive. */
3040 if (actual_register_packet_size
== 0)
3041 actual_register_packet_size
= strlen (buf
);
3043 /* Unimplemented registers read as all bits zero. */
3044 memset (regs
, 0, REGISTER_BYTES
);
3046 /* We can get out of synch in various cases. If the first character
3047 in the buffer is not a hex character, assume that has happened
3048 and try to fetch another packet to read. */
3049 while ((buf
[0] < '0' || buf
[0] > '9')
3050 && (buf
[0] < 'a' || buf
[0] > 'f')
3051 && buf
[0] != 'x') /* New: unavailable register value */
3054 fprintf_unfiltered (gdb_stdlog
,
3055 "Bad register packet; fetching a new packet\n");
3056 getpkt (buf
, PBUFSIZ
, 0);
3059 /* Reply describes registers byte by byte, each byte encoded as two
3060 hex characters. Suck them all up, then supply them to the
3061 register cacheing/storage mechanism. */
3064 for (i
= 0; i
< REGISTER_BYTES
; i
++)
3070 warning ("Remote reply is of odd length: %s", buf
);
3071 /* Don't change register_bytes_found in this case, and don't
3072 print a second warning. */
3075 if (p
[0] == 'x' && p
[1] == 'x')
3076 regs
[i
] = 0; /* 'x' */
3078 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3082 if (i
!= register_bytes_found
)
3084 register_bytes_found
= i
;
3085 if (REGISTER_BYTES_OK_P ()
3086 && !REGISTER_BYTES_OK (i
))
3087 warning ("Remote reply is too short: %s", buf
);
3091 for (i
= 0; i
< NUM_REGS
; i
++)
3093 supply_register (i
, ®s
[REGISTER_BYTE (i
)]);
3094 if (buf
[REGISTER_BYTE (i
) * 2] == 'x')
3095 set_register_cached (i
, -1);
3099 /* Prepare to store registers. Since we may send them all (using a
3100 'G' request), we have to read out the ones we don't want to change
3104 remote_prepare_to_store (void)
3106 /* Make sure the entire registers array is valid. */
3107 switch (remote_protocol_P
.support
)
3109 case PACKET_DISABLE
:
3110 case PACKET_SUPPORT_UNKNOWN
:
3111 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
);
3118 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
3119 packet was not recognized. */
3122 store_register_using_P (int regno
)
3124 /* Try storing a single register. */
3125 char *buf
= alloca (PBUFSIZ
);
3130 sprintf (buf
, "P%x=", regno
);
3131 p
= buf
+ strlen (buf
);
3132 regp
= register_buffer (regno
);
3133 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
3135 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
3136 *p
++ = tohex (regp
[i
] & 0xf);
3139 remote_send (buf
, PBUFSIZ
);
3141 return buf
[0] != '\0';
3145 /* Store register REGNO, or all registers if REGNO == -1, from the contents
3146 of the register cache buffer. FIXME: ignores errors. */
3149 remote_store_registers (int regno
)
3151 char *buf
= alloca (PBUFSIZ
);
3156 set_thread (inferior_pid
, 1);
3160 switch (remote_protocol_P
.support
)
3162 case PACKET_DISABLE
:
3165 if (store_register_using_P (regno
))
3168 error ("Protocol error: P packet not recognized by stub");
3169 case PACKET_SUPPORT_UNKNOWN
:
3170 if (store_register_using_P (regno
))
3172 /* The stub recognized the 'P' packet. Remember this. */
3173 remote_protocol_P
.support
= PACKET_ENABLE
;
3178 /* The stub does not support the 'P' packet. Use 'G'
3179 instead, and don't try using 'P' in the future (it
3180 will just waste our time). */
3181 remote_protocol_P
.support
= PACKET_DISABLE
;
3189 /* Command describes registers byte by byte,
3190 each byte encoded as two hex characters. */
3192 regs
= register_buffer (-1);
3194 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3195 for (i
= 0; i
< register_bytes_found
; i
++)
3197 *p
++ = tohex ((regs
[i
] >> 4) & 0xf);
3198 *p
++ = tohex (regs
[i
] & 0xf);
3202 remote_send (buf
, PBUFSIZ
);
3206 /* Return the number of hex digits in num. */
3209 hexnumlen (ULONGEST num
)
3213 for (i
= 0; num
!= 0; i
++)
3219 /* Set BUF to the minimum number of hex digits representing NUM. */
3222 hexnumstr (char *buf
, ULONGEST num
)
3224 int len
= hexnumlen (num
);
3225 return hexnumnstr (buf
, num
, len
);
3229 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3232 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3238 for (i
= width
- 1; i
>= 0; i
--)
3240 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3247 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3250 remote_address_masked (CORE_ADDR addr
)
3252 if (remote_address_size
> 0
3253 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3255 /* Only create a mask when that mask can safely be constructed
3256 in a ULONGEST variable. */
3258 mask
= (mask
<< remote_address_size
) - 1;
3264 /* Determine whether the remote target supports binary downloading.
3265 This is accomplished by sending a no-op memory write of zero length
3266 to the target at the specified address. It does not suffice to send
3267 the whole packet, since many stubs strip the eighth bit and subsequently
3268 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3270 NOTE: This can still lose if the serial line is not eight-bit
3271 clean. In cases like this, the user should clear "remote
3275 check_binary_download (CORE_ADDR addr
)
3277 switch (remote_protocol_binary_download
.support
)
3279 case PACKET_DISABLE
:
3283 case PACKET_SUPPORT_UNKNOWN
:
3285 char *buf
= alloca (PBUFSIZ
);
3290 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3292 p
+= hexnumstr (p
, (ULONGEST
) 0);
3296 putpkt_binary (buf
, (int) (p
- buf
));
3297 getpkt (buf
, PBUFSIZ
, 0);
3302 fprintf_unfiltered (gdb_stdlog
,
3303 "binary downloading NOT suppported by target\n");
3304 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3309 fprintf_unfiltered (gdb_stdlog
,
3310 "binary downloading suppported by target\n");
3311 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3318 /* Write memory data directly to the remote machine.
3319 This does not inform the data cache; the data cache uses this.
3320 MEMADDR is the address in the remote memory space.
3321 MYADDR is the address of the buffer in our space.
3322 LEN is the number of bytes.
3324 Returns number of bytes transferred, or 0 (setting errno) for
3325 error. Only transfer a single packet. */
3328 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3331 int max_buf_size
; /* Max size of packet output buffer */
3333 unsigned char *plen
;
3339 /* Verify that the target can support a binary download */
3340 check_binary_download (memaddr
);
3342 /* Determine the max packet size. */
3343 max_buf_size
= get_memory_write_packet_size ();
3344 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3345 buf
= alloca (sizeof_buf
);
3347 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3348 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3350 /* construct "M"<memaddr>","<len>":" */
3351 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3354 /* Append [XM]. Compute a best guess of the number of bytes
3355 actually transfered. */
3356 switch (remote_protocol_binary_download
.support
)
3360 /* Best guess at number of bytes that will fit. */
3361 todo
= min (len
, max_buf_size
);
3363 case PACKET_DISABLE
:
3365 /* num bytes that will fit */
3366 todo
= min (len
, max_buf_size
/ 2);
3368 case PACKET_SUPPORT_UNKNOWN
:
3369 internal_error (__FILE__
, __LINE__
,
3370 "remote_write_bytes: bad internal state");
3372 internal_error (__FILE__
, __LINE__
, "bad switch");
3375 /* Append <memaddr> */
3376 memaddr
= remote_address_masked (memaddr
);
3377 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3380 /* Append <len>. Retain the location/size of <len>. It may
3381 need to be adjusted once the packet body has been created. */
3383 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3388 /* Append the packet body. */
3389 switch (remote_protocol_binary_download
.support
)
3392 /* Binary mode. Send target system values byte by byte, in
3393 increasing byte addresses. Only escape certain critical
3396 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3399 switch (myaddr
[nr_bytes
] & 0xff)
3404 /* These must be escaped */
3406 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3409 *p
++ = myaddr
[nr_bytes
] & 0xff;
3413 if (nr_bytes
< todo
)
3415 /* Escape chars have filled up the buffer prematurely,
3416 and we have actually sent fewer bytes than planned.
3417 Fix-up the length field of the packet. Use the same
3418 number of characters as before. */
3420 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3421 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3424 case PACKET_DISABLE
:
3425 /* Normal mode: Send target system values byte by byte, in
3426 increasing byte addresses. Each byte is encoded as a two hex
3428 for (nr_bytes
= 0; nr_bytes
< todo
; nr_bytes
++)
3430 *p
++ = tohex ((myaddr
[nr_bytes
] >> 4) & 0xf);
3431 *p
++ = tohex (myaddr
[nr_bytes
] & 0xf);
3435 case PACKET_SUPPORT_UNKNOWN
:
3436 internal_error (__FILE__
, __LINE__
,
3437 "remote_write_bytes: bad internal state");
3439 internal_error (__FILE__
, __LINE__
, "bad switch");
3442 putpkt_binary (buf
, (int) (p
- buf
));
3443 getpkt (buf
, sizeof_buf
, 0);
3447 /* There is no correspondance between what the remote protocol
3448 uses for errors and errno codes. We would like a cleaner way
3449 of representing errors (big enough to include errno codes,
3450 bfd_error codes, and others). But for now just return EIO. */
3455 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3456 bytes than we'd planned. */
3460 /* Read memory data directly from the remote machine.
3461 This does not use the data cache; the data cache uses this.
3462 MEMADDR is the address in the remote memory space.
3463 MYADDR is the address of the buffer in our space.
3464 LEN is the number of bytes.
3466 Returns number of bytes transferred, or 0 for error. */
3468 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3469 remote targets) shouldn't attempt to read the entire buffer.
3470 Instead it should read a single packet worth of data and then
3471 return the byte size of that packet to the caller. The caller (its
3472 caller and its callers caller ;-) already contains code for
3473 handling partial reads. */
3476 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3479 int max_buf_size
; /* Max size of packet output buffer */
3483 /* Create a buffer big enough for this packet. */
3484 max_buf_size
= get_memory_read_packet_size ();
3485 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3486 buf
= alloca (sizeof_buf
);
3495 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3497 /* construct "m"<memaddr>","<len>" */
3498 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3499 memaddr
= remote_address_masked (memaddr
);
3502 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3504 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3508 getpkt (buf
, sizeof_buf
, 0);
3512 /* There is no correspondance between what the remote protocol uses
3513 for errors and errno codes. We would like a cleaner way of
3514 representing errors (big enough to include errno codes, bfd_error
3515 codes, and others). But for now just return EIO. */
3520 /* Reply describes memory byte by byte,
3521 each byte encoded as two hex characters. */
3524 for (i
= 0; i
< todo
; i
++)
3526 if (p
[0] == 0 || p
[1] == 0)
3527 /* Reply is short. This means that we were able to read
3528 only part of what we wanted to. */
3529 return i
+ (origlen
- len
);
3530 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3540 /* Read or write LEN bytes from inferior memory at MEMADDR,
3541 transferring to or from debugger address BUFFER. Write to inferior if
3542 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3543 for error. TARGET is unused. */
3547 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3549 struct mem_attrib
*attrib ATTRIBUTE_UNUSED
,
3550 struct target_ops
*target
)
3552 CORE_ADDR targ_addr
;
3556 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3561 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3563 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3570 /* Enable after 4.12. */
3573 remote_search (int len
, char *data
, char *mask
, CORE_ADDR startaddr
,
3574 int increment
, CORE_ADDR lorange
, CORE_ADDR hirange
,
3575 CORE_ADDR
*addr_found
, char *data_found
)
3577 if (increment
== -4 && len
== 4)
3579 long mask_long
, data_long
;
3580 long data_found_long
;
3581 CORE_ADDR addr_we_found
;
3582 char *buf
= alloca (PBUFSIZ
);
3583 long returned_long
[2];
3586 mask_long
= extract_unsigned_integer (mask
, len
);
3587 data_long
= extract_unsigned_integer (data
, len
);
3588 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
3590 getpkt (buf
, PBUFSIZ
, 0);
3593 /* The stub doesn't support the 't' request. We might want to
3594 remember this fact, but on the other hand the stub could be
3595 switched on us. Maybe we should remember it only until
3596 the next "target remote". */
3597 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3598 hirange
, addr_found
, data_found
);
3603 /* There is no correspondance between what the remote protocol uses
3604 for errors and errno codes. We would like a cleaner way of
3605 representing errors (big enough to include errno codes, bfd_error
3606 codes, and others). But for now just use EIO. */
3607 memory_error (EIO
, startaddr
);
3610 while (*p
!= '\0' && *p
!= ',')
3611 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
3613 error ("Protocol error: short return for search");
3615 data_found_long
= 0;
3616 while (*p
!= '\0' && *p
!= ',')
3617 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
3618 /* Ignore anything after this comma, for future extensions. */
3620 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
3626 *addr_found
= addr_we_found
;
3627 *data_found
= store_unsigned_integer (data_we_found
, len
);
3630 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3631 hirange
, addr_found
, data_found
);
3636 remote_files_info (struct target_ops
*ignore
)
3638 puts_filtered ("Debugging a target over a serial line.\n");
3641 /* Stuff for dealing with the packets which are part of this protocol.
3642 See comment at top of file for details. */
3644 /* Read a single character from the remote end, masking it down to 7 bits. */
3647 readchar (int timeout
)
3651 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
3656 switch ((enum serial_rc
) ch
)
3659 target_mourn_inferior ();
3660 error ("Remote connection closed");
3663 perror_with_name ("Remote communication error");
3665 case SERIAL_TIMEOUT
:
3671 /* Send the command in BUF to the remote machine, and read the reply
3672 into BUF. Report an error if we get an error reply. */
3675 remote_send (char *buf
,
3679 getpkt (buf
, sizeof_buf
, 0);
3682 error ("Remote failure reply: %s", buf
);
3685 /* Display a null-terminated packet on stdout, for debugging, using C
3689 print_packet (char *buf
)
3691 puts_filtered ("\"");
3692 fputstr_filtered (buf
, '"', gdb_stdout
);
3693 puts_filtered ("\"");
3699 return putpkt_binary (buf
, strlen (buf
));
3702 /* Send a packet to the remote machine, with error checking. The data
3703 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3704 to account for the $, # and checksum, and for a possible /0 if we are
3705 debugging (remote_debug) and want to print the sent packet as a string */
3708 putpkt_binary (char *buf
, int cnt
)
3711 unsigned char csum
= 0;
3712 char *buf2
= alloca (cnt
+ 6);
3713 long sizeof_junkbuf
= PBUFSIZ
;
3714 char *junkbuf
= alloca (sizeof_junkbuf
);
3720 /* Copy the packet into buffer BUF2, encapsulating it
3721 and giving it a checksum. */
3726 for (i
= 0; i
< cnt
; i
++)
3732 *p
++ = tohex ((csum
>> 4) & 0xf);
3733 *p
++ = tohex (csum
& 0xf);
3735 /* Send it over and over until we get a positive ack. */
3739 int started_error_output
= 0;
3744 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
3745 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
3746 fprintf_unfiltered (gdb_stdlog
, "...");
3747 gdb_flush (gdb_stdlog
);
3749 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
3750 perror_with_name ("putpkt: write failed");
3752 /* read until either a timeout occurs (-2) or '+' is read */
3755 ch
= readchar (remote_timeout
);
3763 case SERIAL_TIMEOUT
:
3765 if (started_error_output
)
3767 putchar_unfiltered ('\n');
3768 started_error_output
= 0;
3777 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
3781 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
3782 case SERIAL_TIMEOUT
:
3786 break; /* Retransmit buffer */
3790 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
3791 /* It's probably an old response, and we're out of sync.
3792 Just gobble up the packet and ignore it. */
3793 read_frame (junkbuf
, sizeof_junkbuf
);
3794 continue; /* Now, go look for + */
3799 if (!started_error_output
)
3801 started_error_output
= 1;
3802 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
3804 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
3808 break; /* Here to retransmit */
3812 /* This is wrong. If doing a long backtrace, the user should be
3813 able to get out next time we call QUIT, without anything as
3814 violent as interrupt_query. If we want to provide a way out of
3815 here without getting to the next QUIT, it should be based on
3816 hitting ^C twice as in remote_wait. */
3826 static int remote_cisco_mode
;
3828 /* Come here after finding the start of the frame. Collect the rest
3829 into BUF, verifying the checksum, length, and handling run-length
3830 compression. No more than sizeof_buf-1 characters are read so that
3831 the buffer can be NUL terminated.
3833 Returns -1 on error, number of characters in buffer (ignoring the
3834 trailing NULL) on success. (could be extended to return one of the
3835 SERIAL status indications). */
3838 read_frame (char *buf
,
3850 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
3851 c
= readchar (remote_timeout
);
3854 case SERIAL_TIMEOUT
:
3856 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
3860 fputs_filtered ("Saw new packet start in middle of old one\n",
3862 return -1; /* Start a new packet, count retries */
3865 unsigned char pktcsum
;
3871 check_0
= readchar (remote_timeout
);
3873 check_1
= readchar (remote_timeout
);
3875 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
3878 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
3881 else if (check_0
< 0 || check_1
< 0)
3884 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
3888 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
3889 if (csum
== pktcsum
)
3894 fprintf_filtered (gdb_stdlog
,
3895 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3897 fputs_filtered (buf
, gdb_stdlog
);
3898 fputs_filtered ("\n", gdb_stdlog
);
3900 /* Number of characters in buffer ignoring trailing
3904 case '*': /* Run length encoding */
3909 if (remote_cisco_mode
== 0)
3911 c
= readchar (remote_timeout
);
3913 repeat
= c
- ' ' + 3; /* Compute repeat count */
3917 /* Cisco's run-length encoding variant uses two
3918 hex chars to represent the repeat count. */
3920 c
= readchar (remote_timeout
);
3922 repeat
= fromhex (c
) << 4;
3923 c
= readchar (remote_timeout
);
3925 repeat
+= fromhex (c
);
3928 /* The character before ``*'' is repeated. */
3930 if (repeat
> 0 && repeat
<= 255
3932 && bc
+ repeat
< sizeof_buf
- 1)
3934 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
3940 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
3941 puts_filtered (buf
);
3942 puts_filtered ("\n");
3946 if (bc
< sizeof_buf
- 1)
3954 puts_filtered ("Remote packet too long: ");
3955 puts_filtered (buf
);
3956 puts_filtered ("\n");
3963 /* Read a packet from the remote machine, with error checking, and
3964 store it in BUF. If FOREVER, wait forever rather than timing out;
3965 this is used (in synchronous mode) to wait for a target that is is
3966 executing user code to stop. */
3967 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
3968 don't have to change all the calls to getpkt to deal with the
3969 return value, because at the moment I don't know what the right
3970 thing to do it for those. */
3978 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
3982 /* Read a packet from the remote machine, with error checking, and
3983 store it in BUF. If FOREVER, wait forever rather than timing out;
3984 this is used (in synchronous mode) to wait for a target that is is
3985 executing user code to stop. If FOREVER == 0, this function is
3986 allowed to time out gracefully and return an indication of this to
3989 getpkt_sane (char *buf
,
3998 strcpy (buf
, "timeout");
4002 timeout
= watchdog
> 0 ? watchdog
: -1;
4006 timeout
= remote_timeout
;
4010 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4012 /* This can loop forever if the remote side sends us characters
4013 continuously, but if it pauses, we'll get a zero from readchar
4014 because of timeout. Then we'll count that as a retry. */
4016 /* Note that we will only wait forever prior to the start of a packet.
4017 After that, we expect characters to arrive at a brisk pace. They
4018 should show up within remote_timeout intervals. */
4022 c
= readchar (timeout
);
4024 if (c
== SERIAL_TIMEOUT
)
4026 if (forever
) /* Watchdog went off? Kill the target. */
4029 target_mourn_inferior ();
4030 error ("Watchdog has expired. Target detached.\n");
4033 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4039 /* We've found the start of a packet, now collect the data. */
4041 val
= read_frame (buf
, sizeof_buf
);
4047 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4048 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4049 fprintf_unfiltered (gdb_stdlog
, "\n");
4051 SERIAL_WRITE (remote_desc
, "+", 1);
4055 /* Try the whole thing again. */
4057 SERIAL_WRITE (remote_desc
, "-", 1);
4060 /* We have tried hard enough, and just can't receive the packet. Give up. */
4062 printf_unfiltered ("Ignoring packet error, continuing...\n");
4063 SERIAL_WRITE (remote_desc
, "+", 1);
4070 /* For some mysterious reason, wait_for_inferior calls kill instead of
4071 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4075 target_mourn_inferior ();
4079 /* Use catch_errors so the user can quit from gdb even when we aren't on
4080 speaking terms with the remote system. */
4081 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4083 /* Don't wait for it to die. I'm not really sure it matters whether
4084 we do or not. For the existing stubs, kill is a noop. */
4085 target_mourn_inferior ();
4088 /* Async version of remote_kill. */
4090 remote_async_kill (void)
4092 /* Unregister the file descriptor from the event loop. */
4093 if (target_is_async_p ())
4094 SERIAL_ASYNC (remote_desc
, NULL
, 0);
4096 /* For some mysterious reason, wait_for_inferior calls kill instead of
4097 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4101 target_mourn_inferior ();
4105 /* Use catch_errors so the user can quit from gdb even when we aren't on
4106 speaking terms with the remote system. */
4107 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4109 /* Don't wait for it to die. I'm not really sure it matters whether
4110 we do or not. For the existing stubs, kill is a noop. */
4111 target_mourn_inferior ();
4117 remote_mourn_1 (&remote_ops
);
4121 remote_async_mourn (void)
4123 remote_mourn_1 (&remote_async_ops
);
4127 extended_remote_mourn (void)
4129 /* We do _not_ want to mourn the target like this; this will
4130 remove the extended remote target from the target stack,
4131 and the next time the user says "run" it'll fail.
4133 FIXME: What is the right thing to do here? */
4135 remote_mourn_1 (&extended_remote_ops
);
4139 /* Worker function for remote_mourn. */
4141 remote_mourn_1 (struct target_ops
*target
)
4143 unpush_target (target
);
4144 generic_mourn_inferior ();
4147 /* In the extended protocol we want to be able to do things like
4148 "run" and have them basically work as expected. So we need
4149 a special create_inferior function.
4151 FIXME: One day add support for changing the exec file
4152 we're debugging, arguments and an environment. */
4155 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4157 /* Rip out the breakpoints; we'll reinsert them after restarting
4158 the remote server. */
4159 remove_breakpoints ();
4161 /* Now restart the remote server. */
4162 extended_remote_restart ();
4164 /* Now put the breakpoints back in. This way we're safe if the
4165 restart function works via a unix fork on the remote side. */
4166 insert_breakpoints ();
4168 /* Clean up from the last time we were running. */
4169 clear_proceed_status ();
4171 /* Let the remote process run. */
4172 proceed (-1, TARGET_SIGNAL_0
, 0);
4175 /* Async version of extended_remote_create_inferior. */
4177 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4179 /* Rip out the breakpoints; we'll reinsert them after restarting
4180 the remote server. */
4181 remove_breakpoints ();
4183 /* If running asynchronously, register the target file descriptor
4184 with the event loop. */
4185 if (event_loop_p
&& target_can_async_p ())
4186 target_async (inferior_event_handler
, 0);
4188 /* Now restart the remote server. */
4189 extended_remote_restart ();
4191 /* Now put the breakpoints back in. This way we're safe if the
4192 restart function works via a unix fork on the remote side. */
4193 insert_breakpoints ();
4195 /* Clean up from the last time we were running. */
4196 clear_proceed_status ();
4198 /* Let the remote process run. */
4199 proceed (-1, TARGET_SIGNAL_0
, 0);
4203 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4204 than other targets; in those use REMOTE_BREAKPOINT instead of just
4205 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4206 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4207 the standard routines that are in mem-break.c. */
4209 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4210 the choice of breakpoint instruction affects target program design and
4211 vice versa, and by making it user-tweakable, the special code here
4212 goes away and we need fewer special GDB configurations. */
4214 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4215 #define REMOTE_BREAKPOINT
4218 #ifdef REMOTE_BREAKPOINT
4220 /* If the target isn't bi-endian, just pretend it is. */
4221 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4222 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4223 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4226 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
4227 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
4229 #endif /* REMOTE_BREAKPOINT */
4231 /* Insert a breakpoint on targets that don't have any better breakpoint
4232 support. We read the contents of the target location and stash it,
4233 then overwrite it with a breakpoint instruction. ADDR is the target
4234 location in the target machine. CONTENTS_CACHE is a pointer to
4235 memory allocated for saving the target contents. It is guaranteed
4236 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4237 is accomplished via BREAKPOINT_MAX). */
4240 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4242 #ifdef REMOTE_BREAKPOINT
4247 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4248 If it succeeds, then set the support to PACKET_ENABLE. If it
4249 fails, and the user has explicitly requested the Z support then
4250 report an error, otherwise, mark it disabled and go on. */
4252 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4254 char *buf
= alloca (PBUFSIZ
);
4257 addr
= remote_address_masked (addr
);
4261 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4262 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4263 sprintf (p
, ",%d", bp_size
);
4266 getpkt (buf
, PBUFSIZ
, 0);
4268 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4274 case PACKET_UNKNOWN
:
4279 #ifdef REMOTE_BREAKPOINT
4280 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4284 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
4285 val
= target_write_memory (addr
, (char *) big_break_insn
,
4286 sizeof big_break_insn
);
4288 val
= target_write_memory (addr
, (char *) little_break_insn
,
4289 sizeof little_break_insn
);
4294 return memory_insert_breakpoint (addr
, contents_cache
);
4295 #endif /* REMOTE_BREAKPOINT */
4299 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4303 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4305 char *buf
= alloca (PBUFSIZ
);
4312 addr
= remote_address_masked (addr
);
4313 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4314 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4315 sprintf (p
, ",%d", bp_size
);
4318 getpkt (buf
, PBUFSIZ
, 0);
4320 return (buf
[0] == 'E');
4323 #ifdef REMOTE_BREAKPOINT
4324 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4326 return memory_remove_breakpoint (addr
, contents_cache
);
4327 #endif /* REMOTE_BREAKPOINT */
4331 watchpoint_to_Z_packet (int type
)
4345 internal_error (__FILE__
, __LINE__
,
4346 "hw_bp_to_z: bad watchpoint type %d", type
);
4350 /* FIXME: This function should be static and a member of the remote
4354 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4356 char *buf
= alloca (PBUFSIZ
);
4358 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4360 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4361 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4362 remote_protocol_Z
[packet
].name
,
4363 remote_protocol_Z
[packet
].title
);
4365 sprintf (buf
, "Z%x,", packet
);
4366 p
= strchr (buf
, '\0');
4367 addr
= remote_address_masked (addr
);
4368 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4369 sprintf (p
, ",%x", len
);
4372 getpkt (buf
, PBUFSIZ
, 0);
4374 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4377 case PACKET_UNKNOWN
:
4382 internal_error (__FILE__
, __LINE__
,
4383 "remote_insert_watchpoint: reached end of function");
4386 /* FIXME: This function should be static and a member of the remote
4390 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4392 char *buf
= alloca (PBUFSIZ
);
4394 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4396 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4397 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4398 remote_protocol_Z
[packet
].name
,
4399 remote_protocol_Z
[packet
].title
);
4401 sprintf (buf
, "z%x,", packet
);
4402 p
= strchr (buf
, '\0');
4403 addr
= remote_address_masked (addr
);
4404 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4405 sprintf (p
, ",%x", len
);
4407 getpkt (buf
, PBUFSIZ
, 0);
4409 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4412 case PACKET_UNKNOWN
:
4417 internal_error (__FILE__
, __LINE__
,
4418 "remote_remove_watchpoint: reached end of function");
4421 /* FIXME: This function should be static and a member of the remote
4425 remote_insert_hw_breakpoint (CORE_ADDR addr
, int len
)
4427 char *buf
= alloca (PBUFSIZ
);
4430 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4431 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4432 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4433 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4439 addr
= remote_address_masked (addr
);
4440 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4441 sprintf (p
, ",%x", len
);
4444 getpkt (buf
, PBUFSIZ
, 0);
4446 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4449 case PACKET_UNKNOWN
:
4454 internal_error (__FILE__
, __LINE__
,
4455 "remote_remove_watchpoint: reached end of function");
4458 /* FIXME: This function should be static and a member of the remote
4462 remote_remove_hw_breakpoint (CORE_ADDR addr
, int len
)
4464 char *buf
= alloca (PBUFSIZ
);
4467 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4468 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4469 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4470 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4476 addr
= remote_address_masked (addr
);
4477 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4478 sprintf (p
, ",%x", len
);
4481 getpkt (buf
, PBUFSIZ
, 0);
4483 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4486 case PACKET_UNKNOWN
:
4491 internal_error (__FILE__
, __LINE__
,
4492 "remote_remove_watchpoint: reached end of function");
4495 /* Some targets are only capable of doing downloads, and afterwards
4496 they switch to the remote serial protocol. This function provides
4497 a clean way to get from the download target to the remote target.
4498 It's basically just a wrapper so that we don't have to expose any
4499 of the internal workings of remote.c.
4501 Prior to calling this routine, you should shutdown the current
4502 target code, else you will get the "A program is being debugged
4503 already..." message. Usually a call to pop_target() suffices. */
4506 push_remote_target (char *name
, int from_tty
)
4508 printf_filtered ("Switching to remote protocol\n");
4509 remote_open (name
, from_tty
);
4512 /* Other targets want to use the entire remote serial module but with
4513 certain remote_ops overridden. */
4516 open_remote_target (char *name
, int from_tty
, struct target_ops
*target
,
4519 printf_filtered ("Selecting the %sremote protocol\n",
4520 (extended_p
? "extended-" : ""));
4521 remote_open_1 (name
, from_tty
, target
, extended_p
);
4524 /* Table used by the crc32 function to calcuate the checksum. */
4526 static unsigned long crc32_table
[256] =
4529 static unsigned long
4530 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4532 if (!crc32_table
[1])
4534 /* Initialize the CRC table and the decoding table. */
4538 for (i
= 0; i
< 256; i
++)
4540 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4541 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4548 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4554 /* compare-sections command
4556 With no arguments, compares each loadable section in the exec bfd
4557 with the same memory range on the target, and reports mismatches.
4558 Useful for verifying the image on the target against the exec file.
4559 Depends on the target understanding the new "qCRC:" request. */
4561 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4562 target method (target verify memory) and generic version of the
4563 actual command. This will allow other high-level code (especially
4564 generic_load()) to make use of this target functionality. */
4567 compare_sections_command (char *args
, int from_tty
)
4570 unsigned long host_crc
, target_crc
;
4571 extern bfd
*exec_bfd
;
4572 struct cleanup
*old_chain
;
4575 const char *sectname
;
4576 char *buf
= alloca (PBUFSIZ
);
4583 error ("command cannot be used without an exec file");
4584 if (!current_target
.to_shortname
||
4585 strcmp (current_target
.to_shortname
, "remote") != 0)
4586 error ("command can only be used with remote target");
4588 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4590 if (!(s
->flags
& SEC_LOAD
))
4591 continue; /* skip non-loadable section */
4593 size
= bfd_get_section_size_before_reloc (s
);
4595 continue; /* skip zero-length section */
4597 sectname
= bfd_get_section_name (exec_bfd
, s
);
4598 if (args
&& strcmp (args
, sectname
) != 0)
4599 continue; /* not the section selected by user */
4601 matched
= 1; /* do this section */
4603 /* FIXME: assumes lma can fit into long */
4604 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
4607 /* be clever; compute the host_crc before waiting for target reply */
4608 sectdata
= xmalloc (size
);
4609 old_chain
= make_cleanup (xfree
, sectdata
);
4610 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4611 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4613 getpkt (buf
, PBUFSIZ
, 0);
4615 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4616 sectname
, lma
, lma
+ size
);
4618 error ("remote target does not support this operation");
4620 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4621 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4623 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4624 sectname
, paddr (lma
), paddr (lma
+ size
));
4625 if (host_crc
== target_crc
)
4626 printf_filtered ("matched.\n");
4629 printf_filtered ("MIS-MATCHED!\n");
4633 do_cleanups (old_chain
);
4636 warning ("One or more sections of the remote executable does not match\n\
4637 the loaded file\n");
4638 if (args
&& !matched
)
4639 printf_filtered ("No loaded section named '%s'.\n", args
);
4643 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
4646 char *buf2
= alloca (PBUFSIZ
);
4647 char *p2
= &buf2
[0];
4650 error ("null pointer to remote bufer size specified");
4652 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4653 the caller know and return what the minimum size is */
4654 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4655 if (*bufsiz
< PBUFSIZ
)
4661 /* except for querying the minimum buffer size, target must be open */
4663 error ("remote query is only available after target open");
4665 /* we only take uppercase letters as query types, at least for now */
4666 if ((query_type
< 'A') || (query_type
> 'Z'))
4667 error ("invalid remote query type");
4670 error ("null remote query specified");
4673 error ("remote query requires a buffer to receive data");
4680 /* we used one buffer char for the remote protocol q command and another
4681 for the query type. As the remote protocol encapsulation uses 4 chars
4682 plus one extra in case we are debugging (remote_debug),
4683 we have PBUFZIZ - 7 left to pack the query string */
4685 while (buf
[i
] && (i
< (PBUFSIZ
- 8)))
4687 /* bad caller may have sent forbidden characters */
4688 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
4689 error ("illegal characters in query string");
4697 error ("query larger than available buffer");
4703 getpkt (outbuf
, *bufsiz
, 0);
4709 remote_rcmd (char *command
,
4710 struct ui_file
*outbuf
)
4713 char *buf
= alloca (PBUFSIZ
);
4717 error ("remote rcmd is only available after target open");
4719 /* Send a NULL command across as an empty command */
4720 if (command
== NULL
)
4723 /* The query prefix */
4724 strcpy (buf
, "qRcmd,");
4725 p
= strchr (buf
, '\0');
4727 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > PBUFSIZ
)
4728 error ("\"monitor\" command ``%s'' is too long\n", command
);
4730 /* Encode the actual command */
4731 for (i
= 0; command
[i
]; i
++)
4733 *p
++ = tohex ((command
[i
] >> 4) & 0xf);
4734 *p
++ = tohex (command
[i
] & 0xf);
4738 if (putpkt (buf
) < 0)
4739 error ("Communication problem with target\n");
4741 /* get/display the response */
4744 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4746 getpkt (buf
, PBUFSIZ
, 0);
4748 error ("Target does not support this command\n");
4749 if (buf
[0] == 'O' && buf
[1] != 'K')
4751 remote_console_output (buf
+ 1); /* 'O' message from stub */
4754 if (strcmp (buf
, "OK") == 0)
4756 if (strlen (buf
) == 3 && buf
[0] == 'E'
4757 && isdigit (buf
[1]) && isdigit (buf
[2]))
4759 error ("Protocol error with Rcmd");
4761 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
4763 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
4764 fputc_unfiltered (c
, outbuf
);
4771 packet_command (char *args
, int from_tty
)
4773 char *buf
= alloca (PBUFSIZ
);
4776 error ("command can only be used with remote target");
4779 error ("remote-packet command requires packet text as argument");
4781 puts_filtered ("sending: ");
4782 print_packet (args
);
4783 puts_filtered ("\n");
4786 getpkt (buf
, PBUFSIZ
, 0);
4787 puts_filtered ("received: ");
4789 puts_filtered ("\n");
4793 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4795 static void display_thread_info (struct gdb_ext_thread_info
*info
);
4797 static void threadset_test_cmd (char *cmd
, int tty
);
4799 static void threadalive_test (char *cmd
, int tty
);
4801 static void threadlist_test_cmd (char *cmd
, int tty
);
4803 int get_and_display_threadinfo (threadref
* ref
);
4805 static void threadinfo_test_cmd (char *cmd
, int tty
);
4807 static int thread_display_step (threadref
* ref
, void *context
);
4809 static void threadlist_update_test_cmd (char *cmd
, int tty
);
4811 static void init_remote_threadtests (void);
4813 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4816 threadset_test_cmd (char *cmd
, int tty
)
4818 int sample_thread
= SAMPLE_THREAD
;
4820 printf_filtered ("Remote threadset test\n");
4821 set_thread (sample_thread
, 1);
4826 threadalive_test (char *cmd
, int tty
)
4828 int sample_thread
= SAMPLE_THREAD
;
4830 if (remote_thread_alive (sample_thread
))
4831 printf_filtered ("PASS: Thread alive test\n");
4833 printf_filtered ("FAIL: Thread alive test\n");
4836 void output_threadid (char *title
, threadref
* ref
);
4839 output_threadid (char *title
, threadref
*ref
)
4843 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
4845 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
4849 threadlist_test_cmd (char *cmd
, int tty
)
4852 threadref nextthread
;
4853 int done
, result_count
;
4854 threadref threadlist
[3];
4856 printf_filtered ("Remote Threadlist test\n");
4857 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
4858 &result_count
, &threadlist
[0]))
4859 printf_filtered ("FAIL: threadlist test\n");
4862 threadref
*scan
= threadlist
;
4863 threadref
*limit
= scan
+ result_count
;
4865 while (scan
< limit
)
4866 output_threadid (" thread ", scan
++);
4871 display_thread_info (struct gdb_ext_thread_info
*info
)
4873 output_threadid ("Threadid: ", &info
->threadid
);
4874 printf_filtered ("Name: %s\n ", info
->shortname
);
4875 printf_filtered ("State: %s\n", info
->display
);
4876 printf_filtered ("other: %s\n\n", info
->more_display
);
4880 get_and_display_threadinfo (threadref
*ref
)
4884 struct gdb_ext_thread_info threadinfo
;
4886 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
4887 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
4888 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
4889 display_thread_info (&threadinfo
);
4894 threadinfo_test_cmd (char *cmd
, int tty
)
4896 int athread
= SAMPLE_THREAD
;
4900 int_to_threadref (&thread
, athread
);
4901 printf_filtered ("Remote Threadinfo test\n");
4902 if (!get_and_display_threadinfo (&thread
))
4903 printf_filtered ("FAIL cannot get thread info\n");
4907 thread_display_step (threadref
*ref
, void *context
)
4909 /* output_threadid(" threadstep ",ref); *//* simple test */
4910 return get_and_display_threadinfo (ref
);
4914 threadlist_update_test_cmd (char *cmd
, int tty
)
4916 printf_filtered ("Remote Threadlist update test\n");
4917 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
4921 init_remote_threadtests (void)
4923 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
4924 "Fetch and print the remote list of thread identifiers, one pkt only");
4925 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
4926 "Fetch and display info about one thread");
4927 add_com ("tset", class_obscure
, threadset_test_cmd
,
4928 "Test setting to a different thread");
4929 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
4930 "Iterate through updating all remote thread info");
4931 add_com ("talive", class_obscure
, threadalive_test
,
4932 " Remote thread alive test ");
4938 init_remote_ops (void)
4940 remote_ops
.to_shortname
= "remote";
4941 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
4943 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4944 Specify the serial device it is connected to\n\
4945 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
4946 remote_ops
.to_open
= remote_open
;
4947 remote_ops
.to_close
= remote_close
;
4948 remote_ops
.to_detach
= remote_detach
;
4949 remote_ops
.to_resume
= remote_resume
;
4950 remote_ops
.to_wait
= remote_wait
;
4951 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
4952 remote_ops
.to_store_registers
= remote_store_registers
;
4953 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
4954 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
4955 remote_ops
.to_files_info
= remote_files_info
;
4956 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
4957 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
4958 remote_ops
.to_kill
= remote_kill
;
4959 remote_ops
.to_load
= generic_load
;
4960 remote_ops
.to_mourn_inferior
= remote_mourn
;
4961 remote_ops
.to_thread_alive
= remote_thread_alive
;
4962 remote_ops
.to_find_new_threads
= remote_threads_info
;
4963 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
4964 remote_ops
.to_stop
= remote_stop
;
4965 remote_ops
.to_query
= remote_query
;
4966 remote_ops
.to_rcmd
= remote_rcmd
;
4967 remote_ops
.to_stratum
= process_stratum
;
4968 remote_ops
.to_has_all_memory
= 1;
4969 remote_ops
.to_has_memory
= 1;
4970 remote_ops
.to_has_stack
= 1;
4971 remote_ops
.to_has_registers
= 1;
4972 remote_ops
.to_has_execution
= 1;
4973 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
4974 remote_ops
.to_magic
= OPS_MAGIC
;
4977 /* Set up the extended remote vector by making a copy of the standard
4978 remote vector and adding to it. */
4981 init_extended_remote_ops (void)
4983 extended_remote_ops
= remote_ops
;
4985 extended_remote_ops
.to_shortname
= "extended-remote";
4986 extended_remote_ops
.to_longname
=
4987 "Extended remote serial target in gdb-specific protocol";
4988 extended_remote_ops
.to_doc
=
4989 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4990 Specify the serial device it is connected to (e.g. /dev/ttya).",
4991 extended_remote_ops
.to_open
= extended_remote_open
;
4992 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
4993 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
4997 * Command: info remote-process
4999 * This implements Cisco's version of the "info proc" command.
5001 * This query allows the target stub to return an arbitrary string
5002 * (or strings) giving arbitrary information about the target process.
5003 * This is optional; the target stub isn't required to implement it.
5005 * Syntax: qfProcessInfo request first string
5006 * qsProcessInfo request subsequent string
5007 * reply: 'O'<hex-encoded-string>
5008 * 'l' last reply (empty)
5012 remote_info_process (char *args
, int from_tty
)
5014 char *buf
= alloca (PBUFSIZ
);
5016 if (remote_desc
== 0)
5017 error ("Command can only be used when connected to the remote target.");
5019 putpkt ("qfProcessInfo");
5020 getpkt (buf
, PBUFSIZ
, 0);
5022 return; /* Silently: target does not support this feature. */
5025 error ("info proc: target error.");
5027 while (buf
[0] == 'O') /* Capitol-O packet */
5029 remote_console_output (&buf
[1]);
5030 putpkt ("qsProcessInfo");
5031 getpkt (buf
, PBUFSIZ
, 0);
5040 remote_cisco_open (char *name
, int from_tty
)
5044 "To open a remote debug connection, you need to specify what \n\
5045 device is attached to the remote system (e.g. host:port).");
5047 /* See FIXME above */
5048 wait_forever_enabled_p
= 1;
5050 target_preopen (from_tty
);
5052 unpush_target (&remote_cisco_ops
);
5054 remote_desc
= SERIAL_OPEN (name
);
5056 perror_with_name (name
);
5059 * If a baud rate was specified on the gdb command line it will
5060 * be greater than the initial value of -1. If it is, use it otherwise
5064 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5065 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
5067 SERIAL_CLOSE (remote_desc
);
5068 perror_with_name (name
);
5071 SERIAL_RAW (remote_desc
);
5073 /* If there is something sitting in the buffer we might take it as a
5074 response to a command, which would be bad. */
5075 SERIAL_FLUSH_INPUT (remote_desc
);
5079 puts_filtered ("Remote debugging using ");
5080 puts_filtered (name
);
5081 puts_filtered ("\n");
5084 remote_cisco_mode
= 1;
5086 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5088 init_all_packet_configs ();
5090 general_thread
= -2;
5091 continue_thread
= -2;
5093 /* Probe for ability to use "ThreadInfo" query, as required. */
5094 use_threadinfo_query
= 1;
5095 use_threadextra_query
= 1;
5097 /* Without this, some commands which require an active target (such
5098 as kill) won't work. This variable serves (at least) double duty
5099 as both the pid of the target process (if it has such), and as a
5100 flag indicating that a target is active. These functions should
5101 be split out into seperate variables, especially since GDB will
5102 someday have a notion of debugging several processes. */
5103 inferior_pid
= MAGIC_NULL_PID
;
5105 /* Start the remote connection; if error (0), discard this target. */
5107 if (!catch_errors (remote_start_remote_dummy
, (char *) 0,
5108 "Couldn't establish connection to remote target\n",
5117 remote_cisco_close (int quitting
)
5119 remote_cisco_mode
= 0;
5120 remote_close (quitting
);
5124 remote_cisco_mourn (void)
5126 remote_mourn_1 (&remote_cisco_ops
);
5138 /* shared between readsocket() and readtty() */
5139 static char *tty_input
;
5141 static int escape_count
;
5142 static int echo_check
;
5143 extern int quit_flag
;
5150 /* Loop until the socket doesn't have any more data */
5152 while ((data
= readchar (0)) >= 0)
5154 /* Check for the escape sequence */
5157 /* If this is the fourth escape, get out */
5158 if (++escape_count
== 4)
5163 { /* This is a '|', but not the fourth in a row.
5164 Continue without echoing it. If it isn't actually
5165 one of four in a row, it'll be echoed later. */
5172 /* Ensure any pending '|'s are flushed. */
5174 for (; escape_count
> 0; escape_count
--)
5178 if (data
== '\r') /* If this is a return character, */
5179 continue; /* - just supress it. */
5181 if (echo_check
!= -1) /* Check for echo of user input. */
5183 if (tty_input
[echo_check
] == data
)
5185 echo_check
++; /* Character matched user input: */
5186 continue; /* Continue without echoing it. */
5188 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5189 { /* End of the line (and of echo checking). */
5190 echo_check
= -1; /* No more echo supression */
5191 continue; /* Continue without echoing. */
5194 { /* Failed check for echo of user input.
5195 We now have some suppressed output to flush! */
5198 for (j
= 0; j
< echo_check
; j
++)
5199 putchar (tty_input
[j
]);
5203 putchar (data
); /* Default case: output the char. */
5206 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5207 return READ_MORE
; /* Try to read some more */
5209 return FATAL_ERROR
; /* Trouble, bail out */
5217 /* First, read a buffer full from the terminal */
5218 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5219 if (tty_bytecount
== -1)
5221 perror ("readtty: read failed");
5225 /* Remove a quoted newline. */
5226 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5227 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5229 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5230 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5233 /* Turn trailing newlines into returns */
5234 if (tty_input
[tty_bytecount
- 1] == '\n')
5235 tty_input
[tty_bytecount
- 1] = '\r';
5237 /* If the line consists of a ~, enter debugging mode. */
5238 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5241 /* Make this a zero terminated string and write it out */
5242 tty_input
[tty_bytecount
] = 0;
5243 if (SERIAL_WRITE (remote_desc
, tty_input
, tty_bytecount
))
5245 perror_with_name ("readtty: write failed");
5255 fd_set input
; /* file descriptors for select */
5256 int tablesize
; /* max number of FDs for select */
5260 extern int escape_count
; /* global shared by readsocket */
5261 extern int echo_check
; /* ditto */
5266 tablesize
= 8 * sizeof (input
);
5270 /* Check for anything from our socket - doesn't block. Note that
5271 this must be done *before* the select as there may be
5272 buffered I/O waiting to be processed. */
5274 if ((status
= readsocket ()) == FATAL_ERROR
)
5276 error ("Debugging terminated by communications error");
5278 else if (status
!= READ_MORE
)
5283 fflush (stdout
); /* Flush output before blocking */
5285 /* Now block on more socket input or TTY input */
5288 FD_SET (fileno (stdin
), &input
);
5289 FD_SET (DEPRECATED_SERIAL_FD (remote_desc
), &input
);
5291 status
= select (tablesize
, &input
, 0, 0, 0);
5292 if ((status
== -1) && (errno
!= EINTR
))
5294 error ("Communications error on select %d", errno
);
5297 /* Handle Control-C typed */
5301 if ((++quit_count
) == 2)
5303 if (query ("Interrupt GDB? "))
5305 printf_filtered ("Interrupted by user.\n");
5306 return_to_top_level (RETURN_QUIT
);
5313 SERIAL_SEND_BREAK (remote_desc
);
5315 SERIAL_WRITE (remote_desc
, "\003", 1);
5320 /* Handle console input */
5322 if (FD_ISSET (fileno (stdin
), &input
))
5326 status
= readtty ();
5327 if (status
== READ_MORE
)
5330 return status
; /* telnet session ended */
5336 remote_cisco_wait (int pid
, struct target_waitstatus
*status
)
5338 if (minitelnet () != ENTER_DEBUG
)
5340 error ("Debugging session terminated by protocol error");
5343 return remote_wait (pid
, status
);
5347 init_remote_cisco_ops (void)
5349 remote_cisco_ops
.to_shortname
= "cisco";
5350 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5351 remote_cisco_ops
.to_doc
=
5352 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5353 Specify the serial device it is connected to (e.g. host:2020).";
5354 remote_cisco_ops
.to_open
= remote_cisco_open
;
5355 remote_cisco_ops
.to_close
= remote_cisco_close
;
5356 remote_cisco_ops
.to_detach
= remote_detach
;
5357 remote_cisco_ops
.to_resume
= remote_resume
;
5358 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5359 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5360 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5361 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5362 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5363 remote_cisco_ops
.to_files_info
= remote_files_info
;
5364 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5365 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5366 remote_cisco_ops
.to_kill
= remote_kill
;
5367 remote_cisco_ops
.to_load
= generic_load
;
5368 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5369 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5370 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5371 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5372 remote_cisco_ops
.to_stratum
= process_stratum
;
5373 remote_cisco_ops
.to_has_all_memory
= 1;
5374 remote_cisco_ops
.to_has_memory
= 1;
5375 remote_cisco_ops
.to_has_stack
= 1;
5376 remote_cisco_ops
.to_has_registers
= 1;
5377 remote_cisco_ops
.to_has_execution
= 1;
5378 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5382 remote_can_async_p (void)
5384 /* We're async whenever the serial device is. */
5385 return (current_target
.to_async_mask_value
) && SERIAL_CAN_ASYNC_P (remote_desc
);
5389 remote_is_async_p (void)
5391 /* We're async whenever the serial device is. */
5392 return (current_target
.to_async_mask_value
) && SERIAL_IS_ASYNC_P (remote_desc
);
5395 /* Pass the SERIAL event on and up to the client. One day this code
5396 will be able to delay notifying the client of an event until the
5397 point where an entire packet has been received. */
5399 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5400 static void *async_client_context
;
5401 static serial_event_ftype remote_async_serial_handler
;
5404 remote_async_serial_handler (serial_t scb
, void *context
)
5406 /* Don't propogate error information up to the client. Instead let
5407 the client find out about the error by querying the target. */
5408 async_client_callback (INF_REG_EVENT
, async_client_context
);
5412 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5414 if (current_target
.to_async_mask_value
== 0)
5415 internal_error (__FILE__
, __LINE__
,
5416 "Calling remote_async when async is masked");
5418 if (callback
!= NULL
)
5420 SERIAL_ASYNC (remote_desc
, remote_async_serial_handler
, NULL
);
5421 async_client_callback
= callback
;
5422 async_client_context
= context
;
5425 SERIAL_ASYNC (remote_desc
, NULL
, NULL
);
5428 /* Target async and target extended-async.
5430 This are temporary targets, until it is all tested. Eventually
5431 async support will be incorporated int the usual 'remote'
5435 init_remote_async_ops (void)
5437 remote_async_ops
.to_shortname
= "async";
5438 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5439 remote_async_ops
.to_doc
=
5440 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5441 Specify the serial device it is connected to (e.g. /dev/ttya).";
5442 remote_async_ops
.to_open
= remote_async_open
;
5443 remote_async_ops
.to_close
= remote_close
;
5444 remote_async_ops
.to_detach
= remote_async_detach
;
5445 remote_async_ops
.to_resume
= remote_async_resume
;
5446 remote_async_ops
.to_wait
= remote_async_wait
;
5447 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5448 remote_async_ops
.to_store_registers
= remote_store_registers
;
5449 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5450 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5451 remote_async_ops
.to_files_info
= remote_files_info
;
5452 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5453 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5454 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5455 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5456 remote_async_ops
.to_kill
= remote_async_kill
;
5457 remote_async_ops
.to_load
= generic_load
;
5458 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5459 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5460 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5461 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5462 remote_async_ops
.to_stop
= remote_stop
;
5463 remote_async_ops
.to_query
= remote_query
;
5464 remote_async_ops
.to_rcmd
= remote_rcmd
;
5465 remote_async_ops
.to_stratum
= process_stratum
;
5466 remote_async_ops
.to_has_all_memory
= 1;
5467 remote_async_ops
.to_has_memory
= 1;
5468 remote_async_ops
.to_has_stack
= 1;
5469 remote_async_ops
.to_has_registers
= 1;
5470 remote_async_ops
.to_has_execution
= 1;
5471 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5472 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5473 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5474 remote_async_ops
.to_async
= remote_async
;
5475 remote_async_ops
.to_async_mask_value
= 1;
5476 remote_async_ops
.to_magic
= OPS_MAGIC
;
5479 /* Set up the async extended remote vector by making a copy of the standard
5480 remote vector and adding to it. */
5483 init_extended_async_remote_ops (void)
5485 extended_async_remote_ops
= remote_async_ops
;
5487 extended_async_remote_ops
.to_shortname
= "extended-async";
5488 extended_async_remote_ops
.to_longname
=
5489 "Extended remote serial target in async gdb-specific protocol";
5490 extended_async_remote_ops
.to_doc
=
5491 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5492 Specify the serial device it is connected to (e.g. /dev/ttya).",
5493 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5494 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5495 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5499 set_remote_cmd (char *args
, int from_tty
)
5505 show_remote_cmd (char *args
, int from_tty
)
5507 show_remote_protocol_Z_packet_cmd (args
, from_tty
);
5508 show_remote_protocol_P_packet_cmd (args
, from_tty
);
5509 show_remote_protocol_binary_download_cmd (args
, from_tty
);
5513 build_remote_gdbarch_data (void)
5515 build_remote_packet_sizes ();
5518 tty_input
= xmalloc (PBUFSIZ
);
5519 remote_address_size
= TARGET_ADDR_BIT
;
5523 _initialize_remote (void)
5525 static struct cmd_list_element
*remote_set_cmdlist
;
5526 static struct cmd_list_element
*remote_show_cmdlist
;
5527 struct cmd_list_element
*tmpcmd
;
5529 /* architecture specific data */
5530 build_remote_gdbarch_data ();
5531 register_gdbarch_swap (&tty_input
, sizeof (&tty_input
), NULL
);
5532 register_remote_packet_sizes ();
5533 register_gdbarch_swap (&remote_address_size
,
5534 sizeof (&remote_address_size
), NULL
);
5535 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5538 add_target (&remote_ops
);
5540 init_extended_remote_ops ();
5541 add_target (&extended_remote_ops
);
5543 init_remote_async_ops ();
5544 add_target (&remote_async_ops
);
5546 init_extended_async_remote_ops ();
5547 add_target (&extended_async_remote_ops
);
5549 init_remote_cisco_ops ();
5550 add_target (&remote_cisco_ops
);
5553 init_remote_threadtests ();
5556 /* set/show remote ... */
5558 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5559 Remote protocol specific variables\n\
5560 Configure various remote-protocol specific variables such as\n\
5561 the packets being used",
5562 &remote_set_cmdlist
, "set remote ",
5563 0/*allow-unknown*/, &setlist
);
5564 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
5565 Remote protocol specific variables\n\
5566 Configure various remote-protocol specific variables such as\n\
5567 the packets being used",
5568 &remote_show_cmdlist
, "show remote ",
5569 0/*allow-unknown*/, &showlist
);
5571 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
5572 "Compare section data on target to the exec file.\n\
5573 Argument is a single section name (default: all loaded sections).",
5576 add_cmd ("packet", class_maintenance
, packet_command
,
5577 "Send an arbitrary packet to a remote target.\n\
5578 maintenance packet TEXT\n\
5579 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5580 this command sends the string TEXT to the inferior, and displays the\n\
5581 response packet. GDB supplies the initial `$' character, and the\n\
5582 terminating `#' character and checksum.",
5586 (add_set_cmd ("remotebreak", no_class
,
5587 var_boolean
, (char *) &remote_break
,
5588 "Set whether to send break if interrupted.\n",
5592 /* Install commands for configuring memory read/write packets. */
5594 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
5595 "Set the maximum number of bytes per memory write packet (deprecated).\n",
5597 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
5598 "Show the maximum number of bytes per memory write packet (deprecated).\n",
5600 add_cmd ("memory-write-packet-size", no_class
,
5601 set_memory_write_packet_size
,
5602 "Set the maximum number of bytes per memory-write packet.\n"
5603 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5604 "default packet size. The actual limit is further reduced\n"
5605 "dependent on the target. Specify ``fixed'' to disable the\n"
5606 "further restriction and ``limit'' to enable that restriction\n",
5607 &remote_set_cmdlist
);
5608 add_cmd ("memory-read-packet-size", no_class
,
5609 set_memory_read_packet_size
,
5610 "Set the maximum number of bytes per memory-read packet.\n"
5611 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5612 "default packet size. The actual limit is further reduced\n"
5613 "dependent on the target. Specify ``fixed'' to disable the\n"
5614 "further restriction and ``limit'' to enable that restriction\n",
5615 &remote_set_cmdlist
);
5616 add_cmd ("memory-write-packet-size", no_class
,
5617 show_memory_write_packet_size
,
5618 "Show the maximum number of bytes per memory-write packet.\n",
5619 &remote_show_cmdlist
);
5620 add_cmd ("memory-read-packet-size", no_class
,
5621 show_memory_read_packet_size
,
5622 "Show the maximum number of bytes per memory-read packet.\n",
5623 &remote_show_cmdlist
);
5626 (add_set_cmd ("remoteaddresssize", class_obscure
,
5627 var_integer
, (char *) &remote_address_size
,
5628 "Set the maximum size of the address (in bits) \
5629 in a memory packet.\n",
5633 add_packet_config_cmd (&remote_protocol_binary_download
,
5634 "X", "binary-download",
5635 set_remote_protocol_binary_download_cmd
,
5636 show_remote_protocol_binary_download_cmd
,
5637 &remote_set_cmdlist
, &remote_show_cmdlist
,
5640 /* XXXX - should ``set remotebinarydownload'' be retained for
5643 (add_set_cmd ("remotebinarydownload", no_class
,
5644 var_boolean
, (char *) &remote_binary_download
,
5645 "Set binary downloads.\n", &setlist
),
5649 add_info ("remote-process", remote_info_process
,
5650 "Query the remote system for process info.");
5652 add_packet_config_cmd (&remote_protocol_P
,
5653 "P", "set-register",
5654 set_remote_protocol_P_packet_cmd
,
5655 show_remote_protocol_P_packet_cmd
,
5656 &remote_set_cmdlist
, &remote_show_cmdlist
,
5659 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
5660 "Z0", "software-breakpoint",
5661 set_remote_protocol_Z_software_bp_packet_cmd
,
5662 show_remote_protocol_Z_software_bp_packet_cmd
,
5663 &remote_set_cmdlist
, &remote_show_cmdlist
,
5666 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
5667 "Z1", "hardware-breakpoint",
5668 set_remote_protocol_Z_hardware_bp_packet_cmd
,
5669 show_remote_protocol_Z_hardware_bp_packet_cmd
,
5670 &remote_set_cmdlist
, &remote_show_cmdlist
,
5673 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
5674 "Z2", "write-watchpoint",
5675 set_remote_protocol_Z_write_wp_packet_cmd
,
5676 show_remote_protocol_Z_write_wp_packet_cmd
,
5677 &remote_set_cmdlist
, &remote_show_cmdlist
,
5680 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
5681 "Z3", "read-watchpoint",
5682 set_remote_protocol_Z_read_wp_packet_cmd
,
5683 show_remote_protocol_Z_read_wp_packet_cmd
,
5684 &remote_set_cmdlist
, &remote_show_cmdlist
,
5687 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
5688 "Z4", "access-watchpoint",
5689 set_remote_protocol_Z_access_wp_packet_cmd
,
5690 show_remote_protocol_Z_access_wp_packet_cmd
,
5691 &remote_set_cmdlist
, &remote_show_cmdlist
,
5694 /* Keep the old ``set remote Z-packet ...'' working. */
5695 tmpcmd
= add_set_auto_boolean_cmd ("Z-packet", class_obscure
,
5696 &remote_Z_packet_detect
,
5698 Set use of remote protocol `Z' packets", &remote_set_cmdlist
);
5699 tmpcmd
->function
.sfunc
= set_remote_protocol_Z_packet_cmd
;
5700 add_cmd ("Z-packet", class_obscure
, show_remote_protocol_Z_packet_cmd
,
5701 "Show use of remote protocol `Z' packets ",
5702 &remote_show_cmdlist
);