1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 1991-2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* See the GDB User Guide for details of the GDB remote protocol. */
24 #include "gdb_string.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
45 #include <sys/types.h>
48 #include "event-loop.h"
49 #include "event-top.h"
55 /* Prototypes for local functions */
56 static void cleanup_sigint_signal_handler (void *dummy
);
57 static void initialize_sigint_signal_handler (void);
58 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
60 static void handle_remote_sigint (int);
61 static void handle_remote_sigint_twice (int);
62 static void async_remote_interrupt (gdb_client_data
);
63 void async_remote_interrupt_twice (gdb_client_data
);
65 static void build_remote_gdbarch_data (void);
67 static int remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
69 static int remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
71 static void remote_files_info (struct target_ops
*ignore
);
73 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
74 int len
, int should_write
,
75 struct target_ops
*target
);
77 static void remote_prepare_to_store (void);
79 static void remote_fetch_registers (int regno
);
81 static void remote_resume (int pid
, int step
, enum target_signal siggnal
);
82 static void remote_async_resume (int pid
, int step
,
83 enum target_signal siggnal
);
84 static int remote_start_remote (PTR
);
86 static void remote_open (char *name
, int from_tty
);
87 static void remote_async_open (char *name
, int from_tty
);
89 static void extended_remote_open (char *name
, int from_tty
);
90 static void extended_remote_async_open (char *name
, int from_tty
);
92 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
93 static void remote_async_open_1 (char *, int, struct target_ops
*,
96 static void remote_close (int quitting
);
98 static void remote_store_registers (int regno
);
100 static void remote_mourn (void);
101 static void remote_async_mourn (void);
103 static void extended_remote_restart (void);
105 static void extended_remote_mourn (void);
107 static void extended_remote_create_inferior (char *, char *, char **);
108 static void extended_remote_async_create_inferior (char *, char *, char **);
110 static void remote_mourn_1 (struct target_ops
*);
112 static void remote_send (char *buf
, long sizeof_buf
);
114 static int readchar (int timeout
);
116 static int remote_wait (int pid
, struct target_waitstatus
*status
);
117 static int remote_async_wait (int pid
, struct target_waitstatus
*status
);
119 static void remote_kill (void);
120 static void remote_async_kill (void);
122 static int tohex (int nib
);
124 static void remote_detach (char *args
, int from_tty
);
125 static void remote_async_detach (char *args
, int from_tty
);
127 static void remote_interrupt (int signo
);
129 static void remote_interrupt_twice (int signo
);
131 static void interrupt_query (void);
133 static void set_thread (int, int);
135 static int remote_thread_alive (int);
137 static void get_offsets (void);
139 static long read_frame (char *buf
, long sizeof_buf
);
141 static int remote_insert_breakpoint (CORE_ADDR
, char *);
143 static int remote_remove_breakpoint (CORE_ADDR
, char *);
145 static int hexnumlen (ULONGEST num
);
147 static void init_remote_ops (void);
149 static void init_extended_remote_ops (void);
151 static void init_remote_cisco_ops (void);
153 static struct target_ops remote_cisco_ops
;
155 static void remote_stop (void);
157 static int ishex (int ch
, int *val
);
159 static int stubhex (int ch
);
161 static int remote_query (int /*char */ , char *, char *, int *);
163 static int hexnumstr (char *, ULONGEST
);
165 static int hexnumnstr (char *, ULONGEST
, int);
167 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
169 static void print_packet (char *);
171 static unsigned long crc32 (unsigned char *, int, unsigned int);
173 static void compare_sections_command (char *, int);
175 static void packet_command (char *, int);
177 static int stub_unpack_int (char *buff
, int fieldlength
);
179 static int remote_current_thread (int oldpid
);
181 static void remote_find_new_threads (void);
183 static void record_currthread (int currthread
);
185 /* exported functions */
187 extern int fromhex (int a
);
189 static int putpkt_binary (char *buf
, int cnt
);
191 static void check_binary_download (CORE_ADDR addr
);
193 struct packet_config
;
195 static void show_packet_config_cmd (struct packet_config
*config
);
197 static void update_packet_config (struct packet_config
*config
);
199 /* Define the target subroutine names */
201 void open_remote_target (char *, int, struct target_ops
*, int);
203 void _initialize_remote (void);
207 static struct target_ops remote_ops
;
209 static struct target_ops extended_remote_ops
;
211 /* Temporary target ops. Just like the remote_ops and
212 extended_remote_ops, but with asynchronous support. */
213 static struct target_ops remote_async_ops
;
215 static struct target_ops extended_async_remote_ops
;
217 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
218 ``forever'' still use the normal timeout mechanism. This is
219 currently used by the ASYNC code to guarentee that target reads
220 during the initial connect always time-out. Once getpkt has been
221 modified to return a timeout indication and, in turn
222 remote_wait()/wait_for_inferior() have gained a timeout parameter
224 static int wait_forever_enabled_p
= 1;
227 /* This variable chooses whether to send a ^C or a break when the user
228 requests program interruption. Although ^C is usually what remote
229 systems expect, and that is the default here, sometimes a break is
230 preferable instead. */
232 static int remote_break
;
234 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
235 remote_open knows that we don't have a file open when the program
237 static serial_t remote_desc
= NULL
;
239 /* This is set by the target (thru the 'S' message)
240 to denote that the target is in kernel mode. */
241 static int cisco_kernel_mode
= 0;
243 /* This variable sets the number of bits in an address that are to be
244 sent in a memory ("M" or "m") packet. Normally, after stripping
245 leading zeros, the entire address would be sent. This variable
246 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
247 initial implementation of remote.c restricted the address sent in
248 memory packets to ``host::sizeof long'' bytes - (typically 32
249 bits). Consequently, for 64 bit targets, the upper 32 bits of an
250 address was never sent. Since fixing this bug may cause a break in
251 some remote targets this variable is principly provided to
252 facilitate backward compatibility. */
254 static int remote_address_size
;
256 /* Tempoary to track who currently owns the terminal. See
257 target_async_terminal_* for more details. */
259 static int remote_async_terminal_ours_p
;
262 /* This is the size (in chars) of the first response to the ``g''
263 packet. It is used as a heuristic when determining the maximum
264 size of memory-read and memory-write packets. A target will
265 typically only reserve a buffer large enough to hold the ``g''
266 packet. The size does not include packet overhead (headers and
269 static long actual_register_packet_size
;
271 /* This is the maximum size (in chars) of a non read/write packet. It
272 is also used as a cap on the size of read/write packets. */
274 static long remote_packet_size
;
276 #define PBUFSIZ (remote_packet_size)
278 /* User configurable variables for the number of characters in a
279 memory read/write packet. MIN (PBUFSIZ, g-packet-size) is the
280 default. Some targets need smaller values (fifo overruns, et.al.)
281 and some users need larger values (speed up transfers). The
282 variables ``preferred_*'' (the user request), ``current_*'' (what
283 was actually set) and ``forced_*'' (Positive - a soft limit,
284 negative - a hard limit). */
286 struct memory_packet_config
293 /* Compute the current size of a read/write packet. Since this makes
294 use of ``actual_register_packet_size'' the computation is dynamic. */
297 get_memory_packet_size (struct memory_packet_config
*config
)
299 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
300 law?) that some hosts don't cope very well with large alloca()
301 calls. Eventually the alloca() code will be replaced by calls to
302 xmalloc() and make_cleanups() allowing this restriction to either
303 be lifted or removed. */
304 #ifndef MAX_REMOTE_PACKET_SIZE
305 #define MAX_REMOTE_PACKET_SIZE 16384
307 /* NOTE: 16 is just chosen at random. */
308 #ifndef MIN_REMOTE_PACKET_SIZE
309 #define MIN_REMOTE_PACKET_SIZE 16
314 if (config
->size
<= 0)
315 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
317 what_they_get
= config
->size
;
321 what_they_get
= remote_packet_size
;
322 /* Limit the packet to the size specified by the user. */
324 && what_they_get
> config
->size
)
325 what_they_get
= config
->size
;
326 /* Limit it to the size of the targets ``g'' response. */
327 if (actual_register_packet_size
> 0
328 && what_they_get
> actual_register_packet_size
)
329 what_they_get
= actual_register_packet_size
;
331 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
332 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
333 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
334 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
335 return what_they_get
;
338 /* Update the size of a read/write packet. If they user wants
339 something really big then do a sanity check. */
342 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
344 int fixed_p
= config
->fixed_p
;
345 long size
= config
->size
;
347 error ("Argument required (integer, `fixed' or `limited').");
348 else if (strcmp (args
, "hard") == 0
349 || strcmp (args
, "fixed") == 0)
351 else if (strcmp (args
, "soft") == 0
352 || strcmp (args
, "limit") == 0)
357 size
= strtoul (args
, &end
, 0);
359 error ("Invalid %s (bad syntax).", config
->name
);
361 /* Instead of explicitly capping the size of a packet to
362 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
363 instead allowed to set the size to something arbitrarily
365 if (size
> MAX_REMOTE_PACKET_SIZE
)
366 error ("Invalid %s (too large).", config
->name
);
370 if (fixed_p
&& !config
->fixed_p
)
372 if (! query ("The target may not be able to correctly handle a %s\n"
373 "of %ld bytes. Change the packet size? ",
375 error ("Packet size not changed.");
377 /* Update the config. */
378 config
->fixed_p
= fixed_p
;
383 show_memory_packet_size (struct memory_packet_config
*config
)
385 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
387 printf_filtered ("Packets are fixed at %ld bytes.\n",
388 get_memory_packet_size (config
));
390 printf_filtered ("Packets are limited to %ld bytes.\n",
391 get_memory_packet_size (config
));
394 static struct memory_packet_config memory_write_packet_config
=
396 "memory-write-packet-size",
400 set_memory_write_packet_size (char *args
, int from_tty
)
402 set_memory_packet_size (args
, &memory_write_packet_config
);
406 show_memory_write_packet_size (char *args
, int from_tty
)
408 show_memory_packet_size (&memory_write_packet_config
);
412 get_memory_write_packet_size (void)
414 return get_memory_packet_size (&memory_write_packet_config
);
417 static struct memory_packet_config memory_read_packet_config
=
419 "memory-read-packet-size",
423 set_memory_read_packet_size (char *args
, int from_tty
)
425 set_memory_packet_size (args
, &memory_read_packet_config
);
429 show_memory_read_packet_size (char *args
, int from_tty
)
431 show_memory_packet_size (&memory_read_packet_config
);
435 get_memory_read_packet_size (void)
437 long size
= get_memory_packet_size (&memory_read_packet_config
);
438 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
439 extra buffer size argument before the memory read size can be
440 increased beyond PBUFSIZ. */
446 /* Register packet size initialization. Since the bounds change when
447 the architecture changes (namely REGISTER_BYTES) this all needs to
451 register_remote_packet_sizes (void)
453 REGISTER_GDBARCH_SWAP (remote_packet_size
);
454 REGISTER_GDBARCH_SWAP (actual_register_packet_size
);
458 build_remote_packet_sizes (void)
460 /* Default maximum number of characters in a packet body. Many
461 remote stubs have a hardwired buffer size of 400 bytes
462 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
463 as the maximum packet-size to ensure that the packet and an extra
464 NUL character can always fit in the buffer. This stops GDB
465 trashing stubs that try to squeeze an extra NUL into what is
466 already a full buffer (As of 1999-12-04 that was most stubs. */
467 remote_packet_size
= 400 - 1;
468 /* Should REGISTER_BYTES needs more space than the default, adjust
469 the size accordingly. Remember that each byte is encoded as two
470 characters. 32 is the overhead for the packet header /
471 footer. NOTE: cagney/1999-10-26: I suspect that 8
472 (``$NN:G...#NN'') is a better guess, the below has been padded a
474 if (REGISTER_BYTES
> ((remote_packet_size
- 32) / 2))
475 remote_packet_size
= (REGISTER_BYTES
* 2 + 32);
477 /* This one is filled in when a ``g'' packet is received. */
478 actual_register_packet_size
= 0;
481 /* Generic configuration support for packets the stub optionally
482 supports. Allows the user to specify the use of the packet as well
483 as allowing GDB to auto-detect support in the remote stub. */
487 PACKET_SUPPORT_UNKNOWN
= 0,
496 enum cmd_auto_boolean detect
;
497 enum packet_support support
;
500 /* Analyze a packet's return value and update the packet config
511 update_packet_config (struct packet_config
*config
)
513 switch (config
->detect
)
515 case CMD_AUTO_BOOLEAN_TRUE
:
516 config
->support
= PACKET_ENABLE
;
518 case CMD_AUTO_BOOLEAN_FALSE
:
519 config
->support
= PACKET_DISABLE
;
521 case CMD_AUTO_BOOLEAN_AUTO
:
522 config
->support
= PACKET_SUPPORT_UNKNOWN
;
528 show_packet_config_cmd (struct packet_config
*config
)
530 char *support
= "internal-error";
531 switch (config
->support
)
537 support
= "disabled";
539 case PACKET_SUPPORT_UNKNOWN
:
543 switch (config
->detect
)
545 case CMD_AUTO_BOOLEAN_AUTO
:
546 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
547 config
->name
, config
->title
, support
);
549 case CMD_AUTO_BOOLEAN_TRUE
:
550 case CMD_AUTO_BOOLEAN_FALSE
:
551 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
552 config
->name
, config
->title
, support
);
558 add_packet_config_cmd (struct packet_config
*config
,
561 void (*set_func
) (char *args
, int from_tty
,
562 struct cmd_list_element
*
564 void (*show_func
) (char *name
,
566 struct cmd_list_element
**set_remote_list
,
567 struct cmd_list_element
**show_remote_list
,
570 struct cmd_list_element
*set_cmd
;
571 struct cmd_list_element
*show_cmd
;
576 config
->title
= title
;
577 config
->detect
= CMD_AUTO_BOOLEAN_AUTO
;
578 config
->support
= PACKET_SUPPORT_UNKNOWN
;
579 asprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
581 asprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
583 /* set/show TITLE-packet {auto,on,off} */
584 asprintf (&cmd_name
, "%s-packet", title
);
585 set_cmd
= add_set_auto_boolean_cmd (cmd_name
, class_obscure
,
586 &config
->detect
, set_doc
,
588 set_cmd
->function
.sfunc
= set_func
;
589 show_cmd
= add_cmd (cmd_name
, class_obscure
, show_func
, show_doc
,
591 /* set/show remote NAME-packet {auto,on,off} -- legacy */
595 asprintf (&legacy_name
, "%s-packet", name
);
596 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
598 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
603 static enum packet_result
604 packet_ok (const char *buf
, struct packet_config
*config
)
608 /* The stub recognized the packet request. Check that the
609 operation succeeded. */
610 switch (config
->support
)
612 case PACKET_SUPPORT_UNKNOWN
:
614 fprintf_unfiltered (gdb_stdlog
,
615 "Packet %s (%s) is supported\n",
616 config
->name
, config
->title
);
617 config
->support
= PACKET_ENABLE
;
620 internal_error ("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 ("remote_threads_extra_info");
1688 if (use_threadextra_query
)
1690 sprintf (bufp
, "qThreadExtraInfo,%x", tp
->pid
);
1692 getpkt (bufp
, PBUFSIZ
, 0);
1697 for (p
= display_buf
;
1698 p
< display_buf
+ sizeof(display_buf
) - 1 &&
1703 *p
= fromhex (bufp
[0]) * 16 + fromhex (bufp
[1]);
1710 /* If the above query fails, fall back to the old method. */
1711 use_threadextra_query
= 0;
1712 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1713 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1714 int_to_threadref (&id
, tp
->pid
);
1715 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1716 if (threadinfo
.active
)
1718 if (*threadinfo
.shortname
)
1719 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1720 if (*threadinfo
.display
)
1721 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1722 if (*threadinfo
.more_display
)
1723 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1724 threadinfo
.more_display
);
1728 /* for purely cosmetic reasons, clear up trailing commas */
1729 if (',' == display_buf
[n
-1])
1730 display_buf
[n
-1] = ' ';
1739 /* Restart the remote side; this is an extended protocol operation. */
1742 extended_remote_restart (void)
1744 char *buf
= alloca (PBUFSIZ
);
1746 /* Send the restart command; for reasons I don't understand the
1747 remote side really expects a number after the "R". */
1749 sprintf (&buf
[1], "%x", 0);
1752 /* Now query for status so this looks just like we restarted
1753 gdbserver from scratch. */
1755 getpkt (buf
, PBUFSIZ
, 0);
1758 /* Clean up connection to a remote debugger. */
1762 remote_close (int quitting
)
1765 SERIAL_CLOSE (remote_desc
);
1769 /* Query the remote side for the text, data and bss offsets. */
1774 char *buf
= alloca (PBUFSIZ
);
1777 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1778 struct section_offsets
*offs
;
1780 putpkt ("qOffsets");
1782 getpkt (buf
, PBUFSIZ
, 0);
1784 if (buf
[0] == '\000')
1785 return; /* Return silently. Stub doesn't support
1789 warning ("Remote failure reply: %s", buf
);
1793 /* Pick up each field in turn. This used to be done with scanf, but
1794 scanf will make trouble if CORE_ADDR size doesn't match
1795 conversion directives correctly. The following code will work
1796 with any size of CORE_ADDR. */
1797 text_addr
= data_addr
= bss_addr
= 0;
1801 if (strncmp (ptr
, "Text=", 5) == 0)
1804 /* Don't use strtol, could lose on big values. */
1805 while (*ptr
&& *ptr
!= ';')
1806 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1811 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1814 while (*ptr
&& *ptr
!= ';')
1815 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1820 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1823 while (*ptr
&& *ptr
!= ';')
1824 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1830 error ("Malformed response to offset query, %s", buf
);
1832 if (symfile_objfile
== NULL
)
1835 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1836 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1838 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1840 /* This is a temporary kludge to force data and bss to use the same offsets
1841 because that's what nlmconv does now. The real solution requires changes
1842 to the stub and remote.c that I don't have time to do right now. */
1844 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
1845 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
1847 objfile_relocate (symfile_objfile
, offs
);
1851 * Cisco version of section offsets:
1853 * Instead of having GDB query the target for the section offsets,
1854 * Cisco lets the target volunteer the information! It's also in
1855 * a different format, so here are the functions that will decode
1856 * a section offset packet from a Cisco target.
1860 * Function: remote_cisco_section_offsets
1862 * Returns: zero for success, non-zero for failure
1866 remote_cisco_section_offsets (bfd_vma text_addr
,
1869 bfd_signed_vma
*text_offs
,
1870 bfd_signed_vma
*data_offs
,
1871 bfd_signed_vma
*bss_offs
)
1873 bfd_vma text_base
, data_base
, bss_base
;
1874 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 p
= (unsigned char *) 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
= 1; /* 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. */
2030 static DCACHE
*remote_dcache
;
2033 init_all_packet_configs (void)
2036 update_packet_config (&remote_protocol_P
);
2037 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2038 update_packet_config (&remote_protocol_Z
[i
]);
2039 /* Force remote_write_bytes to check whether target supports binary
2041 update_packet_config (&remote_protocol_binary_download
);
2045 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2049 error ("To open a remote debug connection, you need to specify what\n\
2050 serial device is attached to the remote system\n\
2051 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2053 /* See FIXME above */
2054 wait_forever_enabled_p
= 1;
2056 target_preopen (from_tty
);
2058 unpush_target (target
);
2061 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
2063 dcache_invd (remote_dcache
);
2065 remote_desc
= SERIAL_OPEN (name
);
2067 perror_with_name (name
);
2069 if (baud_rate
!= -1)
2071 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
2073 SERIAL_CLOSE (remote_desc
);
2074 perror_with_name (name
);
2078 SERIAL_RAW (remote_desc
);
2080 /* If there is something sitting in the buffer we might take it as a
2081 response to a command, which would be bad. */
2082 SERIAL_FLUSH_INPUT (remote_desc
);
2086 puts_filtered ("Remote debugging using ");
2087 puts_filtered (name
);
2088 puts_filtered ("\n");
2090 push_target (target
); /* Switch to using remote target now */
2092 init_all_packet_configs ();
2094 general_thread
= -2;
2095 continue_thread
= -2;
2097 /* Probe for ability to use "ThreadInfo" query, as required. */
2098 use_threadinfo_query
= 1;
2099 use_threadextra_query
= 1;
2101 /* Without this, some commands which require an active target (such
2102 as kill) won't work. This variable serves (at least) double duty
2103 as both the pid of the target process (if it has such), and as a
2104 flag indicating that a target is active. These functions should
2105 be split out into seperate variables, especially since GDB will
2106 someday have a notion of debugging several processes. */
2108 inferior_pid
= MAGIC_NULL_PID
;
2109 /* Start the remote connection; if error (0), discard this target.
2110 In particular, if the user quits, be sure to discard it
2111 (we'd be in an inconsistent state otherwise). */
2112 if (!catch_errors (remote_start_remote
, NULL
,
2113 "Couldn't establish connection to remote target\n",
2122 /* tell the remote that we're using the extended protocol. */
2123 char *buf
= alloca (PBUFSIZ
);
2125 getpkt (buf
, PBUFSIZ
, 0);
2129 /* Just like remote_open but with asynchronous support. */
2131 remote_async_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2135 error ("To open a remote debug connection, you need to specify what\n\
2136 serial device is attached to the remote system\n\
2137 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2139 target_preopen (from_tty
);
2141 unpush_target (target
);
2143 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
2145 remote_desc
= SERIAL_OPEN (name
);
2147 perror_with_name (name
);
2149 if (baud_rate
!= -1)
2151 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
2153 SERIAL_CLOSE (remote_desc
);
2154 perror_with_name (name
);
2158 SERIAL_RAW (remote_desc
);
2160 /* If there is something sitting in the buffer we might take it as a
2161 response to a command, which would be bad. */
2162 SERIAL_FLUSH_INPUT (remote_desc
);
2166 puts_filtered ("Remote debugging using ");
2167 puts_filtered (name
);
2168 puts_filtered ("\n");
2171 push_target (target
); /* Switch to using remote target now */
2173 init_all_packet_configs ();
2175 general_thread
= -2;
2176 continue_thread
= -2;
2178 /* Probe for ability to use "ThreadInfo" query, as required. */
2179 use_threadinfo_query
= 1;
2180 use_threadextra_query
= 1;
2182 /* Without this, some commands which require an active target (such
2183 as kill) won't work. This variable serves (at least) double duty
2184 as both the pid of the target process (if it has such), and as a
2185 flag indicating that a target is active. These functions should
2186 be split out into seperate variables, especially since GDB will
2187 someday have a notion of debugging several processes. */
2188 inferior_pid
= MAGIC_NULL_PID
;
2190 /* With this target we start out by owning the terminal. */
2191 remote_async_terminal_ours_p
= 1;
2193 /* FIXME: cagney/1999-09-23: During the initial connection it is
2194 assumed that the target is already ready and able to respond to
2195 requests. Unfortunatly remote_start_remote() eventually calls
2196 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2197 around this. Eventually a mechanism that allows
2198 wait_for_inferior() to expect/get timeouts will be
2200 wait_forever_enabled_p
= 0;
2202 /* Start the remote connection; if error (0), discard this target.
2203 In particular, if the user quits, be sure to discard it
2204 (we'd be in an inconsistent state otherwise). */
2205 if (!catch_errors (remote_start_remote
, NULL
,
2206 "Couldn't establish connection to remote target\n",
2210 wait_forever_enabled_p
= 1;
2214 wait_forever_enabled_p
= 1;
2218 /* tell the remote that we're using the extended protocol. */
2219 char *buf
= alloca (PBUFSIZ
);
2221 getpkt (buf
, PBUFSIZ
, 0);
2225 /* This takes a program previously attached to and detaches it. After
2226 this is done, GDB can be used to debug some other program. We
2227 better not have left any breakpoints in the target program or it'll
2228 die when it hits one. */
2231 remote_detach (char *args
, int from_tty
)
2233 char *buf
= alloca (PBUFSIZ
);
2236 error ("Argument given to \"detach\" when remotely debugging.");
2238 /* Tell the remote target to detach. */
2240 remote_send (buf
, PBUFSIZ
);
2242 target_mourn_inferior ();
2244 puts_filtered ("Ending remote debugging.\n");
2248 /* Same as remote_detach, but with async support. */
2250 remote_async_detach (char *args
, int from_tty
)
2252 char *buf
= alloca (PBUFSIZ
);
2255 error ("Argument given to \"detach\" when remotely debugging.");
2257 /* Tell the remote target to detach. */
2259 remote_send (buf
, PBUFSIZ
);
2261 /* Unregister the file descriptor from the event loop. */
2262 if (target_is_async_p ())
2263 SERIAL_ASYNC (remote_desc
, NULL
, 0);
2265 target_mourn_inferior ();
2267 puts_filtered ("Ending remote debugging.\n");
2270 /* Convert hex digit A to a number. */
2275 if (a
>= '0' && a
<= '9')
2277 else if (a
>= 'a' && a
<= 'f')
2278 return a
- 'a' + 10;
2279 else if (a
>= 'A' && a
<= 'F')
2280 return a
- 'A' + 10;
2282 error ("Reply contains invalid hex digit %d", a
);
2285 /* Convert number NIB to a hex digit. */
2293 return 'a' + nib
- 10;
2296 /* Tell the remote machine to resume. */
2298 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2300 static int last_sent_step
;
2303 remote_resume (int pid
, int step
, enum target_signal siggnal
)
2305 char *buf
= alloca (PBUFSIZ
);
2308 set_thread (0, 0); /* run any thread */
2310 set_thread (pid
, 0); /* run this thread */
2312 dcache_invd (remote_dcache
);
2314 last_sent_signal
= siggnal
;
2315 last_sent_step
= step
;
2317 /* A hook for when we need to do something at the last moment before
2319 if (target_resume_hook
)
2320 (*target_resume_hook
) ();
2322 if (siggnal
!= TARGET_SIGNAL_0
)
2324 buf
[0] = step
? 'S' : 'C';
2325 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2326 buf
[2] = tohex ((int) siggnal
& 0xf);
2330 strcpy (buf
, step
? "s" : "c");
2335 /* Same as remote_resume, but with async support. */
2337 remote_async_resume (int pid
, int step
, enum target_signal siggnal
)
2339 char *buf
= alloca (PBUFSIZ
);
2342 set_thread (0, 0); /* run any thread */
2344 set_thread (pid
, 0); /* run this thread */
2346 dcache_invd (remote_dcache
);
2348 last_sent_signal
= siggnal
;
2349 last_sent_step
= step
;
2351 /* A hook for when we need to do something at the last moment before
2353 if (target_resume_hook
)
2354 (*target_resume_hook
) ();
2356 if (siggnal
!= TARGET_SIGNAL_0
)
2358 buf
[0] = step
? 'S' : 'C';
2359 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2360 buf
[2] = tohex ((int) siggnal
& 0xf);
2364 strcpy (buf
, step
? "s" : "c");
2366 /* We are about to start executing the inferior, let's register it
2367 with the event loop. NOTE: this is the one place where all the
2368 execution commands end up. We could alternatively do this in each
2369 of the execution commands in infcmd.c.*/
2370 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2371 into infcmd.c in order to allow inferior function calls to work
2372 NOT asynchronously. */
2373 if (event_loop_p
&& target_can_async_p ())
2374 target_async (inferior_event_handler
, 0);
2375 /* Tell the world that the target is now executing. */
2376 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2377 this? Instead, should the client of target just assume (for
2378 async targets) that the target is going to start executing? Is
2379 this information already found in the continuation block? */
2380 if (target_is_async_p ())
2381 target_executing
= 1;
2386 /* Set up the signal handler for SIGINT, while the target is
2387 executing, ovewriting the 'regular' SIGINT signal handler. */
2389 initialize_sigint_signal_handler (void)
2391 sigint_remote_token
=
2392 create_async_signal_handler (async_remote_interrupt
, NULL
);
2393 signal (SIGINT
, handle_remote_sigint
);
2396 /* Signal handler for SIGINT, while the target is executing. */
2398 handle_remote_sigint (int sig
)
2400 signal (sig
, handle_remote_sigint_twice
);
2401 sigint_remote_twice_token
=
2402 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2403 mark_async_signal_handler_wrapper (sigint_remote_token
);
2406 /* Signal handler for SIGINT, installed after SIGINT has already been
2407 sent once. It will take effect the second time that the user sends
2410 handle_remote_sigint_twice (int sig
)
2412 signal (sig
, handle_sigint
);
2413 sigint_remote_twice_token
=
2414 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2415 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2418 /* Perform the real interruption of the target execution, in response
2421 async_remote_interrupt (gdb_client_data arg
)
2424 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2429 /* Perform interrupt, if the first attempt did not succeed. Just give
2430 up on the target alltogether. */
2432 async_remote_interrupt_twice (gdb_client_data arg
)
2435 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2436 /* Do something only if the target was not killed by the previous
2438 if (target_executing
)
2441 signal (SIGINT
, handle_remote_sigint
);
2445 /* Reinstall the usual SIGINT handlers, after the target has
2448 cleanup_sigint_signal_handler (void *dummy
)
2450 signal (SIGINT
, handle_sigint
);
2451 if (sigint_remote_twice_token
)
2452 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2453 if (sigint_remote_token
)
2454 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2457 /* Send ^C to target to halt it. Target will respond, and send us a
2459 static void (*ofunc
) (int);
2461 /* The command line interface's stop routine. This function is installed
2462 as a signal handler for SIGINT. The first time a user requests a
2463 stop, we call remote_stop to send a break or ^C. If there is no
2464 response from the target (it didn't stop when the user requested it),
2465 we ask the user if he'd like to detach from the target. */
2467 remote_interrupt (int signo
)
2469 /* If this doesn't work, try more severe steps. */
2470 signal (signo
, remote_interrupt_twice
);
2473 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2478 /* The user typed ^C twice. */
2481 remote_interrupt_twice (int signo
)
2483 signal (signo
, ofunc
);
2485 signal (signo
, remote_interrupt
);
2488 /* This is the generic stop called via the target vector. When a target
2489 interrupt is requested, either by the command line or the GUI, we
2490 will eventually end up here. */
2494 /* Send a break or a ^C, depending on user preference. */
2496 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2499 SERIAL_SEND_BREAK (remote_desc
);
2501 SERIAL_WRITE (remote_desc
, "\003", 1);
2504 /* Ask the user what to do when an interrupt is received. */
2507 interrupt_query (void)
2509 target_terminal_ours ();
2511 if (query ("Interrupted while waiting for the program.\n\
2512 Give up (and stop debugging it)? "))
2514 target_mourn_inferior ();
2515 return_to_top_level (RETURN_QUIT
);
2518 target_terminal_inferior ();
2521 /* Enable/disable target terminal ownership. Most targets can use
2522 terminal groups to control terminal ownership. Remote targets are
2523 different in that explicit transfer of ownership to/from GDB/target
2527 remote_async_terminal_inferior (void)
2529 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2530 sync_execution here. This function should only be called when
2531 GDB is resuming the inferior in the forground. A background
2532 resume (``run&'') should leave GDB in control of the terminal and
2533 consequently should not call this code. */
2534 if (!sync_execution
)
2536 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2537 calls target_terminal_*() idenpotent. The event-loop GDB talking
2538 to an asynchronous target with a synchronous command calls this
2539 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2540 stops trying to transfer the terminal to the target when it
2541 shouldn't this guard can go away. */
2542 if (!remote_async_terminal_ours_p
)
2544 delete_file_handler (input_fd
);
2545 remote_async_terminal_ours_p
= 0;
2546 initialize_sigint_signal_handler ();
2547 /* NOTE: At this point we could also register our selves as the
2548 recipient of all input. Any characters typed could then be
2549 passed on down to the target. */
2553 remote_async_terminal_ours (void)
2555 /* See FIXME in remote_async_terminal_inferior. */
2556 if (!sync_execution
)
2558 /* See FIXME in remote_async_terminal_inferior. */
2559 if (remote_async_terminal_ours_p
)
2561 cleanup_sigint_signal_handler (NULL
);
2562 add_file_handler (input_fd
, stdin_event_handler
, 0);
2563 remote_async_terminal_ours_p
= 1;
2566 /* If nonzero, ignore the next kill. */
2571 remote_console_output (char *msg
)
2575 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2578 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2581 fputs_unfiltered (tb
, gdb_stdtarg
);
2583 gdb_flush (gdb_stdtarg
);
2586 /* Wait until the remote machine stops, then return,
2587 storing status in STATUS just as `wait' would.
2588 Returns "pid", which in the case of a multi-threaded
2589 remote OS, is the thread-id. */
2592 remote_wait (int pid
, struct target_waitstatus
*status
)
2594 unsigned char *buf
= alloca (PBUFSIZ
);
2595 int thread_num
= -1;
2597 status
->kind
= TARGET_WAITKIND_EXITED
;
2598 status
->value
.integer
= 0;
2604 ofunc
= signal (SIGINT
, remote_interrupt
);
2605 getpkt (buf
, PBUFSIZ
, 1);
2606 signal (SIGINT
, ofunc
);
2608 /* This is a hook for when we need to do something (perhaps the
2609 collection of trace data) every time the target stops. */
2610 if (target_wait_loop_hook
)
2611 (*target_wait_loop_hook
) ();
2615 case 'E': /* Error of some sort */
2616 warning ("Remote failure reply: %s", buf
);
2618 case 'T': /* Status with PC, SP, FP, ... */
2622 char regs
[MAX_REGISTER_RAW_SIZE
];
2624 /* Expedited reply, containing Signal, {regno, reg} repeat */
2625 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2627 n... = register number
2628 r... = register contents
2630 p
= &buf
[3]; /* after Txx */
2637 /* Read the register number */
2638 regno
= strtol ((const char *) p
, &p_temp
, 16);
2639 p1
= (unsigned char *) p_temp
;
2641 if (p1
== p
) /* No register number present here */
2643 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2645 warning ("Malformed packet(a) (missing colon): %s\n\
2648 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2650 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2651 record_currthread (thread_num
);
2652 p
= (unsigned char *) p_temp
;
2660 warning ("Malformed packet(b) (missing colon): %s\n\
2664 if (regno
>= NUM_REGS
)
2665 warning ("Remote sent bad register number %ld: %s\n\
2669 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2671 if (p
[0] == 0 || p
[1] == 0)
2672 warning ("Remote reply is too short: %s", buf
);
2673 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2676 supply_register (regno
, regs
);
2681 warning ("Remote register badly formatted: %s", buf
);
2682 warning (" here: %s", p
);
2687 case 'S': /* Old style status, just signal only */
2688 status
->kind
= TARGET_WAITKIND_STOPPED
;
2689 status
->value
.sig
= (enum target_signal
)
2690 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2694 /* Export Cisco kernel mode as a convenience variable
2695 (so that it can be used in the GDB prompt if desired). */
2697 if (cisco_kernel_mode
== 1)
2698 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2699 value_from_string ("PDEBUG-"));
2700 cisco_kernel_mode
= 0;
2701 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2702 record_currthread (thread_num
);
2704 else if (buf
[3] == 'k')
2706 /* Export Cisco kernel mode as a convenience variable
2707 (so that it can be used in the GDB prompt if desired). */
2709 if (cisco_kernel_mode
== 1)
2710 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2711 value_from_string ("KDEBUG-"));
2712 cisco_kernel_mode
= 1;
2715 case 'N': /* Cisco special: status and offsets */
2717 bfd_vma text_addr
, data_addr
, bss_addr
;
2718 bfd_signed_vma text_off
, data_off
, bss_off
;
2721 status
->kind
= TARGET_WAITKIND_STOPPED
;
2722 status
->value
.sig
= (enum target_signal
)
2723 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2725 if (symfile_objfile
== NULL
)
2727 warning ("Relocation packet received with no symbol file. \
2732 /* Relocate object file. Buffer format is NAATT;DD;BB
2733 * where AA is the signal number, TT is the new text
2734 * address, DD * is the new data address, and BB is the
2735 * new bss address. */
2738 text_addr
= strtoul (p
, (char **) &p1
, 16);
2739 if (p1
== p
|| *p1
!= ';')
2740 warning ("Malformed relocation packet: Packet '%s'", buf
);
2742 data_addr
= strtoul (p
, (char **) &p1
, 16);
2743 if (p1
== p
|| *p1
!= ';')
2744 warning ("Malformed relocation packet: Packet '%s'", buf
);
2746 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2748 warning ("Malformed relocation packet: Packet '%s'", buf
);
2750 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2751 &text_off
, &data_off
, &bss_off
)
2753 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2754 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2758 case 'W': /* Target exited */
2760 /* The remote process exited. */
2761 status
->kind
= TARGET_WAITKIND_EXITED
;
2762 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2766 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2767 status
->value
.sig
= (enum target_signal
)
2768 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2772 case 'O': /* Console output */
2773 remote_console_output (buf
+ 1);
2776 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2778 /* Zero length reply means that we tried 'S' or 'C' and
2779 the remote system doesn't support it. */
2780 target_terminal_ours_for_output ();
2782 ("Can't send signals to this remote system. %s not sent.\n",
2783 target_signal_to_name (last_sent_signal
));
2784 last_sent_signal
= TARGET_SIGNAL_0
;
2785 target_terminal_inferior ();
2787 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2788 putpkt ((char *) buf
);
2791 /* else fallthrough */
2793 warning ("Invalid remote reply: %s", buf
);
2798 if (thread_num
!= -1)
2802 return inferior_pid
;
2805 /* Async version of remote_wait. */
2807 remote_async_wait (int pid
, struct target_waitstatus
*status
)
2809 unsigned char *buf
= alloca (PBUFSIZ
);
2810 int thread_num
= -1;
2812 status
->kind
= TARGET_WAITKIND_EXITED
;
2813 status
->value
.integer
= 0;
2819 if (!target_is_async_p ())
2820 ofunc
= signal (SIGINT
, remote_interrupt
);
2821 /* FIXME: cagney/1999-09-27: If we're in async mode we should
2822 _never_ wait for ever -> test on target_is_async_p().
2823 However, before we do that we need to ensure that the caller
2824 knows how to take the target into/out of async mode. */
2825 getpkt (buf
, PBUFSIZ
, wait_forever_enabled_p
);
2826 if (!target_is_async_p ())
2827 signal (SIGINT
, ofunc
);
2829 /* This is a hook for when we need to do something (perhaps the
2830 collection of trace data) every time the target stops. */
2831 if (target_wait_loop_hook
)
2832 (*target_wait_loop_hook
) ();
2836 case 'E': /* Error of some sort */
2837 warning ("Remote failure reply: %s", buf
);
2839 case 'T': /* Status with PC, SP, FP, ... */
2843 char regs
[MAX_REGISTER_RAW_SIZE
];
2845 /* Expedited reply, containing Signal, {regno, reg} repeat */
2846 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2848 n... = register number
2849 r... = register contents
2851 p
= &buf
[3]; /* after Txx */
2858 /* Read the register number */
2859 regno
= strtol ((const char *) p
, &p_temp
, 16);
2860 p1
= (unsigned char *) p_temp
;
2862 if (p1
== p
) /* No register number present here */
2864 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2866 warning ("Malformed packet(a) (missing colon): %s\n\
2869 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2871 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2872 record_currthread (thread_num
);
2873 p
= (unsigned char *) p_temp
;
2881 warning ("Malformed packet(b) (missing colon): %s\n\
2885 if (regno
>= NUM_REGS
)
2886 warning ("Remote sent bad register number %ld: %s\n\
2890 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2892 if (p
[0] == 0 || p
[1] == 0)
2893 warning ("Remote reply is too short: %s", buf
);
2894 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2897 supply_register (regno
, regs
);
2902 warning ("Remote register badly formatted: %s", buf
);
2903 warning (" here: %s", p
);
2908 case 'S': /* Old style status, just signal only */
2909 status
->kind
= TARGET_WAITKIND_STOPPED
;
2910 status
->value
.sig
= (enum target_signal
)
2911 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2915 /* Export Cisco kernel mode as a convenience variable
2916 (so that it can be used in the GDB prompt if desired). */
2918 if (cisco_kernel_mode
== 1)
2919 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2920 value_from_string ("PDEBUG-"));
2921 cisco_kernel_mode
= 0;
2922 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2923 record_currthread (thread_num
);
2925 else if (buf
[3] == 'k')
2927 /* Export Cisco kernel mode as a convenience variable
2928 (so that it can be used in the GDB prompt if desired). */
2930 if (cisco_kernel_mode
== 1)
2931 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2932 value_from_string ("KDEBUG-"));
2933 cisco_kernel_mode
= 1;
2936 case 'N': /* Cisco special: status and offsets */
2938 bfd_vma text_addr
, data_addr
, bss_addr
;
2939 bfd_signed_vma text_off
, data_off
, bss_off
;
2942 status
->kind
= TARGET_WAITKIND_STOPPED
;
2943 status
->value
.sig
= (enum target_signal
)
2944 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2946 if (symfile_objfile
== NULL
)
2948 warning ("Relocation packet recieved with no symbol file. \
2953 /* Relocate object file. Buffer format is NAATT;DD;BB
2954 * where AA is the signal number, TT is the new text
2955 * address, DD * is the new data address, and BB is the
2956 * new bss address. */
2959 text_addr
= strtoul (p
, (char **) &p1
, 16);
2960 if (p1
== p
|| *p1
!= ';')
2961 warning ("Malformed relocation packet: Packet '%s'", buf
);
2963 data_addr
= strtoul (p
, (char **) &p1
, 16);
2964 if (p1
== p
|| *p1
!= ';')
2965 warning ("Malformed relocation packet: Packet '%s'", buf
);
2967 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2969 warning ("Malformed relocation packet: Packet '%s'", buf
);
2971 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2972 &text_off
, &data_off
, &bss_off
)
2974 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2975 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2979 case 'W': /* Target exited */
2981 /* The remote process exited. */
2982 status
->kind
= TARGET_WAITKIND_EXITED
;
2983 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2987 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2988 status
->value
.sig
= (enum target_signal
)
2989 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2993 case 'O': /* Console output */
2994 remote_console_output (buf
+ 1);
2995 /* Return immediately to the event loop. The event loop will
2996 still be waiting on the inferior afterwards. */
2997 status
->kind
= TARGET_WAITKIND_IGNORE
;
3000 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3002 /* Zero length reply means that we tried 'S' or 'C' and
3003 the remote system doesn't support it. */
3004 target_terminal_ours_for_output ();
3006 ("Can't send signals to this remote system. %s not sent.\n",
3007 target_signal_to_name (last_sent_signal
));
3008 last_sent_signal
= TARGET_SIGNAL_0
;
3009 target_terminal_inferior ();
3011 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3012 putpkt ((char *) buf
);
3015 /* else fallthrough */
3017 warning ("Invalid remote reply: %s", buf
);
3022 if (thread_num
!= -1)
3026 return inferior_pid
;
3029 /* Number of bytes of registers this stub implements. */
3031 static int register_bytes_found
;
3033 /* Read the remote registers into the block REGS. */
3034 /* Currently we just read all the registers, so we don't use regno. */
3038 remote_fetch_registers (int regno
)
3040 char *buf
= alloca (PBUFSIZ
);
3043 char regs
[REGISTER_BYTES
];
3045 set_thread (inferior_pid
, 1);
3048 remote_send (buf
, PBUFSIZ
);
3050 /* Save the size of the packet sent to us by the target. Its used
3051 as a heuristic when determining the max size of packets that the
3052 target can safely receive. */
3053 if (actual_register_packet_size
== 0)
3054 actual_register_packet_size
= strlen (buf
);
3056 /* Unimplemented registers read as all bits zero. */
3057 memset (regs
, 0, REGISTER_BYTES
);
3059 /* We can get out of synch in various cases. If the first character
3060 in the buffer is not a hex character, assume that has happened
3061 and try to fetch another packet to read. */
3062 while ((buf
[0] < '0' || buf
[0] > '9')
3063 && (buf
[0] < 'a' || buf
[0] > 'f')
3064 && buf
[0] != 'x') /* New: unavailable register value */
3067 fprintf_unfiltered (gdb_stdlog
,
3068 "Bad register packet; fetching a new packet\n");
3069 getpkt (buf
, PBUFSIZ
, 0);
3072 /* Reply describes registers byte by byte, each byte encoded as two
3073 hex characters. Suck them all up, then supply them to the
3074 register cacheing/storage mechanism. */
3077 for (i
= 0; i
< REGISTER_BYTES
; i
++)
3083 warning ("Remote reply is of odd length: %s", buf
);
3084 /* Don't change register_bytes_found in this case, and don't
3085 print a second warning. */
3088 if (p
[0] == 'x' && p
[1] == 'x')
3089 regs
[i
] = 0; /* 'x' */
3091 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3095 if (i
!= register_bytes_found
)
3097 register_bytes_found
= i
;
3098 #ifdef REGISTER_BYTES_OK
3099 if (!REGISTER_BYTES_OK (i
))
3100 warning ("Remote reply is too short: %s", buf
);
3105 for (i
= 0; i
< NUM_REGS
; i
++)
3107 supply_register (i
, ®s
[REGISTER_BYTE (i
)]);
3108 if (buf
[REGISTER_BYTE (i
) * 2] == 'x')
3109 register_valid
[i
] = -1; /* register value not available */
3113 /* Prepare to store registers. Since we may send them all (using a
3114 'G' request), we have to read out the ones we don't want to change
3118 remote_prepare_to_store (void)
3120 /* Make sure the entire registers array is valid. */
3121 switch (remote_protocol_P
.support
)
3123 case PACKET_DISABLE
:
3124 case PACKET_SUPPORT_UNKNOWN
:
3125 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
);
3132 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
3133 packet was not recognized. */
3136 store_register_using_P (int regno
)
3138 /* Try storing a single register. */
3139 char *buf
= alloca (PBUFSIZ
);
3144 sprintf (buf
, "P%x=", regno
);
3145 p
= buf
+ strlen (buf
);
3146 regp
= ®isters
[REGISTER_BYTE (regno
)];
3147 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
3149 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
3150 *p
++ = tohex (regp
[i
] & 0xf);
3153 remote_send (buf
, PBUFSIZ
);
3155 return buf
[0] != '\0';
3159 /* Store register REGNO, or all registers if REGNO == -1, from the contents
3160 of REGISTERS. FIXME: ignores errors. */
3163 remote_store_registers (int regno
)
3165 char *buf
= alloca (PBUFSIZ
);
3169 set_thread (inferior_pid
, 1);
3173 switch (remote_protocol_P
.support
)
3175 case PACKET_DISABLE
:
3178 if (store_register_using_P (regno
))
3181 error ("Protocol error: P packet not recognized by stub");
3182 case PACKET_SUPPORT_UNKNOWN
:
3183 if (store_register_using_P (regno
))
3185 /* The stub recognized the 'P' packet. Remember this. */
3186 remote_protocol_P
.support
= PACKET_ENABLE
;
3191 /* The stub does not support the 'P' packet. Use 'G'
3192 instead, and don't try using 'P' in the future (it
3193 will just waste our time). */
3194 remote_protocol_P
.support
= PACKET_DISABLE
;
3202 /* Command describes registers byte by byte,
3203 each byte encoded as two hex characters. */
3206 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3207 for (i
= 0; i
< register_bytes_found
; i
++)
3209 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
3210 *p
++ = tohex (registers
[i
] & 0xf);
3214 remote_send (buf
, PBUFSIZ
);
3218 /* Return the number of hex digits in num. */
3221 hexnumlen (ULONGEST num
)
3225 for (i
= 0; num
!= 0; i
++)
3231 /* Set BUF to the minimum number of hex digits representing NUM. */
3234 hexnumstr (char *buf
, ULONGEST num
)
3236 int len
= hexnumlen (num
);
3237 return hexnumnstr (buf
, num
, len
);
3241 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3244 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3250 for (i
= width
- 1; i
>= 0; i
--)
3252 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3259 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3262 remote_address_masked (CORE_ADDR addr
)
3264 if (remote_address_size
> 0
3265 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3267 /* Only create a mask when that mask can safely be constructed
3268 in a ULONGEST variable. */
3270 mask
= (mask
<< remote_address_size
) - 1;
3276 /* Determine whether the remote target supports binary downloading.
3277 This is accomplished by sending a no-op memory write of zero length
3278 to the target at the specified address. It does not suffice to send
3279 the whole packet, since many stubs strip the eighth bit and subsequently
3280 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3282 NOTE: This can still lose if the serial line is not eight-bit
3283 clean. In cases like this, the user should clear "remote
3287 check_binary_download (CORE_ADDR addr
)
3289 switch (remote_protocol_binary_download
.support
)
3291 case PACKET_DISABLE
:
3295 case PACKET_SUPPORT_UNKNOWN
:
3297 char *buf
= alloca (PBUFSIZ
);
3302 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3304 p
+= hexnumstr (p
, (ULONGEST
) 0);
3308 putpkt_binary (buf
, (int) (p
- buf
));
3309 getpkt (buf
, PBUFSIZ
, 0);
3314 fprintf_unfiltered (gdb_stdlog
,
3315 "binary downloading NOT suppported by target\n");
3316 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3321 fprintf_unfiltered (gdb_stdlog
,
3322 "binary downloading suppported by target\n");
3323 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3330 /* Write memory data directly to the remote machine.
3331 This does not inform the data cache; the data cache uses this.
3332 MEMADDR is the address in the remote memory space.
3333 MYADDR is the address of the buffer in our space.
3334 LEN is the number of bytes.
3336 Returns number of bytes transferred, or 0 (setting errno) for
3337 error. Only transfer a single packet. */
3340 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3343 int max_buf_size
; /* Max size of packet output buffer */
3345 unsigned char *plen
;
3351 /* Verify that the target can support a binary download */
3352 check_binary_download (memaddr
);
3354 /* Determine the max packet size. */
3355 max_buf_size
= get_memory_write_packet_size ();
3356 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3357 buf
= alloca (sizeof_buf
);
3359 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3360 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3362 /* construct "M"<memaddr>","<len>":" */
3363 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3366 /* Append [XM]. Compute a best guess of the number of bytes
3367 actually transfered. */
3368 switch (remote_protocol_binary_download
.support
)
3372 /* Best guess at number of bytes that will fit. */
3373 todo
= min (len
, max_buf_size
);
3375 case PACKET_DISABLE
:
3377 /* num bytes that will fit */
3378 todo
= min (len
, max_buf_size
/ 2);
3380 case PACKET_SUPPORT_UNKNOWN
:
3381 internal_error ("remote_write_bytes: bad switch");
3384 /* Append <memaddr> */
3385 memaddr
= remote_address_masked (memaddr
);
3386 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3389 /* Append <len>. Retain the location/size of <len>. It may
3390 need to be adjusted once the packet body has been created. */
3392 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3397 /* Append the packet body. */
3398 switch (remote_protocol_binary_download
.support
)
3401 /* Binary mode. Send target system values byte by byte, in
3402 increasing byte addresses. Only escape certain critical
3405 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3408 switch (myaddr
[nr_bytes
] & 0xff)
3413 /* These must be escaped */
3415 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3418 *p
++ = myaddr
[nr_bytes
] & 0xff;
3422 if (nr_bytes
< todo
)
3424 /* Escape chars have filled up the buffer prematurely,
3425 and we have actually sent fewer bytes than planned.
3426 Fix-up the length field of the packet. Use the same
3427 number of characters as before. */
3429 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3430 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3433 case PACKET_DISABLE
:
3434 /* Normal mode: Send target system values byte by byte, in
3435 increasing byte addresses. Each byte is encoded as a two hex
3437 for (nr_bytes
= 0; nr_bytes
< todo
; nr_bytes
++)
3439 *p
++ = tohex ((myaddr
[nr_bytes
] >> 4) & 0xf);
3440 *p
++ = tohex (myaddr
[nr_bytes
] & 0xf);
3444 case PACKET_SUPPORT_UNKNOWN
:
3445 internal_error ("remote_write_bytes: bad switch");
3448 putpkt_binary (buf
, (int) (p
- buf
));
3449 getpkt (buf
, sizeof_buf
, 0);
3453 /* There is no correspondance between what the remote protocol
3454 uses for errors and errno codes. We would like a cleaner way
3455 of representing errors (big enough to include errno codes,
3456 bfd_error codes, and others). But for now just return EIO. */
3461 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3462 bytes than we'd planned. */
3466 /* Read memory data directly from the remote machine.
3467 This does not use the data cache; the data cache uses this.
3468 MEMADDR is the address in the remote memory space.
3469 MYADDR is the address of the buffer in our space.
3470 LEN is the number of bytes.
3472 Returns number of bytes transferred, or 0 for error. */
3474 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3475 remote targets) shouldn't attempt to read the entire buffer.
3476 Instead it should read a single packet worth of data and then
3477 return the byte size of that packet to the caller. The caller (its
3478 caller and its callers caller ;-) already contains code for
3479 handling partial reads. */
3482 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3485 int max_buf_size
; /* Max size of packet output buffer */
3489 /* Create a buffer big enough for this packet. */
3490 max_buf_size
= get_memory_read_packet_size ();
3491 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3492 buf
= alloca (sizeof_buf
);
3501 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3503 /* construct "m"<memaddr>","<len>" */
3504 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3505 memaddr
= remote_address_masked (memaddr
);
3508 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3510 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3514 getpkt (buf
, sizeof_buf
, 0);
3518 /* There is no correspondance between what the remote protocol uses
3519 for errors and errno codes. We would like a cleaner way of
3520 representing errors (big enough to include errno codes, bfd_error
3521 codes, and others). But for now just return EIO. */
3526 /* Reply describes memory byte by byte,
3527 each byte encoded as two hex characters. */
3530 for (i
= 0; i
< todo
; i
++)
3532 if (p
[0] == 0 || p
[1] == 0)
3533 /* Reply is short. This means that we were able to read
3534 only part of what we wanted to. */
3535 return i
+ (origlen
- len
);
3536 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3546 /* Read or write LEN bytes from inferior memory at MEMADDR,
3547 transferring to or from debugger address BUFFER. Write to inferior if
3548 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3553 remote_xfer_memory (mem_addr
, buffer
, mem_len
, should_write
, target
)
3558 struct target_ops
*target
; /* ignored */
3560 CORE_ADDR targ_addr
;
3562 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3566 return dcache_xfer_memory (remote_dcache
, targ_addr
, buffer
,
3567 targ_len
, should_write
);
3572 /* Enable after 4.12. */
3575 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
3576 addr_found
, data_found
)
3580 CORE_ADDR startaddr
;
3584 CORE_ADDR
*addr_found
;
3587 if (increment
== -4 && len
== 4)
3589 long mask_long
, data_long
;
3590 long data_found_long
;
3591 CORE_ADDR addr_we_found
;
3592 char *buf
= alloca (PBUFSIZ
);
3593 long returned_long
[2];
3596 mask_long
= extract_unsigned_integer (mask
, len
);
3597 data_long
= extract_unsigned_integer (data
, len
);
3598 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
3600 getpkt (buf
, PBUFSIZ
, 0);
3603 /* The stub doesn't support the 't' request. We might want to
3604 remember this fact, but on the other hand the stub could be
3605 switched on us. Maybe we should remember it only until
3606 the next "target remote". */
3607 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3608 hirange
, addr_found
, data_found
);
3613 /* There is no correspondance between what the remote protocol uses
3614 for errors and errno codes. We would like a cleaner way of
3615 representing errors (big enough to include errno codes, bfd_error
3616 codes, and others). But for now just use EIO. */
3617 memory_error (EIO
, startaddr
);
3620 while (*p
!= '\0' && *p
!= ',')
3621 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
3623 error ("Protocol error: short return for search");
3625 data_found_long
= 0;
3626 while (*p
!= '\0' && *p
!= ',')
3627 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
3628 /* Ignore anything after this comma, for future extensions. */
3630 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
3636 *addr_found
= addr_we_found
;
3637 *data_found
= store_unsigned_integer (data_we_found
, len
);
3640 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3641 hirange
, addr_found
, data_found
);
3646 remote_files_info (struct target_ops
*ignore
)
3648 puts_filtered ("Debugging a target over a serial line.\n");
3651 /* Stuff for dealing with the packets which are part of this protocol.
3652 See comment at top of file for details. */
3654 /* Read a single character from the remote end, masking it down to 7 bits. */
3657 readchar (int timeout
)
3661 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
3666 switch ((enum serial_rc
) ch
)
3669 target_mourn_inferior ();
3670 error ("Remote connection closed");
3673 perror_with_name ("Remote communication error");
3675 case SERIAL_TIMEOUT
:
3681 /* Send the command in BUF to the remote machine, and read the reply
3682 into BUF. Report an error if we get an error reply. */
3685 remote_send (char *buf
,
3689 getpkt (buf
, sizeof_buf
, 0);
3692 error ("Remote failure reply: %s", buf
);
3695 /* Display a null-terminated packet on stdout, for debugging, using C
3699 print_packet (char *buf
)
3701 puts_filtered ("\"");
3702 fputstr_filtered (buf
, '"', gdb_stdout
);
3703 puts_filtered ("\"");
3709 return putpkt_binary (buf
, strlen (buf
));
3712 /* Send a packet to the remote machine, with error checking. The data
3713 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3714 to account for the $, # and checksum, and for a possible /0 if we are
3715 debugging (remote_debug) and want to print the sent packet as a string */
3718 putpkt_binary (char *buf
, int cnt
)
3721 unsigned char csum
= 0;
3722 char *buf2
= alloca (cnt
+ 6);
3723 long sizeof_junkbuf
= PBUFSIZ
;
3724 char *junkbuf
= alloca (sizeof_junkbuf
);
3730 /* Copy the packet into buffer BUF2, encapsulating it
3731 and giving it a checksum. */
3736 for (i
= 0; i
< cnt
; i
++)
3742 *p
++ = tohex ((csum
>> 4) & 0xf);
3743 *p
++ = tohex (csum
& 0xf);
3745 /* Send it over and over until we get a positive ack. */
3749 int started_error_output
= 0;
3754 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
3755 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
3756 fprintf_unfiltered (gdb_stdlog
, "...");
3757 gdb_flush (gdb_stdlog
);
3759 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
3760 perror_with_name ("putpkt: write failed");
3762 /* read until either a timeout occurs (-2) or '+' is read */
3765 ch
= readchar (remote_timeout
);
3773 case SERIAL_TIMEOUT
:
3775 if (started_error_output
)
3777 putchar_unfiltered ('\n');
3778 started_error_output
= 0;
3787 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
3791 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
3792 case SERIAL_TIMEOUT
:
3796 break; /* Retransmit buffer */
3799 /* It's probably an old response, and we're out of sync.
3800 Just gobble up the packet and ignore it. */
3801 getpkt (junkbuf
, sizeof_junkbuf
, 0);
3802 continue; /* Now, go look for + */
3807 if (!started_error_output
)
3809 started_error_output
= 1;
3810 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
3812 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
3816 break; /* Here to retransmit */
3820 /* This is wrong. If doing a long backtrace, the user should be
3821 able to get out next time we call QUIT, without anything as
3822 violent as interrupt_query. If we want to provide a way out of
3823 here without getting to the next QUIT, it should be based on
3824 hitting ^C twice as in remote_wait. */
3834 static int remote_cisco_mode
;
3836 /* Come here after finding the start of the frame. Collect the rest
3837 into BUF, verifying the checksum, length, and handling run-length
3838 compression. No more than sizeof_buf-1 characters are read so that
3839 the buffer can be NUL terminated.
3841 Returns -1 on error, number of characters in buffer (ignoring the
3842 trailing NULL) on success. (could be extended to return one of the
3843 SERIAL status indications). */
3846 read_frame (char *buf
,
3858 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
3859 c
= readchar (remote_timeout
);
3862 case SERIAL_TIMEOUT
:
3864 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
3868 fputs_filtered ("Saw new packet start in middle of old one\n",
3870 return -1; /* Start a new packet, count retries */
3873 unsigned char pktcsum
;
3877 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
3878 pktcsum
|= fromhex (readchar (remote_timeout
));
3880 if (csum
== pktcsum
)
3885 fprintf_filtered (gdb_stdlog
,
3886 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3888 fputs_filtered (buf
, gdb_stdlog
);
3889 fputs_filtered ("\n", gdb_stdlog
);
3891 /* Number of characters in buffer ignoring trailing
3895 case '*': /* Run length encoding */
3900 if (remote_cisco_mode
== 0)
3902 c
= readchar (remote_timeout
);
3904 repeat
= c
- ' ' + 3; /* Compute repeat count */
3908 /* Cisco's run-length encoding variant uses two
3909 hex chars to represent the repeat count. */
3911 c
= readchar (remote_timeout
);
3913 repeat
= fromhex (c
) << 4;
3914 c
= readchar (remote_timeout
);
3916 repeat
+= fromhex (c
);
3919 /* The character before ``*'' is repeated. */
3921 if (repeat
> 0 && repeat
<= 255
3923 && bc
+ repeat
< sizeof_buf
- 1)
3925 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
3931 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
3932 puts_filtered (buf
);
3933 puts_filtered ("\n");
3937 if (bc
< sizeof_buf
- 1)
3945 puts_filtered ("Remote packet too long: ");
3946 puts_filtered (buf
);
3947 puts_filtered ("\n");
3954 /* Read a packet from the remote machine, with error checking, and
3955 store it in BUF. If FOREVER, wait forever rather than timing out;
3956 this is used (in synchronous mode) to wait for a target that is is
3957 executing user code to stop. */
3958 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
3959 don't have to change all the calls to getpkt to deal with the
3960 return value, because at the moment I don't know what the right
3961 thing to do it for those. */
3969 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
3973 /* Read a packet from the remote machine, with error checking, and
3974 store it in BUF. If FOREVER, wait forever rather than timing out;
3975 this is used (in synchronous mode) to wait for a target that is is
3976 executing user code to stop. If FOREVER == 0, this function is
3977 allowed to time out gracefully and return an indication of this to
3980 getpkt_sane (char *buf
,
3989 strcpy (buf
, "timeout");
3993 timeout
= watchdog
> 0 ? watchdog
: -1;
3997 timeout
= remote_timeout
;
4001 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4003 /* This can loop forever if the remote side sends us characters
4004 continuously, but if it pauses, we'll get a zero from readchar
4005 because of timeout. Then we'll count that as a retry. */
4007 /* Note that we will only wait forever prior to the start of a packet.
4008 After that, we expect characters to arrive at a brisk pace. They
4009 should show up within remote_timeout intervals. */
4013 c
= readchar (timeout
);
4015 if (c
== SERIAL_TIMEOUT
)
4017 if (forever
) /* Watchdog went off? Kill the target. */
4020 target_mourn_inferior ();
4021 error ("Watchdog has expired. Target detached.\n");
4024 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4030 /* We've found the start of a packet, now collect the data. */
4032 val
= read_frame (buf
, sizeof_buf
);
4038 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4039 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4040 fprintf_unfiltered (gdb_stdlog
, "\n");
4042 SERIAL_WRITE (remote_desc
, "+", 1);
4046 /* Try the whole thing again. */
4048 SERIAL_WRITE (remote_desc
, "-", 1);
4051 /* We have tried hard enough, and just can't receive the packet. Give up. */
4053 printf_unfiltered ("Ignoring packet error, continuing...\n");
4054 SERIAL_WRITE (remote_desc
, "+", 1);
4061 /* For some mysterious reason, wait_for_inferior calls kill instead of
4062 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4066 target_mourn_inferior ();
4070 /* Use catch_errors so the user can quit from gdb even when we aren't on
4071 speaking terms with the remote system. */
4072 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4074 /* Don't wait for it to die. I'm not really sure it matters whether
4075 we do or not. For the existing stubs, kill is a noop. */
4076 target_mourn_inferior ();
4079 /* Async version of remote_kill. */
4081 remote_async_kill (void)
4083 /* Unregister the file descriptor from the event loop. */
4084 if (target_is_async_p ())
4085 SERIAL_ASYNC (remote_desc
, NULL
, 0);
4087 /* For some mysterious reason, wait_for_inferior calls kill instead of
4088 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4092 target_mourn_inferior ();
4096 /* Use catch_errors so the user can quit from gdb even when we aren't on
4097 speaking terms with the remote system. */
4098 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4100 /* Don't wait for it to die. I'm not really sure it matters whether
4101 we do or not. For the existing stubs, kill is a noop. */
4102 target_mourn_inferior ();
4108 remote_mourn_1 (&remote_ops
);
4112 remote_async_mourn (void)
4114 remote_mourn_1 (&remote_async_ops
);
4118 extended_remote_mourn (void)
4120 /* We do _not_ want to mourn the target like this; this will
4121 remove the extended remote target from the target stack,
4122 and the next time the user says "run" it'll fail.
4124 FIXME: What is the right thing to do here? */
4126 remote_mourn_1 (&extended_remote_ops
);
4130 /* Worker function for remote_mourn. */
4132 remote_mourn_1 (struct target_ops
*target
)
4134 unpush_target (target
);
4135 generic_mourn_inferior ();
4138 /* In the extended protocol we want to be able to do things like
4139 "run" and have them basically work as expected. So we need
4140 a special create_inferior function.
4142 FIXME: One day add support for changing the exec file
4143 we're debugging, arguments and an environment. */
4146 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4148 /* Rip out the breakpoints; we'll reinsert them after restarting
4149 the remote server. */
4150 remove_breakpoints ();
4152 /* Now restart the remote server. */
4153 extended_remote_restart ();
4155 /* Now put the breakpoints back in. This way we're safe if the
4156 restart function works via a unix fork on the remote side. */
4157 insert_breakpoints ();
4159 /* Clean up from the last time we were running. */
4160 clear_proceed_status ();
4162 /* Let the remote process run. */
4163 proceed (-1, TARGET_SIGNAL_0
, 0);
4166 /* Async version of extended_remote_create_inferior. */
4168 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4170 /* Rip out the breakpoints; we'll reinsert them after restarting
4171 the remote server. */
4172 remove_breakpoints ();
4174 /* If running asynchronously, register the target file descriptor
4175 with the event loop. */
4176 if (event_loop_p
&& target_can_async_p ())
4177 target_async (inferior_event_handler
, 0);
4179 /* Now restart the remote server. */
4180 extended_remote_restart ();
4182 /* Now put the breakpoints back in. This way we're safe if the
4183 restart function works via a unix fork on the remote side. */
4184 insert_breakpoints ();
4186 /* Clean up from the last time we were running. */
4187 clear_proceed_status ();
4189 /* Let the remote process run. */
4190 proceed (-1, TARGET_SIGNAL_0
, 0);
4194 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4195 than other targets; in those use REMOTE_BREAKPOINT instead of just
4196 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4197 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4198 the standard routines that are in mem-break.c. */
4200 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4201 the choice of breakpoint instruction affects target program design and
4202 vice versa, and by making it user-tweakable, the special code here
4203 goes away and we need fewer special GDB configurations. */
4205 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4206 #define REMOTE_BREAKPOINT
4209 #ifdef REMOTE_BREAKPOINT
4211 /* If the target isn't bi-endian, just pretend it is. */
4212 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4213 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4214 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4217 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
4218 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
4220 #endif /* REMOTE_BREAKPOINT */
4222 /* Insert a breakpoint on targets that don't have any better breakpoint
4223 support. We read the contents of the target location and stash it,
4224 then overwrite it with a breakpoint instruction. ADDR is the target
4225 location in the target machine. CONTENTS_CACHE is a pointer to
4226 memory allocated for saving the target contents. It is guaranteed
4227 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4228 is accomplished via BREAKPOINT_MAX). */
4231 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4233 #ifdef REMOTE_BREAKPOINT
4238 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4239 If it succeeds, then set the support to PACKET_ENABLE. If it
4240 fails, and the user has explicitly requested the Z support then
4241 report an error, otherwise, mark it disabled and go on. */
4243 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4245 char *buf
= alloca (PBUFSIZ
);
4248 addr
= remote_address_masked (addr
);
4252 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4253 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4254 sprintf (p
, ",%d", bp_size
);
4257 getpkt (buf
, PBUFSIZ
, 0);
4259 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4265 case PACKET_UNKNOWN
:
4270 #ifdef REMOTE_BREAKPOINT
4271 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4275 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
4276 val
= target_write_memory (addr
, (char *) big_break_insn
,
4277 sizeof big_break_insn
);
4279 val
= target_write_memory (addr
, (char *) little_break_insn
,
4280 sizeof little_break_insn
);
4285 return memory_insert_breakpoint (addr
, contents_cache
);
4286 #endif /* REMOTE_BREAKPOINT */
4290 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4294 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4296 char *buf
= alloca (PBUFSIZ
);
4303 addr
= remote_address_masked (addr
);
4304 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4305 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4306 sprintf (p
, ",%d", bp_size
);
4309 getpkt (buf
, PBUFSIZ
, 0);
4311 return (buf
[0] == 'E');
4314 #ifdef REMOTE_BREAKPOINT
4315 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4317 return memory_remove_breakpoint (addr
, contents_cache
);
4318 #endif /* REMOTE_BREAKPOINT */
4322 watchpoint_to_Z_packet (int type
)
4336 internal_error ("hw_bp_to_z: bad watchpoint type %d", type
);
4340 /* FIXME: This function should be static and a member of the remote
4344 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4346 char *buf
= alloca (PBUFSIZ
);
4348 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4350 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4351 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4352 remote_protocol_Z
[packet
].name
,
4353 remote_protocol_Z
[packet
].title
);
4355 sprintf (buf
, "Z%x,", packet
);
4356 p
= strchr (buf
, '\0');
4357 addr
= remote_address_masked (addr
);
4358 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4359 sprintf (p
, ",%x", len
);
4362 getpkt (buf
, PBUFSIZ
, 0);
4364 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4367 case PACKET_UNKNOWN
:
4372 internal_error ("remote_insert_watchpoint: reached end of function");
4375 /* FIXME: This function should be static and a member of the remote
4379 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4381 char *buf
= alloca (PBUFSIZ
);
4383 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4385 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4386 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4387 remote_protocol_Z
[packet
].name
,
4388 remote_protocol_Z
[packet
].title
);
4390 sprintf (buf
, "z%x,", packet
);
4391 p
= strchr (buf
, '\0');
4392 addr
= remote_address_masked (addr
);
4393 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4394 sprintf (p
, ",%x", len
);
4396 getpkt (buf
, PBUFSIZ
, 0);
4398 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4401 case PACKET_UNKNOWN
:
4406 internal_error ("remote_remove_watchpoint: reached end of function");
4409 /* FIXME: This function should be static and a member of the remote
4413 remote_insert_hw_breakpoint (CORE_ADDR addr
, int len
)
4415 char *buf
= alloca (PBUFSIZ
);
4418 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4419 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4420 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4421 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4427 addr
= remote_address_masked (addr
);
4428 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4432 getpkt (buf
, PBUFSIZ
, 0);
4434 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4437 case PACKET_UNKNOWN
:
4442 internal_error ("remote_remove_watchpoint: reached end of function");
4445 /* FIXME: This function should be static and a member of the remote
4449 remote_remove_hw_breakpoint (CORE_ADDR addr
, int len
)
4451 char *buf
= alloca (PBUFSIZ
);
4454 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4455 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4456 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4457 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4463 addr
= remote_address_masked (addr
);
4464 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4468 getpkt (buf
, PBUFSIZ
, 0);
4470 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4473 case PACKET_UNKNOWN
:
4478 internal_error ("remote_remove_watchpoint: reached end of function");
4481 /* Some targets are only capable of doing downloads, and afterwards
4482 they switch to the remote serial protocol. This function provides
4483 a clean way to get from the download target to the remote target.
4484 It's basically just a wrapper so that we don't have to expose any
4485 of the internal workings of remote.c.
4487 Prior to calling this routine, you should shutdown the current
4488 target code, else you will get the "A program is being debugged
4489 already..." message. Usually a call to pop_target() suffices. */
4492 push_remote_target (char *name
, int from_tty
)
4494 printf_filtered ("Switching to remote protocol\n");
4495 remote_open (name
, from_tty
);
4498 /* Other targets want to use the entire remote serial module but with
4499 certain remote_ops overridden. */
4502 open_remote_target (char *name
, int from_tty
, struct target_ops
*target
,
4505 printf_filtered ("Selecting the %sremote protocol\n",
4506 (extended_p
? "extended-" : ""));
4507 remote_open_1 (name
, from_tty
, target
, extended_p
);
4510 /* Table used by the crc32 function to calcuate the checksum. */
4512 static unsigned long crc32_table
[256] =
4515 static unsigned long
4516 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4518 if (!crc32_table
[1])
4520 /* Initialize the CRC table and the decoding table. */
4524 for (i
= 0; i
< 256; i
++)
4526 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4527 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4534 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4540 /* compare-sections command
4542 With no arguments, compares each loadable section in the exec bfd
4543 with the same memory range on the target, and reports mismatches.
4544 Useful for verifying the image on the target against the exec file.
4545 Depends on the target understanding the new "qCRC:" request. */
4547 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4548 target method (target verify memory) and generic version of the
4549 actual command. This will allow other high-level code (especially
4550 generic_load()) to make use of this target functionality. */
4553 compare_sections_command (char *args
, int from_tty
)
4556 unsigned long host_crc
, target_crc
;
4557 extern bfd
*exec_bfd
;
4558 struct cleanup
*old_chain
;
4562 char *buf
= alloca (PBUFSIZ
);
4569 error ("command cannot be used without an exec file");
4570 if (!current_target
.to_shortname
||
4571 strcmp (current_target
.to_shortname
, "remote") != 0)
4572 error ("command can only be used with remote target");
4574 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4576 if (!(s
->flags
& SEC_LOAD
))
4577 continue; /* skip non-loadable section */
4579 size
= bfd_get_section_size_before_reloc (s
);
4581 continue; /* skip zero-length section */
4583 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
4584 if (args
&& strcmp (args
, sectname
) != 0)
4585 continue; /* not the section selected by user */
4587 matched
= 1; /* do this section */
4589 /* FIXME: assumes lma can fit into long */
4590 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
4593 /* be clever; compute the host_crc before waiting for target reply */
4594 sectdata
= xmalloc (size
);
4595 old_chain
= make_cleanup (free
, sectdata
);
4596 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4597 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4599 getpkt (buf
, PBUFSIZ
, 0);
4601 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4602 sectname
, lma
, lma
+ size
);
4604 error ("remote target does not support this operation");
4606 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4607 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4609 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4610 sectname
, paddr (lma
), paddr (lma
+ size
));
4611 if (host_crc
== target_crc
)
4612 printf_filtered ("matched.\n");
4615 printf_filtered ("MIS-MATCHED!\n");
4619 do_cleanups (old_chain
);
4622 warning ("One or more sections of the remote executable does not match\n\
4623 the loaded file\n");
4624 if (args
&& !matched
)
4625 printf_filtered ("No loaded section named '%s'.\n", args
);
4629 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
4632 char *buf2
= alloca (PBUFSIZ
);
4633 char *p2
= &buf2
[0];
4636 error ("null pointer to remote bufer size specified");
4638 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4639 the caller know and return what the minimum size is */
4640 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4641 if (*bufsiz
< PBUFSIZ
)
4647 /* except for querying the minimum buffer size, target must be open */
4649 error ("remote query is only available after target open");
4651 /* we only take uppercase letters as query types, at least for now */
4652 if ((query_type
< 'A') || (query_type
> 'Z'))
4653 error ("invalid remote query type");
4656 error ("null remote query specified");
4659 error ("remote query requires a buffer to receive data");
4666 /* we used one buffer char for the remote protocol q command and another
4667 for the query type. As the remote protocol encapsulation uses 4 chars
4668 plus one extra in case we are debugging (remote_debug),
4669 we have PBUFZIZ - 7 left to pack the query string */
4671 while (buf
[i
] && (i
< (PBUFSIZ
- 8)))
4673 /* bad caller may have sent forbidden characters */
4674 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
4675 error ("illegal characters in query string");
4683 error ("query larger than available buffer");
4689 getpkt (outbuf
, *bufsiz
, 0);
4695 remote_rcmd (char *command
,
4696 struct ui_file
*outbuf
)
4699 char *buf
= alloca (PBUFSIZ
);
4703 error ("remote rcmd is only available after target open");
4705 /* Send a NULL command across as an empty command */
4706 if (command
== NULL
)
4709 /* The query prefix */
4710 strcpy (buf
, "qRcmd,");
4711 p
= strchr (buf
, '\0');
4713 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > PBUFSIZ
)
4714 error ("\"monitor\" command ``%s'' is too long\n", command
);
4716 /* Encode the actual command */
4717 for (i
= 0; command
[i
]; i
++)
4719 *p
++ = tohex ((command
[i
] >> 4) & 0xf);
4720 *p
++ = tohex (command
[i
] & 0xf);
4724 if (putpkt (buf
) < 0)
4725 error ("Communication problem with target\n");
4727 /* get/display the response */
4730 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4732 getpkt (buf
, PBUFSIZ
, 0);
4734 error ("Target does not support this command\n");
4735 if (buf
[0] == 'O' && buf
[1] != 'K')
4737 remote_console_output (buf
+ 1); /* 'O' message from stub */
4740 if (strcmp (buf
, "OK") == 0)
4742 if (strlen (buf
) == 3 && buf
[0] == 'E'
4743 && isdigit (buf
[1]) && isdigit (buf
[2]))
4745 error ("Protocol error with Rcmd");
4747 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
4749 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
4750 fputc_unfiltered (c
, outbuf
);
4757 packet_command (char *args
, int from_tty
)
4759 char *buf
= alloca (PBUFSIZ
);
4762 error ("command can only be used with remote target");
4765 error ("remote-packet command requires packet text as argument");
4767 puts_filtered ("sending: ");
4768 print_packet (args
);
4769 puts_filtered ("\n");
4772 getpkt (buf
, PBUFSIZ
, 0);
4773 puts_filtered ("received: ");
4775 puts_filtered ("\n");
4779 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4781 static void display_thread_info (struct gdb_ext_thread_info
*info
);
4783 static void threadset_test_cmd (char *cmd
, int tty
);
4785 static void threadalive_test (char *cmd
, int tty
);
4787 static void threadlist_test_cmd (char *cmd
, int tty
);
4789 int get_and_display_threadinfo (threadref
* ref
);
4791 static void threadinfo_test_cmd (char *cmd
, int tty
);
4793 static int thread_display_step (threadref
* ref
, void *context
);
4795 static void threadlist_update_test_cmd (char *cmd
, int tty
);
4797 static void init_remote_threadtests (void);
4799 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4802 threadset_test_cmd (char *cmd
, int tty
)
4804 int sample_thread
= SAMPLE_THREAD
;
4806 printf_filtered ("Remote threadset test\n");
4807 set_thread (sample_thread
, 1);
4812 threadalive_test (char *cmd
, int tty
)
4814 int sample_thread
= SAMPLE_THREAD
;
4816 if (remote_thread_alive (sample_thread
))
4817 printf_filtered ("PASS: Thread alive test\n");
4819 printf_filtered ("FAIL: Thread alive test\n");
4822 void output_threadid (char *title
, threadref
* ref
);
4825 output_threadid (char *title
, threadref
*ref
)
4829 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
4831 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
4835 threadlist_test_cmd (char *cmd
, int tty
)
4838 threadref nextthread
;
4839 int done
, result_count
;
4840 threadref threadlist
[3];
4842 printf_filtered ("Remote Threadlist test\n");
4843 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
4844 &result_count
, &threadlist
[0]))
4845 printf_filtered ("FAIL: threadlist test\n");
4848 threadref
*scan
= threadlist
;
4849 threadref
*limit
= scan
+ result_count
;
4851 while (scan
< limit
)
4852 output_threadid (" thread ", scan
++);
4857 display_thread_info (struct gdb_ext_thread_info
*info
)
4859 output_threadid ("Threadid: ", &info
->threadid
);
4860 printf_filtered ("Name: %s\n ", info
->shortname
);
4861 printf_filtered ("State: %s\n", info
->display
);
4862 printf_filtered ("other: %s\n\n", info
->more_display
);
4866 get_and_display_threadinfo (threadref
*ref
)
4870 struct gdb_ext_thread_info threadinfo
;
4872 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
4873 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
4874 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
4875 display_thread_info (&threadinfo
);
4880 threadinfo_test_cmd (char *cmd
, int tty
)
4882 int athread
= SAMPLE_THREAD
;
4886 int_to_threadref (&thread
, athread
);
4887 printf_filtered ("Remote Threadinfo test\n");
4888 if (!get_and_display_threadinfo (&thread
))
4889 printf_filtered ("FAIL cannot get thread info\n");
4893 thread_display_step (threadref
*ref
, void *context
)
4895 /* output_threadid(" threadstep ",ref); *//* simple test */
4896 return get_and_display_threadinfo (ref
);
4900 threadlist_update_test_cmd (char *cmd
, int tty
)
4902 printf_filtered ("Remote Threadlist update test\n");
4903 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
4907 init_remote_threadtests (void)
4909 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
4910 "Fetch and print the remote list of thread identifiers, one pkt only");
4911 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
4912 "Fetch and display info about one thread");
4913 add_com ("tset", class_obscure
, threadset_test_cmd
,
4914 "Test setting to a different thread");
4915 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
4916 "Iterate through updating all remote thread info");
4917 add_com ("talive", class_obscure
, threadalive_test
,
4918 " Remote thread alive test ");
4924 init_remote_ops (void)
4926 remote_ops
.to_shortname
= "remote";
4927 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
4929 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4930 Specify the serial device it is connected to\n\
4931 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
4932 remote_ops
.to_open
= remote_open
;
4933 remote_ops
.to_close
= remote_close
;
4934 remote_ops
.to_detach
= remote_detach
;
4935 remote_ops
.to_resume
= remote_resume
;
4936 remote_ops
.to_wait
= remote_wait
;
4937 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
4938 remote_ops
.to_store_registers
= remote_store_registers
;
4939 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
4940 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
4941 remote_ops
.to_files_info
= remote_files_info
;
4942 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
4943 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
4944 remote_ops
.to_kill
= remote_kill
;
4945 remote_ops
.to_load
= generic_load
;
4946 remote_ops
.to_mourn_inferior
= remote_mourn
;
4947 remote_ops
.to_thread_alive
= remote_thread_alive
;
4948 remote_ops
.to_find_new_threads
= remote_threads_info
;
4949 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
4950 remote_ops
.to_stop
= remote_stop
;
4951 remote_ops
.to_query
= remote_query
;
4952 remote_ops
.to_rcmd
= remote_rcmd
;
4953 remote_ops
.to_stratum
= process_stratum
;
4954 remote_ops
.to_has_all_memory
= 1;
4955 remote_ops
.to_has_memory
= 1;
4956 remote_ops
.to_has_stack
= 1;
4957 remote_ops
.to_has_registers
= 1;
4958 remote_ops
.to_has_execution
= 1;
4959 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
4960 remote_ops
.to_magic
= OPS_MAGIC
;
4963 /* Set up the extended remote vector by making a copy of the standard
4964 remote vector and adding to it. */
4967 init_extended_remote_ops (void)
4969 extended_remote_ops
= remote_ops
;
4971 extended_remote_ops
.to_shortname
= "extended-remote";
4972 extended_remote_ops
.to_longname
=
4973 "Extended remote serial target in gdb-specific protocol";
4974 extended_remote_ops
.to_doc
=
4975 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4976 Specify the serial device it is connected to (e.g. /dev/ttya).",
4977 extended_remote_ops
.to_open
= extended_remote_open
;
4978 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
4979 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
4983 * Command: info remote-process
4985 * This implements Cisco's version of the "info proc" command.
4987 * This query allows the target stub to return an arbitrary string
4988 * (or strings) giving arbitrary information about the target process.
4989 * This is optional; the target stub isn't required to implement it.
4991 * Syntax: qfProcessInfo request first string
4992 * qsProcessInfo request subsequent string
4993 * reply: 'O'<hex-encoded-string>
4994 * 'l' last reply (empty)
4998 remote_info_process (char *args
, int from_tty
)
5000 char *buf
= alloca (PBUFSIZ
);
5002 if (remote_desc
== 0)
5003 error ("Command can only be used when connected to the remote target.");
5005 putpkt ("qfProcessInfo");
5006 getpkt (buf
, PBUFSIZ
, 0);
5008 return; /* Silently: target does not support this feature. */
5011 error ("info proc: target error.");
5013 while (buf
[0] == 'O') /* Capitol-O packet */
5015 remote_console_output (&buf
[1]);
5016 putpkt ("qsProcessInfo");
5017 getpkt (buf
, PBUFSIZ
, 0);
5026 remote_cisco_open (char *name
, int from_tty
)
5030 "To open a remote debug connection, you need to specify what \n\
5031 device is attached to the remote system (e.g. host:port).");
5033 /* See FIXME above */
5034 wait_forever_enabled_p
= 1;
5036 target_preopen (from_tty
);
5038 unpush_target (&remote_cisco_ops
);
5041 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
5043 dcache_invd (remote_dcache
);
5045 remote_desc
= SERIAL_OPEN (name
);
5047 perror_with_name (name
);
5050 * If a baud rate was specified on the gdb command line it will
5051 * be greater than the initial value of -1. If it is, use it otherwise
5055 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5056 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
5058 SERIAL_CLOSE (remote_desc
);
5059 perror_with_name (name
);
5062 SERIAL_RAW (remote_desc
);
5064 /* If there is something sitting in the buffer we might take it as a
5065 response to a command, which would be bad. */
5066 SERIAL_FLUSH_INPUT (remote_desc
);
5070 puts_filtered ("Remote debugging using ");
5071 puts_filtered (name
);
5072 puts_filtered ("\n");
5075 remote_cisco_mode
= 1;
5077 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5079 init_all_packet_configs ();
5081 general_thread
= -2;
5082 continue_thread
= -2;
5084 /* Probe for ability to use "ThreadInfo" query, as required. */
5085 use_threadinfo_query
= 1;
5086 use_threadextra_query
= 1;
5088 /* Without this, some commands which require an active target (such
5089 as kill) won't work. This variable serves (at least) double duty
5090 as both the pid of the target process (if it has such), and as a
5091 flag indicating that a target is active. These functions should
5092 be split out into seperate variables, especially since GDB will
5093 someday have a notion of debugging several processes. */
5094 inferior_pid
= MAGIC_NULL_PID
;
5096 /* Start the remote connection; if error (0), discard this target. */
5098 if (!catch_errors (remote_start_remote_dummy
, (char *) 0,
5099 "Couldn't establish connection to remote target\n",
5108 remote_cisco_close (int quitting
)
5110 remote_cisco_mode
= 0;
5111 remote_close (quitting
);
5115 remote_cisco_mourn (void)
5117 remote_mourn_1 (&remote_cisco_ops
);
5129 /* shared between readsocket() and readtty() */
5130 static char *tty_input
;
5132 static int escape_count
;
5133 static int echo_check
;
5134 extern int quit_flag
;
5141 /* Loop until the socket doesn't have any more data */
5143 while ((data
= readchar (0)) >= 0)
5145 /* Check for the escape sequence */
5148 /* If this is the fourth escape, get out */
5149 if (++escape_count
== 4)
5154 { /* This is a '|', but not the fourth in a row.
5155 Continue without echoing it. If it isn't actually
5156 one of four in a row, it'll be echoed later. */
5163 /* Ensure any pending '|'s are flushed. */
5165 for (; escape_count
> 0; escape_count
--)
5169 if (data
== '\r') /* If this is a return character, */
5170 continue; /* - just supress it. */
5172 if (echo_check
!= -1) /* Check for echo of user input. */
5174 if (tty_input
[echo_check
] == data
)
5176 echo_check
++; /* Character matched user input: */
5177 continue; /* Continue without echoing it. */
5179 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5180 { /* End of the line (and of echo checking). */
5181 echo_check
= -1; /* No more echo supression */
5182 continue; /* Continue without echoing. */
5185 { /* Failed check for echo of user input.
5186 We now have some suppressed output to flush! */
5189 for (j
= 0; j
< echo_check
; j
++)
5190 putchar (tty_input
[j
]);
5194 putchar (data
); /* Default case: output the char. */
5197 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5198 return READ_MORE
; /* Try to read some more */
5200 return FATAL_ERROR
; /* Trouble, bail out */
5208 /* First, read a buffer full from the terminal */
5209 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5210 if (tty_bytecount
== -1)
5212 perror ("readtty: read failed");
5216 /* Remove a quoted newline. */
5217 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5218 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5220 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5221 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5224 /* Turn trailing newlines into returns */
5225 if (tty_input
[tty_bytecount
- 1] == '\n')
5226 tty_input
[tty_bytecount
- 1] = '\r';
5228 /* If the line consists of a ~, enter debugging mode. */
5229 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5232 /* Make this a zero terminated string and write it out */
5233 tty_input
[tty_bytecount
] = 0;
5234 if (SERIAL_WRITE (remote_desc
, tty_input
, tty_bytecount
))
5236 perror_with_name ("readtty: write failed");
5246 fd_set input
; /* file descriptors for select */
5247 int tablesize
; /* max number of FDs for select */
5251 extern int escape_count
; /* global shared by readsocket */
5252 extern int echo_check
; /* ditto */
5257 tablesize
= 8 * sizeof (input
);
5261 /* Check for anything from our socket - doesn't block. Note that
5262 this must be done *before* the select as there may be
5263 buffered I/O waiting to be processed. */
5265 if ((status
= readsocket ()) == FATAL_ERROR
)
5267 error ("Debugging terminated by communications error");
5269 else if (status
!= READ_MORE
)
5274 fflush (stdout
); /* Flush output before blocking */
5276 /* Now block on more socket input or TTY input */
5279 FD_SET (fileno (stdin
), &input
);
5280 FD_SET (DEPRECATED_SERIAL_FD (remote_desc
), &input
);
5282 status
= select (tablesize
, &input
, 0, 0, 0);
5283 if ((status
== -1) && (errno
!= EINTR
))
5285 error ("Communications error on select %d", errno
);
5288 /* Handle Control-C typed */
5292 if ((++quit_count
) == 2)
5294 if (query ("Interrupt GDB? "))
5296 printf_filtered ("Interrupted by user.\n");
5297 return_to_top_level (RETURN_QUIT
);
5304 SERIAL_SEND_BREAK (remote_desc
);
5306 SERIAL_WRITE (remote_desc
, "\003", 1);
5311 /* Handle console input */
5313 if (FD_ISSET (fileno (stdin
), &input
))
5317 status
= readtty ();
5318 if (status
== READ_MORE
)
5321 return status
; /* telnet session ended */
5327 remote_cisco_wait (int pid
, struct target_waitstatus
*status
)
5329 if (minitelnet () != ENTER_DEBUG
)
5331 error ("Debugging session terminated by protocol error");
5334 return remote_wait (pid
, status
);
5338 init_remote_cisco_ops (void)
5340 remote_cisco_ops
.to_shortname
= "cisco";
5341 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5342 remote_cisco_ops
.to_doc
=
5343 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5344 Specify the serial device it is connected to (e.g. host:2020).";
5345 remote_cisco_ops
.to_open
= remote_cisco_open
;
5346 remote_cisco_ops
.to_close
= remote_cisco_close
;
5347 remote_cisco_ops
.to_detach
= remote_detach
;
5348 remote_cisco_ops
.to_resume
= remote_resume
;
5349 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5350 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5351 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5352 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5353 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5354 remote_cisco_ops
.to_files_info
= remote_files_info
;
5355 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5356 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5357 remote_cisco_ops
.to_kill
= remote_kill
;
5358 remote_cisco_ops
.to_load
= generic_load
;
5359 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5360 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5361 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5362 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5363 remote_cisco_ops
.to_stratum
= process_stratum
;
5364 remote_cisco_ops
.to_has_all_memory
= 1;
5365 remote_cisco_ops
.to_has_memory
= 1;
5366 remote_cisco_ops
.to_has_stack
= 1;
5367 remote_cisco_ops
.to_has_registers
= 1;
5368 remote_cisco_ops
.to_has_execution
= 1;
5369 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5373 remote_can_async_p (void)
5375 /* We're async whenever the serial device is. */
5376 return (current_target
.to_async_mask_value
) && SERIAL_CAN_ASYNC_P (remote_desc
);
5380 remote_is_async_p (void)
5382 /* We're async whenever the serial device is. */
5383 return (current_target
.to_async_mask_value
) && SERIAL_IS_ASYNC_P (remote_desc
);
5386 /* Pass the SERIAL event on and up to the client. One day this code
5387 will be able to delay notifying the client of an event until the
5388 point where an entire packet has been received. */
5390 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5391 static void *async_client_context
;
5392 static serial_event_ftype remote_async_serial_handler
;
5395 remote_async_serial_handler (serial_t scb
, void *context
)
5397 /* Don't propogate error information up to the client. Instead let
5398 the client find out about the error by querying the target. */
5399 async_client_callback (INF_REG_EVENT
, async_client_context
);
5403 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5405 if (current_target
.to_async_mask_value
== 0)
5406 internal_error ("Calling remote_async when async is masked");
5408 if (callback
!= NULL
)
5410 SERIAL_ASYNC (remote_desc
, remote_async_serial_handler
, NULL
);
5411 async_client_callback
= callback
;
5412 async_client_context
= context
;
5415 SERIAL_ASYNC (remote_desc
, NULL
, NULL
);
5418 /* Target async and target extended-async.
5420 This are temporary targets, until it is all tested. Eventually
5421 async support will be incorporated int the usual 'remote'
5425 init_remote_async_ops (void)
5427 remote_async_ops
.to_shortname
= "async";
5428 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5429 remote_async_ops
.to_doc
=
5430 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5431 Specify the serial device it is connected to (e.g. /dev/ttya).";
5432 remote_async_ops
.to_open
= remote_async_open
;
5433 remote_async_ops
.to_close
= remote_close
;
5434 remote_async_ops
.to_detach
= remote_async_detach
;
5435 remote_async_ops
.to_resume
= remote_async_resume
;
5436 remote_async_ops
.to_wait
= remote_async_wait
;
5437 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5438 remote_async_ops
.to_store_registers
= remote_store_registers
;
5439 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5440 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5441 remote_async_ops
.to_files_info
= remote_files_info
;
5442 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5443 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5444 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5445 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5446 remote_async_ops
.to_kill
= remote_async_kill
;
5447 remote_async_ops
.to_load
= generic_load
;
5448 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5449 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5450 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5451 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5452 remote_async_ops
.to_stop
= remote_stop
;
5453 remote_async_ops
.to_query
= remote_query
;
5454 remote_async_ops
.to_rcmd
= remote_rcmd
;
5455 remote_async_ops
.to_stratum
= process_stratum
;
5456 remote_async_ops
.to_has_all_memory
= 1;
5457 remote_async_ops
.to_has_memory
= 1;
5458 remote_async_ops
.to_has_stack
= 1;
5459 remote_async_ops
.to_has_registers
= 1;
5460 remote_async_ops
.to_has_execution
= 1;
5461 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5462 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5463 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5464 remote_async_ops
.to_async
= remote_async
;
5465 remote_async_ops
.to_async_mask_value
= 1;
5466 remote_async_ops
.to_magic
= OPS_MAGIC
;
5469 /* Set up the async extended remote vector by making a copy of the standard
5470 remote vector and adding to it. */
5473 init_extended_async_remote_ops (void)
5475 extended_async_remote_ops
= remote_async_ops
;
5477 extended_async_remote_ops
.to_shortname
= "extended-async";
5478 extended_async_remote_ops
.to_longname
=
5479 "Extended remote serial target in async gdb-specific protocol";
5480 extended_async_remote_ops
.to_doc
=
5481 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5482 Specify the serial device it is connected to (e.g. /dev/ttya).",
5483 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5484 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5485 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5489 set_remote_cmd (char *args
, int from_tty
)
5495 show_remote_cmd (char *args
, int from_tty
)
5497 show_remote_protocol_Z_packet_cmd (args
, from_tty
);
5498 show_remote_protocol_P_packet_cmd (args
, from_tty
);
5499 show_remote_protocol_binary_download_cmd (args
, from_tty
);
5503 build_remote_gdbarch_data (void)
5505 build_remote_packet_sizes ();
5508 tty_input
= xmalloc (PBUFSIZ
);
5509 remote_address_size
= TARGET_PTR_BIT
;
5513 _initialize_remote (void)
5515 static struct cmd_list_element
*remote_set_cmdlist
;
5516 static struct cmd_list_element
*remote_show_cmdlist
;
5517 struct cmd_list_element
*tmpcmd
;
5519 /* architecture specific data */
5520 build_remote_gdbarch_data ();
5521 register_gdbarch_swap (&tty_input
, sizeof (&tty_input
), NULL
);
5522 register_remote_packet_sizes ();
5523 register_gdbarch_swap (&remote_address_size
,
5524 sizeof (&remote_address_size
), NULL
);
5525 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5528 add_target (&remote_ops
);
5530 init_extended_remote_ops ();
5531 add_target (&extended_remote_ops
);
5533 init_remote_async_ops ();
5534 add_target (&remote_async_ops
);
5536 init_extended_async_remote_ops ();
5537 add_target (&extended_async_remote_ops
);
5539 init_remote_cisco_ops ();
5540 add_target (&remote_cisco_ops
);
5543 init_remote_threadtests ();
5546 /* set/show remote ... */
5548 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5549 Remote protocol specific variables\n\
5550 Configure various remote-protocol specific variables such as\n\
5551 the packets being used",
5552 &remote_set_cmdlist
, "set remote ",
5553 0/*allow-unknown*/, &setlist
);
5554 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
5555 Remote protocol specific variables\n\
5556 Configure various remote-protocol specific variables such as\n\
5557 the packets being used",
5558 &remote_show_cmdlist
, "show remote ",
5559 0/*allow-unknown*/, &showlist
);
5561 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
5562 "Compare section data on target to the exec file.\n\
5563 Argument is a single section name (default: all loaded sections).",
5566 add_cmd ("packet", class_maintenance
, packet_command
,
5567 "Send an arbitrary packet to a remote target.\n\
5568 maintenance packet TEXT\n\
5569 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5570 this command sends the string TEXT to the inferior, and displays the\n\
5571 response packet. GDB supplies the initial `$' character, and the\n\
5572 terminating `#' character and checksum.",
5576 (add_set_cmd ("remotebreak", no_class
,
5577 var_boolean
, (char *) &remote_break
,
5578 "Set whether to send break if interrupted.\n",
5582 /* Install commands for configuring memory read/write packets. */
5584 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
5585 "Set the maximum number of bytes per memory write packet (deprecated).\n",
5587 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
5588 "Show the maximum number of bytes per memory write packet (deprecated).\n",
5590 add_cmd ("memory-write-packet-size", no_class
,
5591 set_memory_write_packet_size
,
5592 "Set the maximum number of bytes per memory-write packet.\n"
5593 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5594 "default packet size. The actual limit is further reduced\n"
5595 "dependent on the target. Specify ``fixed'' to disable the\n"
5596 "further restriction and ``limit'' to enable that restriction\n",
5597 &remote_set_cmdlist
);
5598 add_cmd ("memory-read-packet-size", no_class
,
5599 set_memory_read_packet_size
,
5600 "Set the maximum number of bytes per memory-read packet.\n"
5601 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5602 "default packet size. The actual limit is further reduced\n"
5603 "dependent on the target. Specify ``fixed'' to disable the\n"
5604 "further restriction and ``limit'' to enable that restriction\n",
5605 &remote_set_cmdlist
);
5606 add_cmd ("memory-write-packet-size", no_class
,
5607 show_memory_write_packet_size
,
5608 "Show the maximum number of bytes per memory-write packet.\n",
5609 &remote_show_cmdlist
);
5610 add_cmd ("memory-read-packet-size", no_class
,
5611 show_memory_read_packet_size
,
5612 "Show the maximum number of bytes per memory-read packet.\n",
5613 &remote_show_cmdlist
);
5616 (add_set_cmd ("remoteaddresssize", class_obscure
,
5617 var_integer
, (char *) &remote_address_size
,
5618 "Set the maximum size of the address (in bits) \
5619 in a memory packet.\n",
5623 add_packet_config_cmd (&remote_protocol_binary_download
,
5624 "X", "binary-download",
5625 set_remote_protocol_binary_download_cmd
,
5626 show_remote_protocol_binary_download_cmd
,
5627 &remote_set_cmdlist
, &remote_show_cmdlist
,
5630 /* XXXX - should ``set remotebinarydownload'' be retained for
5633 (add_set_cmd ("remotebinarydownload", no_class
,
5634 var_boolean
, (char *) &remote_binary_download
,
5635 "Set binary downloads.\n", &setlist
),
5639 add_info ("remote-process", remote_info_process
,
5640 "Query the remote system for process info.");
5642 add_packet_config_cmd (&remote_protocol_P
,
5643 "P", "set-register",
5644 set_remote_protocol_P_packet_cmd
,
5645 show_remote_protocol_P_packet_cmd
,
5646 &remote_set_cmdlist
, &remote_show_cmdlist
,
5649 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
5650 "Z0", "software-breakpoint",
5651 set_remote_protocol_Z_software_bp_packet_cmd
,
5652 show_remote_protocol_Z_software_bp_packet_cmd
,
5653 &remote_set_cmdlist
, &remote_show_cmdlist
,
5656 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
5657 "Z1", "hardware-breakpoint",
5658 set_remote_protocol_Z_hardware_bp_packet_cmd
,
5659 show_remote_protocol_Z_hardware_bp_packet_cmd
,
5660 &remote_set_cmdlist
, &remote_show_cmdlist
,
5663 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
5664 "Z2", "write-watchpoint",
5665 set_remote_protocol_Z_write_wp_packet_cmd
,
5666 show_remote_protocol_Z_write_wp_packet_cmd
,
5667 &remote_set_cmdlist
, &remote_show_cmdlist
,
5670 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
5671 "Z3", "read-watchpoint",
5672 set_remote_protocol_Z_read_wp_packet_cmd
,
5673 show_remote_protocol_Z_read_wp_packet_cmd
,
5674 &remote_set_cmdlist
, &remote_show_cmdlist
,
5677 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
5678 "Z4", "access-watchpoint",
5679 set_remote_protocol_Z_access_wp_packet_cmd
,
5680 show_remote_protocol_Z_access_wp_packet_cmd
,
5681 &remote_set_cmdlist
, &remote_show_cmdlist
,
5684 /* Keep the old ``set remote Z-packet ...'' working. */
5685 tmpcmd
= add_set_auto_boolean_cmd ("Z-packet", class_obscure
,
5686 &remote_Z_packet_detect
,
5688 Set use of remote protocol `Z' packets", &remote_set_cmdlist
);
5689 tmpcmd
->function
.sfunc
= set_remote_protocol_Z_packet_cmd
;
5690 add_cmd ("Z-packet", class_obscure
, show_remote_protocol_Z_packet_cmd
,
5691 "Show use of remote protocol `Z' packets ",
5692 &remote_show_cmdlist
);