1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* See the GDB User Guide for details of the GDB remote protocol. */
25 #include "gdb_string.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
44 #include <sys/types.h>
47 #include "event-loop.h"
48 #include "event-top.h"
54 /* Prototypes for local functions */
55 static void cleanup_sigint_signal_handler (void *dummy
);
56 static void initialize_sigint_signal_handler (void);
57 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
59 static void handle_remote_sigint (int);
60 static void handle_remote_sigint_twice (int);
61 static void async_remote_interrupt (gdb_client_data
);
62 void async_remote_interrupt_twice (gdb_client_data
);
64 static void build_remote_gdbarch_data (void);
66 static int remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
68 static int remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
70 static void remote_files_info (struct target_ops
*ignore
);
72 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
73 int len
, int should_write
,
74 struct mem_attrib
*attrib
,
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 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
581 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
583 /* set/show TITLE-packet {auto,on,off} */
584 xasprintf (&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 xasprintf (&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 (__FILE__
, __LINE__
,
621 "packet_ok: attempt to use a disabled packet");
626 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
627 /* "OK" - definitly OK. */
630 && isxdigit (buf
[1]) && isxdigit (buf
[2])
632 /* "Enn" - definitly an error. */
634 /* The packet may or may not be OK. Just assume it is */
639 /* The stub does not support the packet. */
640 switch (config
->support
)
643 if (config
->detect
== CMD_AUTO_BOOLEAN_AUTO
)
644 /* If the stub previously indicated that the packet was
645 supported then there is a protocol error.. */
646 error ("Protocol error: %s (%s) conflicting enabled responses.",
647 config
->name
, config
->title
);
649 /* The user set it wrong. */
650 error ("Enabled packet %s (%s) not recognized by stub",
651 config
->name
, config
->title
);
653 case PACKET_SUPPORT_UNKNOWN
:
655 fprintf_unfiltered (gdb_stdlog
,
656 "Packet %s (%s) is NOT supported\n",
657 config
->name
, config
->title
);
658 config
->support
= PACKET_DISABLE
;
663 return PACKET_UNKNOWN
;
667 /* Should we try the 'P' (set register) request? */
669 static struct packet_config remote_protocol_P
;
672 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
673 struct cmd_list_element
*c
)
675 update_packet_config (&remote_protocol_P
);
679 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
)
681 show_packet_config_cmd (&remote_protocol_P
);
684 /* Should we try one of the 'Z' requests? */
688 Z_PACKET_SOFTWARE_BP
,
689 Z_PACKET_HARDWARE_BP
,
696 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
698 /* FIXME: Instead of having all these boiler plate functions, the
699 command callback should include a context argument. */
702 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
703 struct cmd_list_element
*c
)
705 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
709 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
)
711 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
715 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
716 struct cmd_list_element
*c
)
718 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
722 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
)
724 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
728 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
729 struct cmd_list_element
*c
)
731 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
735 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
)
737 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
741 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
742 struct cmd_list_element
*c
)
744 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
748 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
)
750 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
754 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
755 struct cmd_list_element
*c
)
757 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
761 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
)
763 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
766 /* For compatibility with older distributions. Provide a ``set remote
767 Z-packet ...'' command that updates all the Z packet types. */
769 static enum cmd_auto_boolean remote_Z_packet_detect
;
772 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
773 struct cmd_list_element
*c
)
776 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
778 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
779 update_packet_config (&remote_protocol_Z
[i
]);
784 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
)
787 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
789 show_packet_config_cmd (&remote_protocol_Z
[i
]);
793 /* Should we try the 'X' (remote binary download) packet?
795 This variable (available to the user via "set remote X-packet")
796 dictates whether downloads are sent in binary (via the 'X' packet).
797 We assume that the stub can, and attempt to do it. This will be
798 cleared if the stub does not understand it. This switch is still
799 needed, though in cases when the packet is supported in the stub,
800 but the connection does not allow it (i.e., 7-bit serial connection
803 static struct packet_config remote_protocol_binary_download
;
805 /* Should we try the 'ThreadInfo' query packet?
807 This variable (NOT available to the user: auto-detect only!)
808 determines whether GDB will use the new, simpler "ThreadInfo"
809 query or the older, more complex syntax for thread queries.
810 This is an auto-detect variable (set to true at each connect,
811 and set to false when the target fails to recognize it). */
813 static int use_threadinfo_query
;
814 static int use_threadextra_query
;
817 set_remote_protocol_binary_download_cmd (char *args
,
819 struct cmd_list_element
*c
)
821 update_packet_config (&remote_protocol_binary_download
);
825 show_remote_protocol_binary_download_cmd (char *args
,
828 show_packet_config_cmd (&remote_protocol_binary_download
);
832 /* Tokens for use by the asynchronous signal handlers for SIGINT */
833 PTR sigint_remote_twice_token
;
834 PTR sigint_remote_token
;
836 /* These are pointers to hook functions that may be set in order to
837 modify resume/wait behavior for a particular architecture. */
839 void (*target_resume_hook
) (void);
840 void (*target_wait_loop_hook
) (void);
844 /* These are the threads which we last sent to the remote system.
845 -1 for all or -2 for not sent yet. */
846 static int general_thread
;
847 static int continue_thread
;
849 /* Call this function as a result of
850 1) A halt indication (T packet) containing a thread id
851 2) A direct query of currthread
852 3) Successful execution of set thread
856 record_currthread (int currthread
)
858 general_thread
= currthread
;
860 /* If this is a new thread, add it to GDB's thread list.
861 If we leave it up to WFI to do this, bad things will happen. */
862 if (!in_thread_list (currthread
))
864 add_thread (currthread
);
866 ui_out_text (uiout
, "[New ");
867 ui_out_text (uiout
, target_pid_to_str (currthread
));
868 ui_out_text (uiout
, "]\n");
870 printf_filtered ("[New %s]\n", target_pid_to_str (currthread
));
875 #define MAGIC_NULL_PID 42000
878 set_thread (int th
, int gen
)
880 char *buf
= alloca (PBUFSIZ
);
881 int state
= gen
? general_thread
: continue_thread
;
887 buf
[1] = gen
? 'g' : 'c';
888 if (th
== MAGIC_NULL_PID
)
894 sprintf (&buf
[2], "-%x", -th
);
896 sprintf (&buf
[2], "%x", th
);
898 getpkt (buf
, PBUFSIZ
, 0);
902 continue_thread
= th
;
905 /* Return nonzero if the thread TH is still alive on the remote system. */
908 remote_thread_alive (int tid
)
913 sprintf (buf
, "T-%08x", -tid
);
915 sprintf (buf
, "T%08x", tid
);
917 getpkt (buf
, sizeof (buf
), 0);
918 return (buf
[0] == 'O' && buf
[1] == 'K');
921 /* About these extended threadlist and threadinfo packets. They are
922 variable length packets but, the fields within them are often fixed
923 length. They are redundent enough to send over UDP as is the
924 remote protocol in general. There is a matching unit test module
927 #define OPAQUETHREADBYTES 8
929 /* a 64 bit opaque identifier */
930 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
932 /* WARNING: This threadref data structure comes from the remote O.S., libstub
933 protocol encoding, and remote.c. it is not particularly changable */
935 /* Right now, the internal structure is int. We want it to be bigger.
939 typedef int gdb_threadref
; /* internal GDB thread reference */
941 /* gdb_ext_thread_info is an internal GDB data structure which is
942 equivalint to the reply of the remote threadinfo packet */
944 struct gdb_ext_thread_info
946 threadref threadid
; /* External form of thread reference */
947 int active
; /* Has state interesting to GDB? , regs, stack */
948 char display
[256]; /* Brief state display, name, blocked/syspended */
949 char shortname
[32]; /* To be used to name threads */
950 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
953 /* The volume of remote transfers can be limited by submitting
954 a mask containing bits specifying the desired information.
955 Use a union of these values as the 'selection' parameter to
956 get_thread_info. FIXME: Make these TAG names more thread specific.
959 #define TAG_THREADID 1
961 #define TAG_DISPLAY 4
962 #define TAG_THREADNAME 8
963 #define TAG_MOREDISPLAY 16
965 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
967 char *unpack_varlen_hex (char *buff
, int *result
);
969 static char *unpack_nibble (char *buf
, int *val
);
971 static char *pack_nibble (char *buf
, int nibble
);
973 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
975 static char *unpack_byte (char *buf
, int *value
);
977 static char *pack_int (char *buf
, int value
);
979 static char *unpack_int (char *buf
, int *value
);
981 static char *unpack_string (char *src
, char *dest
, int length
);
983 static char *pack_threadid (char *pkt
, threadref
* id
);
985 static char *unpack_threadid (char *inbuf
, threadref
* id
);
987 void int_to_threadref (threadref
* id
, int value
);
989 static int threadref_to_int (threadref
* ref
);
991 static void copy_threadref (threadref
* dest
, threadref
* src
);
993 static int threadmatch (threadref
* dest
, threadref
* src
);
995 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
997 static int remote_unpack_thread_info_response (char *pkt
,
998 threadref
* expectedref
,
999 struct gdb_ext_thread_info
1003 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1004 struct gdb_ext_thread_info
*info
);
1006 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1008 struct gdb_ext_thread_info
*info
);
1010 static char *pack_threadlist_request (char *pkt
, int startflag
,
1012 threadref
* nextthread
);
1014 static int parse_threadlist_response (char *pkt
,
1016 threadref
* original_echo
,
1017 threadref
* resultlist
, int *doneflag
);
1019 static int remote_get_threadlist (int startflag
,
1020 threadref
* nextthread
,
1023 int *result_count
, threadref
* threadlist
);
1025 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1027 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1028 void *context
, int looplimit
);
1030 static int remote_newthread_step (threadref
* ref
, void *context
);
1032 /* encode 64 bits in 16 chars of hex */
1034 static const char hexchars
[] = "0123456789abcdef";
1037 ishex (int ch
, int *val
)
1039 if ((ch
>= 'a') && (ch
<= 'f'))
1041 *val
= ch
- 'a' + 10;
1044 if ((ch
>= 'A') && (ch
<= 'F'))
1046 *val
= ch
- 'A' + 10;
1049 if ((ch
>= '0') && (ch
<= '9'))
1060 if (ch
>= 'a' && ch
<= 'f')
1061 return ch
- 'a' + 10;
1062 if (ch
>= '0' && ch
<= '9')
1064 if (ch
>= 'A' && ch
<= 'F')
1065 return ch
- 'A' + 10;
1070 stub_unpack_int (char *buff
, int fieldlength
)
1077 nibble
= stubhex (*buff
++);
1081 retval
= retval
<< 4;
1087 unpack_varlen_hex (char *buff
, /* packet to parse */
1093 while (ishex (*buff
, &nibble
))
1096 retval
= retval
<< 4;
1097 retval
|= nibble
& 0x0f;
1104 unpack_nibble (char *buf
, int *val
)
1106 ishex (*buf
++, val
);
1111 pack_nibble (char *buf
, int nibble
)
1113 *buf
++ = hexchars
[(nibble
& 0x0f)];
1118 pack_hex_byte (char *pkt
, int byte
)
1120 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1121 *pkt
++ = hexchars
[(byte
& 0xf)];
1126 unpack_byte (char *buf
, int *value
)
1128 *value
= stub_unpack_int (buf
, 2);
1133 pack_int (char *buf
, int value
)
1135 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1136 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1137 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1138 buf
= pack_hex_byte (buf
, (value
& 0xff));
1143 unpack_int (char *buf
, int *value
)
1145 *value
= stub_unpack_int (buf
, 8);
1149 #if 0 /* currently unused, uncomment when needed */
1150 static char *pack_string (char *pkt
, char *string
);
1153 pack_string (char *pkt
, char *string
)
1158 len
= strlen (string
);
1160 len
= 200; /* Bigger than most GDB packets, junk??? */
1161 pkt
= pack_hex_byte (pkt
, len
);
1165 if ((ch
== '\0') || (ch
== '#'))
1166 ch
= '*'; /* Protect encapsulation */
1171 #endif /* 0 (unused) */
1174 unpack_string (char *src
, char *dest
, int length
)
1183 pack_threadid (char *pkt
, threadref
*id
)
1186 unsigned char *altid
;
1188 altid
= (unsigned char *) id
;
1189 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1191 pkt
= pack_hex_byte (pkt
, *altid
++);
1197 unpack_threadid (char *inbuf
, threadref
*id
)
1200 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1203 altref
= (char *) id
;
1205 while (inbuf
< limit
)
1207 x
= stubhex (*inbuf
++);
1208 y
= stubhex (*inbuf
++);
1209 *altref
++ = (x
<< 4) | y
;
1214 /* Externally, threadrefs are 64 bits but internally, they are still
1215 ints. This is due to a mismatch of specifications. We would like
1216 to use 64bit thread references internally. This is an adapter
1220 int_to_threadref (threadref
*id
, int value
)
1222 unsigned char *scan
;
1224 scan
= (unsigned char *) id
;
1230 *scan
++ = (value
>> 24) & 0xff;
1231 *scan
++ = (value
>> 16) & 0xff;
1232 *scan
++ = (value
>> 8) & 0xff;
1233 *scan
++ = (value
& 0xff);
1237 threadref_to_int (threadref
*ref
)
1240 unsigned char *scan
;
1242 scan
= (char *) ref
;
1246 value
= (value
<< 8) | ((*scan
++) & 0xff);
1251 copy_threadref (threadref
*dest
, threadref
*src
)
1254 unsigned char *csrc
, *cdest
;
1256 csrc
= (unsigned char *) src
;
1257 cdest
= (unsigned char *) dest
;
1264 threadmatch (threadref
*dest
, threadref
*src
)
1266 /* things are broken right now, so just assume we got a match */
1268 unsigned char *srcp
, *destp
;
1270 srcp
= (char *) src
;
1271 destp
= (char *) dest
;
1275 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1282 threadid:1, # always request threadid
1289 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1292 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1294 *pkt
++ = 'q'; /* Info Query */
1295 *pkt
++ = 'P'; /* process or thread info */
1296 pkt
= pack_int (pkt
, mode
); /* mode */
1297 pkt
= pack_threadid (pkt
, id
); /* threadid */
1298 *pkt
= '\0'; /* terminate */
1302 /* These values tag the fields in a thread info response packet */
1303 /* Tagging the fields allows us to request specific fields and to
1304 add more fields as time goes by */
1306 #define TAG_THREADID 1 /* Echo the thread identifier */
1307 #define TAG_EXISTS 2 /* Is this process defined enough to
1308 fetch registers and its stack */
1309 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1310 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1311 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1315 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1316 struct gdb_ext_thread_info
*info
)
1321 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
1324 /* info->threadid = 0; FIXME: implement zero_threadref */
1326 info
->display
[0] = '\0';
1327 info
->shortname
[0] = '\0';
1328 info
->more_display
[0] = '\0';
1330 /* Assume the characters indicating the packet type have been stripped */
1331 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1332 pkt
= unpack_threadid (pkt
, &ref
);
1335 warning ("Incomplete response to threadinfo request\n");
1336 if (!threadmatch (&ref
, expectedref
))
1337 { /* This is an answer to a different request */
1338 warning ("ERROR RMT Thread info mismatch\n");
1341 copy_threadref (&info
->threadid
, &ref
);
1343 /* Loop on tagged fields , try to bail if somthing goes wrong */
1345 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1347 pkt
= unpack_int (pkt
, &tag
); /* tag */
1348 pkt
= unpack_byte (pkt
, &length
); /* length */
1349 if (!(tag
& mask
)) /* tags out of synch with mask */
1351 warning ("ERROR RMT: threadinfo tag mismatch\n");
1355 if (tag
== TAG_THREADID
)
1359 warning ("ERROR RMT: length of threadid is not 16\n");
1363 pkt
= unpack_threadid (pkt
, &ref
);
1364 mask
= mask
& ~TAG_THREADID
;
1367 if (tag
== TAG_EXISTS
)
1369 info
->active
= stub_unpack_int (pkt
, length
);
1371 mask
= mask
& ~(TAG_EXISTS
);
1374 warning ("ERROR RMT: 'exists' length too long\n");
1380 if (tag
== TAG_THREADNAME
)
1382 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1383 mask
= mask
& ~TAG_THREADNAME
;
1386 if (tag
== TAG_DISPLAY
)
1388 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1389 mask
= mask
& ~TAG_DISPLAY
;
1392 if (tag
== TAG_MOREDISPLAY
)
1394 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1395 mask
= mask
& ~TAG_MOREDISPLAY
;
1398 warning ("ERROR RMT: unknown thread info tag\n");
1399 break; /* Not a tag we know about */
1405 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1406 struct gdb_ext_thread_info
*info
)
1409 char *threadinfo_pkt
= alloca (PBUFSIZ
);
1411 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1412 putpkt (threadinfo_pkt
);
1413 getpkt (threadinfo_pkt
, PBUFSIZ
, 0);
1414 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1419 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1420 representation of a threadid. */
1423 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1424 struct gdb_ext_thread_info
*info
)
1428 int_to_threadref (&lclref
, *ref
);
1429 return remote_get_threadinfo (&lclref
, selection
, info
);
1432 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1435 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1436 threadref
*nextthread
)
1438 *pkt
++ = 'q'; /* info query packet */
1439 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1440 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1441 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1442 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1447 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1450 parse_threadlist_response (char *pkt
, int result_limit
,
1451 threadref
*original_echo
, threadref
*resultlist
,
1455 int count
, resultcount
, done
;
1458 /* Assume the 'q' and 'M chars have been stripped. */
1459 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1460 pkt
= unpack_byte (pkt
, &count
); /* count field */
1461 pkt
= unpack_nibble (pkt
, &done
);
1462 /* The first threadid is the argument threadid. */
1463 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1464 while ((count
-- > 0) && (pkt
< limit
))
1466 pkt
= unpack_threadid (pkt
, resultlist
++);
1467 if (resultcount
++ >= result_limit
)
1476 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1477 int *done
, int *result_count
, threadref
*threadlist
)
1479 static threadref echo_nextthread
;
1480 char *threadlist_packet
= alloca (PBUFSIZ
);
1481 char *t_response
= alloca (PBUFSIZ
);
1484 /* Trancate result limit to be smaller than the packet size */
1485 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1486 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1488 pack_threadlist_request (threadlist_packet
,
1489 startflag
, result_limit
, nextthread
);
1490 putpkt (threadlist_packet
);
1491 getpkt (t_response
, PBUFSIZ
, 0);
1494 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1497 if (!threadmatch (&echo_nextthread
, nextthread
))
1499 /* FIXME: This is a good reason to drop the packet */
1500 /* Possably, there is a duplicate response */
1502 retransmit immediatly - race conditions
1503 retransmit after timeout - yes
1505 wait for packet, then exit
1507 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1508 return 0; /* I choose simply exiting */
1510 if (*result_count
<= 0)
1514 warning ("RMT ERROR : failed to get remote thread list\n");
1517 return result
; /* break; */
1519 if (*result_count
> result_limit
)
1522 warning ("RMT ERROR: threadlist response longer than requested\n");
1528 /* This is the interface between remote and threads, remotes upper interface */
1530 /* remote_find_new_threads retrieves the thread list and for each
1531 thread in the list, looks up the thread in GDB's internal list,
1532 ading the thread if it does not already exist. This involves
1533 getting partial thread lists from the remote target so, polling the
1534 quit_flag is required. */
1537 /* About this many threadisds fit in a packet. */
1539 #define MAXTHREADLISTRESULTS 32
1542 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1545 int done
, i
, result_count
;
1549 static threadref nextthread
;
1550 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1555 if (loopcount
++ > looplimit
)
1558 warning ("Remote fetch threadlist -infinite loop-\n");
1561 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1562 &done
, &result_count
, resultthreadlist
))
1567 /* clear for later iterations */
1569 /* Setup to resume next batch of thread references, set nextthread. */
1570 if (result_count
>= 1)
1571 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1573 while (result_count
--)
1574 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1581 remote_newthread_step (threadref
*ref
, void *context
)
1585 pid
= threadref_to_int (ref
);
1586 if (!in_thread_list (pid
))
1588 return 1; /* continue iterator */
1591 #define CRAZY_MAX_THREADS 1000
1594 remote_current_thread (int oldpid
)
1596 char *buf
= alloca (PBUFSIZ
);
1599 getpkt (buf
, PBUFSIZ
, 0);
1600 if (buf
[0] == 'Q' && buf
[1] == 'C')
1601 return strtol (&buf
[2], NULL
, 16);
1606 /* Find new threads for info threads command.
1607 * Original version, using John Metzler's thread protocol.
1611 remote_find_new_threads (void)
1613 remote_threadlist_iterator (remote_newthread_step
, 0,
1615 if (inferior_pid
== MAGIC_NULL_PID
) /* ack ack ack */
1616 inferior_pid
= remote_current_thread (inferior_pid
);
1620 * Find all threads for info threads command.
1621 * Uses new thread protocol contributed by Cisco.
1622 * Falls back and attempts to use the older method (above)
1623 * if the target doesn't respond to the new method.
1627 remote_threads_info (void)
1629 char *buf
= alloca (PBUFSIZ
);
1633 if (remote_desc
== 0) /* paranoia */
1634 error ("Command can only be used when connected to the remote target.");
1636 if (use_threadinfo_query
)
1638 putpkt ("qfThreadInfo");
1640 getpkt (bufp
, PBUFSIZ
, 0);
1641 if (bufp
[0] != '\0') /* q packet recognized */
1643 while (*bufp
++ == 'm') /* reply contains one or more TID */
1647 tid
= strtol (bufp
, &bufp
, 16);
1648 if (tid
!= 0 && !in_thread_list (tid
))
1651 while (*bufp
++ == ','); /* comma-separated list */
1652 putpkt ("qsThreadInfo");
1654 getpkt (bufp
, PBUFSIZ
, 0);
1660 /* Else fall back to old method based on jmetzler protocol. */
1661 use_threadinfo_query
= 0;
1662 remote_find_new_threads ();
1667 * Collect a descriptive string about the given thread.
1668 * The target may say anything it wants to about the thread
1669 * (typically info about its blocked / runnable state, name, etc.).
1670 * This string will appear in the info threads display.
1672 * Optional: targets are not required to implement this function.
1676 remote_threads_extra_info (struct thread_info
*tp
)
1681 struct gdb_ext_thread_info threadinfo
;
1682 static char display_buf
[100]; /* arbitrary... */
1683 char *bufp
= alloca (PBUFSIZ
);
1684 int n
= 0; /* position in display_buf */
1686 if (remote_desc
== 0) /* paranoia */
1687 internal_error (__FILE__
, __LINE__
,
1688 "remote_threads_extra_info");
1690 if (use_threadextra_query
)
1692 sprintf (bufp
, "qThreadExtraInfo,%x", tp
->pid
);
1694 getpkt (bufp
, PBUFSIZ
, 0);
1699 for (p
= display_buf
;
1700 p
< display_buf
+ sizeof(display_buf
) - 1 &&
1705 *p
= fromhex (bufp
[0]) * 16 + fromhex (bufp
[1]);
1712 /* If the above query fails, fall back to the old method. */
1713 use_threadextra_query
= 0;
1714 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1715 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1716 int_to_threadref (&id
, tp
->pid
);
1717 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1718 if (threadinfo
.active
)
1720 if (*threadinfo
.shortname
)
1721 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1722 if (*threadinfo
.display
)
1723 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1724 if (*threadinfo
.more_display
)
1725 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1726 threadinfo
.more_display
);
1730 /* for purely cosmetic reasons, clear up trailing commas */
1731 if (',' == display_buf
[n
-1])
1732 display_buf
[n
-1] = ' ';
1741 /* Restart the remote side; this is an extended protocol operation. */
1744 extended_remote_restart (void)
1746 char *buf
= alloca (PBUFSIZ
);
1748 /* Send the restart command; for reasons I don't understand the
1749 remote side really expects a number after the "R". */
1751 sprintf (&buf
[1], "%x", 0);
1754 /* Now query for status so this looks just like we restarted
1755 gdbserver from scratch. */
1757 getpkt (buf
, PBUFSIZ
, 0);
1760 /* Clean up connection to a remote debugger. */
1764 remote_close (int quitting
)
1767 SERIAL_CLOSE (remote_desc
);
1771 /* Query the remote side for the text, data and bss offsets. */
1776 char *buf
= alloca (PBUFSIZ
);
1779 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1780 struct section_offsets
*offs
;
1782 putpkt ("qOffsets");
1784 getpkt (buf
, PBUFSIZ
, 0);
1786 if (buf
[0] == '\000')
1787 return; /* Return silently. Stub doesn't support
1791 warning ("Remote failure reply: %s", buf
);
1795 /* Pick up each field in turn. This used to be done with scanf, but
1796 scanf will make trouble if CORE_ADDR size doesn't match
1797 conversion directives correctly. The following code will work
1798 with any size of CORE_ADDR. */
1799 text_addr
= data_addr
= bss_addr
= 0;
1803 if (strncmp (ptr
, "Text=", 5) == 0)
1806 /* Don't use strtol, could lose on big values. */
1807 while (*ptr
&& *ptr
!= ';')
1808 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1813 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1816 while (*ptr
&& *ptr
!= ';')
1817 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1822 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1825 while (*ptr
&& *ptr
!= ';')
1826 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1832 error ("Malformed response to offset query, %s", buf
);
1834 if (symfile_objfile
== NULL
)
1837 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1838 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1840 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1842 /* This is a temporary kludge to force data and bss to use the same offsets
1843 because that's what nlmconv does now. The real solution requires changes
1844 to the stub and remote.c that I don't have time to do right now. */
1846 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
1847 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
1849 objfile_relocate (symfile_objfile
, offs
);
1853 * Cisco version of section offsets:
1855 * Instead of having GDB query the target for the section offsets,
1856 * Cisco lets the target volunteer the information! It's also in
1857 * a different format, so here are the functions that will decode
1858 * a section offset packet from a Cisco target.
1862 * Function: remote_cisco_section_offsets
1864 * Returns: zero for success, non-zero for failure
1868 remote_cisco_section_offsets (bfd_vma text_addr
,
1871 bfd_signed_vma
*text_offs
,
1872 bfd_signed_vma
*data_offs
,
1873 bfd_signed_vma
*bss_offs
)
1875 bfd_vma text_base
, data_base
, bss_base
;
1876 struct minimal_symbol
*start
;
1881 if (symfile_objfile
== NULL
)
1882 return -1; /* no can do nothin' */
1884 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
1886 return -1; /* Can't find "_start" symbol */
1888 data_base
= bss_base
= 0;
1889 text_base
= SYMBOL_VALUE_ADDRESS (start
);
1891 abfd
= symfile_objfile
->obfd
;
1892 for (sect
= abfd
->sections
;
1896 const char *p
= bfd_get_section_name (abfd
, sect
);
1898 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
1899 if (data_base
== 0 ||
1900 data_base
> bfd_get_section_vma (abfd
, sect
))
1901 data_base
= bfd_get_section_vma (abfd
, sect
);
1902 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
1903 if (bss_base
== 0 ||
1904 bss_base
> bfd_get_section_vma (abfd
, sect
))
1905 bss_base
= bfd_get_section_vma (abfd
, sect
);
1907 *text_offs
= text_addr
- text_base
;
1908 *data_offs
= data_addr
- data_base
;
1909 *bss_offs
= bss_addr
- bss_base
;
1914 sprintf (tmp
, "VMA: text = 0x");
1915 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
1916 sprintf (tmp
+ strlen (tmp
), " data = 0x");
1917 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
1918 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
1919 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
1920 fprintf_filtered (gdb_stdlog
, tmp
);
1921 fprintf_filtered (gdb_stdlog
,
1922 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
1923 paddr_nz (*text_offs
),
1924 paddr_nz (*data_offs
),
1925 paddr_nz (*bss_offs
));
1932 * Function: remote_cisco_objfile_relocate
1934 * Relocate the symbol file for a remote target.
1938 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
1939 bfd_signed_vma bss_off
)
1941 struct section_offsets
*offs
;
1943 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
1945 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1946 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1947 simple canonical representation for this stuff. */
1949 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1950 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1952 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
1953 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
1954 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
1956 /* First call the standard objfile_relocate. */
1957 objfile_relocate (symfile_objfile
, offs
);
1959 /* Now we need to fix up the section entries already attached to
1960 the exec target. These entries will control memory transfers
1961 from the exec file. */
1963 exec_set_section_offsets (text_off
, data_off
, bss_off
);
1967 /* Stub for catch_errors. */
1970 remote_start_remote_dummy (void *dummy
)
1972 start_remote (); /* Initialize gdb process mechanisms */
1977 remote_start_remote (PTR dummy
)
1979 immediate_quit
++; /* Allow user to interrupt it */
1981 /* Ack any packet which the remote side has already sent. */
1982 SERIAL_WRITE (remote_desc
, "+", 1);
1984 /* Let the stub know that we want it to return the thread. */
1987 inferior_pid
= remote_current_thread (inferior_pid
);
1989 get_offsets (); /* Get text, data & bss offsets */
1991 putpkt ("?"); /* initiate a query from remote machine */
1994 return remote_start_remote_dummy (dummy
);
1997 /* Open a connection to a remote debugger.
1998 NAME is the filename used for communication. */
2001 remote_open (char *name
, int from_tty
)
2003 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
2006 /* Just like remote_open, but with asynchronous support. */
2008 remote_async_open (char *name
, int from_tty
)
2010 remote_async_open_1 (name
, from_tty
, &remote_async_ops
, 0);
2013 /* Open a connection to a remote debugger using the extended
2014 remote gdb protocol. NAME is the filename used for communication. */
2017 extended_remote_open (char *name
, int from_tty
)
2019 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */ );
2022 /* Just like extended_remote_open, but with asynchronous support. */
2024 extended_remote_async_open (char *name
, int from_tty
)
2026 remote_async_open_1 (name
, from_tty
, &extended_async_remote_ops
, 1 /*extended_p */ );
2029 /* Generic code for opening a connection to a remote target. */
2032 init_all_packet_configs (void)
2035 update_packet_config (&remote_protocol_P
);
2036 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2037 update_packet_config (&remote_protocol_Z
[i
]);
2038 /* Force remote_write_bytes to check whether target supports binary
2040 update_packet_config (&remote_protocol_binary_download
);
2044 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2048 error ("To open a remote debug connection, you need to specify what\n\
2049 serial device is attached to the remote system\n\
2050 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2052 /* See FIXME above */
2053 wait_forever_enabled_p
= 1;
2055 target_preopen (from_tty
);
2057 unpush_target (target
);
2059 remote_desc
= SERIAL_OPEN (name
);
2061 perror_with_name (name
);
2063 if (baud_rate
!= -1)
2065 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
2067 SERIAL_CLOSE (remote_desc
);
2068 perror_with_name (name
);
2072 SERIAL_RAW (remote_desc
);
2074 /* If there is something sitting in the buffer we might take it as a
2075 response to a command, which would be bad. */
2076 SERIAL_FLUSH_INPUT (remote_desc
);
2080 puts_filtered ("Remote debugging using ");
2081 puts_filtered (name
);
2082 puts_filtered ("\n");
2084 push_target (target
); /* Switch to using remote target now */
2086 init_all_packet_configs ();
2088 general_thread
= -2;
2089 continue_thread
= -2;
2091 /* Probe for ability to use "ThreadInfo" query, as required. */
2092 use_threadinfo_query
= 1;
2093 use_threadextra_query
= 1;
2095 /* Without this, some commands which require an active target (such
2096 as kill) won't work. This variable serves (at least) double duty
2097 as both the pid of the target process (if it has such), and as a
2098 flag indicating that a target is active. These functions should
2099 be split out into seperate variables, especially since GDB will
2100 someday have a notion of debugging several processes. */
2102 inferior_pid
= MAGIC_NULL_PID
;
2103 /* Start the remote connection; if error (0), discard this target.
2104 In particular, if the user quits, be sure to discard it
2105 (we'd be in an inconsistent state otherwise). */
2106 if (!catch_errors (remote_start_remote
, NULL
,
2107 "Couldn't establish connection to remote target\n",
2116 /* tell the remote that we're using the extended protocol. */
2117 char *buf
= alloca (PBUFSIZ
);
2119 getpkt (buf
, PBUFSIZ
, 0);
2123 /* Just like remote_open but with asynchronous support. */
2125 remote_async_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2129 error ("To open a remote debug connection, you need to specify what\n\
2130 serial device is attached to the remote system\n\
2131 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2133 target_preopen (from_tty
);
2135 unpush_target (target
);
2137 remote_desc
= SERIAL_OPEN (name
);
2139 perror_with_name (name
);
2141 if (baud_rate
!= -1)
2143 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
2145 SERIAL_CLOSE (remote_desc
);
2146 perror_with_name (name
);
2150 SERIAL_RAW (remote_desc
);
2152 /* If there is something sitting in the buffer we might take it as a
2153 response to a command, which would be bad. */
2154 SERIAL_FLUSH_INPUT (remote_desc
);
2158 puts_filtered ("Remote debugging using ");
2159 puts_filtered (name
);
2160 puts_filtered ("\n");
2163 push_target (target
); /* Switch to using remote target now */
2165 init_all_packet_configs ();
2167 general_thread
= -2;
2168 continue_thread
= -2;
2170 /* Probe for ability to use "ThreadInfo" query, as required. */
2171 use_threadinfo_query
= 1;
2172 use_threadextra_query
= 1;
2174 /* Without this, some commands which require an active target (such
2175 as kill) won't work. This variable serves (at least) double duty
2176 as both the pid of the target process (if it has such), and as a
2177 flag indicating that a target is active. These functions should
2178 be split out into seperate variables, especially since GDB will
2179 someday have a notion of debugging several processes. */
2180 inferior_pid
= MAGIC_NULL_PID
;
2182 /* With this target we start out by owning the terminal. */
2183 remote_async_terminal_ours_p
= 1;
2185 /* FIXME: cagney/1999-09-23: During the initial connection it is
2186 assumed that the target is already ready and able to respond to
2187 requests. Unfortunately remote_start_remote() eventually calls
2188 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2189 around this. Eventually a mechanism that allows
2190 wait_for_inferior() to expect/get timeouts will be
2192 wait_forever_enabled_p
= 0;
2194 /* Start the remote connection; if error (0), discard this target.
2195 In particular, if the user quits, be sure to discard it
2196 (we'd be in an inconsistent state otherwise). */
2197 if (!catch_errors (remote_start_remote
, NULL
,
2198 "Couldn't establish connection to remote target\n",
2202 wait_forever_enabled_p
= 1;
2206 wait_forever_enabled_p
= 1;
2210 /* tell the remote that we're using the extended protocol. */
2211 char *buf
= alloca (PBUFSIZ
);
2213 getpkt (buf
, PBUFSIZ
, 0);
2217 /* This takes a program previously attached to and detaches it. After
2218 this is done, GDB can be used to debug some other program. We
2219 better not have left any breakpoints in the target program or it'll
2220 die when it hits one. */
2223 remote_detach (char *args
, int from_tty
)
2225 char *buf
= alloca (PBUFSIZ
);
2228 error ("Argument given to \"detach\" when remotely debugging.");
2230 /* Tell the remote target to detach. */
2232 remote_send (buf
, PBUFSIZ
);
2234 target_mourn_inferior ();
2236 puts_filtered ("Ending remote debugging.\n");
2240 /* Same as remote_detach, but with async support. */
2242 remote_async_detach (char *args
, int from_tty
)
2244 char *buf
= alloca (PBUFSIZ
);
2247 error ("Argument given to \"detach\" when remotely debugging.");
2249 /* Tell the remote target to detach. */
2251 remote_send (buf
, PBUFSIZ
);
2253 /* Unregister the file descriptor from the event loop. */
2254 if (target_is_async_p ())
2255 SERIAL_ASYNC (remote_desc
, NULL
, 0);
2257 target_mourn_inferior ();
2259 puts_filtered ("Ending remote debugging.\n");
2262 /* Convert hex digit A to a number. */
2267 if (a
>= '0' && a
<= '9')
2269 else if (a
>= 'a' && a
<= 'f')
2270 return a
- 'a' + 10;
2271 else if (a
>= 'A' && a
<= 'F')
2272 return a
- 'A' + 10;
2274 error ("Reply contains invalid hex digit %d", a
);
2277 /* Convert number NIB to a hex digit. */
2285 return 'a' + nib
- 10;
2288 /* Tell the remote machine to resume. */
2290 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2292 static int last_sent_step
;
2295 remote_resume (int pid
, int step
, enum target_signal siggnal
)
2297 char *buf
= alloca (PBUFSIZ
);
2300 set_thread (0, 0); /* run any thread */
2302 set_thread (pid
, 0); /* run this thread */
2304 last_sent_signal
= siggnal
;
2305 last_sent_step
= step
;
2307 /* A hook for when we need to do something at the last moment before
2309 if (target_resume_hook
)
2310 (*target_resume_hook
) ();
2312 if (siggnal
!= TARGET_SIGNAL_0
)
2314 buf
[0] = step
? 'S' : 'C';
2315 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2316 buf
[2] = tohex ((int) siggnal
& 0xf);
2320 strcpy (buf
, step
? "s" : "c");
2325 /* Same as remote_resume, but with async support. */
2327 remote_async_resume (int pid
, int step
, enum target_signal siggnal
)
2329 char *buf
= alloca (PBUFSIZ
);
2332 set_thread (0, 0); /* run any thread */
2334 set_thread (pid
, 0); /* run this thread */
2336 last_sent_signal
= siggnal
;
2337 last_sent_step
= step
;
2339 /* A hook for when we need to do something at the last moment before
2341 if (target_resume_hook
)
2342 (*target_resume_hook
) ();
2344 if (siggnal
!= TARGET_SIGNAL_0
)
2346 buf
[0] = step
? 'S' : 'C';
2347 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2348 buf
[2] = tohex ((int) siggnal
& 0xf);
2352 strcpy (buf
, step
? "s" : "c");
2354 /* We are about to start executing the inferior, let's register it
2355 with the event loop. NOTE: this is the one place where all the
2356 execution commands end up. We could alternatively do this in each
2357 of the execution commands in infcmd.c.*/
2358 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2359 into infcmd.c in order to allow inferior function calls to work
2360 NOT asynchronously. */
2361 if (event_loop_p
&& target_can_async_p ())
2362 target_async (inferior_event_handler
, 0);
2363 /* Tell the world that the target is now executing. */
2364 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2365 this? Instead, should the client of target just assume (for
2366 async targets) that the target is going to start executing? Is
2367 this information already found in the continuation block? */
2368 if (target_is_async_p ())
2369 target_executing
= 1;
2374 /* Set up the signal handler for SIGINT, while the target is
2375 executing, ovewriting the 'regular' SIGINT signal handler. */
2377 initialize_sigint_signal_handler (void)
2379 sigint_remote_token
=
2380 create_async_signal_handler (async_remote_interrupt
, NULL
);
2381 signal (SIGINT
, handle_remote_sigint
);
2384 /* Signal handler for SIGINT, while the target is executing. */
2386 handle_remote_sigint (int sig
)
2388 signal (sig
, handle_remote_sigint_twice
);
2389 sigint_remote_twice_token
=
2390 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2391 mark_async_signal_handler_wrapper (sigint_remote_token
);
2394 /* Signal handler for SIGINT, installed after SIGINT has already been
2395 sent once. It will take effect the second time that the user sends
2398 handle_remote_sigint_twice (int sig
)
2400 signal (sig
, handle_sigint
);
2401 sigint_remote_twice_token
=
2402 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2403 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2406 /* Perform the real interruption of the target execution, in response
2409 async_remote_interrupt (gdb_client_data arg
)
2412 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2417 /* Perform interrupt, if the first attempt did not succeed. Just give
2418 up on the target alltogether. */
2420 async_remote_interrupt_twice (gdb_client_data arg
)
2423 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2424 /* Do something only if the target was not killed by the previous
2426 if (target_executing
)
2429 signal (SIGINT
, handle_remote_sigint
);
2433 /* Reinstall the usual SIGINT handlers, after the target has
2436 cleanup_sigint_signal_handler (void *dummy
)
2438 signal (SIGINT
, handle_sigint
);
2439 if (sigint_remote_twice_token
)
2440 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2441 if (sigint_remote_token
)
2442 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2445 /* Send ^C to target to halt it. Target will respond, and send us a
2447 static void (*ofunc
) (int);
2449 /* The command line interface's stop routine. This function is installed
2450 as a signal handler for SIGINT. The first time a user requests a
2451 stop, we call remote_stop to send a break or ^C. If there is no
2452 response from the target (it didn't stop when the user requested it),
2453 we ask the user if he'd like to detach from the target. */
2455 remote_interrupt (int signo
)
2457 /* If this doesn't work, try more severe steps. */
2458 signal (signo
, remote_interrupt_twice
);
2461 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2466 /* The user typed ^C twice. */
2469 remote_interrupt_twice (int signo
)
2471 signal (signo
, ofunc
);
2473 signal (signo
, remote_interrupt
);
2476 /* This is the generic stop called via the target vector. When a target
2477 interrupt is requested, either by the command line or the GUI, we
2478 will eventually end up here. */
2482 /* Send a break or a ^C, depending on user preference. */
2484 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2487 SERIAL_SEND_BREAK (remote_desc
);
2489 SERIAL_WRITE (remote_desc
, "\003", 1);
2492 /* Ask the user what to do when an interrupt is received. */
2495 interrupt_query (void)
2497 target_terminal_ours ();
2499 if (query ("Interrupted while waiting for the program.\n\
2500 Give up (and stop debugging it)? "))
2502 target_mourn_inferior ();
2503 return_to_top_level (RETURN_QUIT
);
2506 target_terminal_inferior ();
2509 /* Enable/disable target terminal ownership. Most targets can use
2510 terminal groups to control terminal ownership. Remote targets are
2511 different in that explicit transfer of ownership to/from GDB/target
2515 remote_async_terminal_inferior (void)
2517 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2518 sync_execution here. This function should only be called when
2519 GDB is resuming the inferior in the forground. A background
2520 resume (``run&'') should leave GDB in control of the terminal and
2521 consequently should not call this code. */
2522 if (!sync_execution
)
2524 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2525 calls target_terminal_*() idenpotent. The event-loop GDB talking
2526 to an asynchronous target with a synchronous command calls this
2527 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2528 stops trying to transfer the terminal to the target when it
2529 shouldn't this guard can go away. */
2530 if (!remote_async_terminal_ours_p
)
2532 delete_file_handler (input_fd
);
2533 remote_async_terminal_ours_p
= 0;
2534 initialize_sigint_signal_handler ();
2535 /* NOTE: At this point we could also register our selves as the
2536 recipient of all input. Any characters typed could then be
2537 passed on down to the target. */
2541 remote_async_terminal_ours (void)
2543 /* See FIXME in remote_async_terminal_inferior. */
2544 if (!sync_execution
)
2546 /* See FIXME in remote_async_terminal_inferior. */
2547 if (remote_async_terminal_ours_p
)
2549 cleanup_sigint_signal_handler (NULL
);
2550 add_file_handler (input_fd
, stdin_event_handler
, 0);
2551 remote_async_terminal_ours_p
= 1;
2554 /* If nonzero, ignore the next kill. */
2559 remote_console_output (char *msg
)
2563 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2566 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2569 fputs_unfiltered (tb
, gdb_stdtarg
);
2571 gdb_flush (gdb_stdtarg
);
2574 /* Wait until the remote machine stops, then return,
2575 storing status in STATUS just as `wait' would.
2576 Returns "pid", which in the case of a multi-threaded
2577 remote OS, is the thread-id. */
2580 remote_wait (int pid
, struct target_waitstatus
*status
)
2582 unsigned char *buf
= alloca (PBUFSIZ
);
2583 int thread_num
= -1;
2585 status
->kind
= TARGET_WAITKIND_EXITED
;
2586 status
->value
.integer
= 0;
2592 ofunc
= signal (SIGINT
, remote_interrupt
);
2593 getpkt (buf
, PBUFSIZ
, 1);
2594 signal (SIGINT
, ofunc
);
2596 /* This is a hook for when we need to do something (perhaps the
2597 collection of trace data) every time the target stops. */
2598 if (target_wait_loop_hook
)
2599 (*target_wait_loop_hook
) ();
2603 case 'E': /* Error of some sort */
2604 warning ("Remote failure reply: %s", buf
);
2606 case 'T': /* Status with PC, SP, FP, ... */
2610 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
2612 /* Expedited reply, containing Signal, {regno, reg} repeat */
2613 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2615 n... = register number
2616 r... = register contents
2618 p
= &buf
[3]; /* after Txx */
2625 /* Read the register number */
2626 regno
= strtol ((const char *) p
, &p_temp
, 16);
2627 p1
= (unsigned char *) p_temp
;
2629 if (p1
== p
) /* No register number present here */
2631 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2633 warning ("Malformed packet(a) (missing colon): %s\n\
2636 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2638 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2639 record_currthread (thread_num
);
2640 p
= (unsigned char *) p_temp
;
2648 warning ("Malformed packet(b) (missing colon): %s\n\
2652 if (regno
>= NUM_REGS
)
2653 warning ("Remote sent bad register number %ld: %s\n\
2657 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2659 if (p
[0] == 0 || p
[1] == 0)
2660 warning ("Remote reply is too short: %s", buf
);
2661 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2664 supply_register (regno
, regs
);
2669 warning ("Remote register badly formatted: %s", buf
);
2670 warning (" here: %s", p
);
2675 case 'S': /* Old style status, just signal only */
2676 status
->kind
= TARGET_WAITKIND_STOPPED
;
2677 status
->value
.sig
= (enum target_signal
)
2678 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2682 /* Export Cisco kernel mode as a convenience variable
2683 (so that it can be used in the GDB prompt if desired). */
2685 if (cisco_kernel_mode
== 1)
2686 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2687 value_from_string ("PDEBUG-"));
2688 cisco_kernel_mode
= 0;
2689 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2690 record_currthread (thread_num
);
2692 else if (buf
[3] == 'k')
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 ("KDEBUG-"));
2700 cisco_kernel_mode
= 1;
2703 case 'N': /* Cisco special: status and offsets */
2705 bfd_vma text_addr
, data_addr
, bss_addr
;
2706 bfd_signed_vma text_off
, data_off
, bss_off
;
2709 status
->kind
= TARGET_WAITKIND_STOPPED
;
2710 status
->value
.sig
= (enum target_signal
)
2711 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2713 if (symfile_objfile
== NULL
)
2715 warning ("Relocation packet received with no symbol file. \
2720 /* Relocate object file. Buffer format is NAATT;DD;BB
2721 * where AA is the signal number, TT is the new text
2722 * address, DD * is the new data address, and BB is the
2723 * new bss address. */
2726 text_addr
= strtoul (p
, (char **) &p1
, 16);
2727 if (p1
== p
|| *p1
!= ';')
2728 warning ("Malformed relocation packet: Packet '%s'", buf
);
2730 data_addr
= strtoul (p
, (char **) &p1
, 16);
2731 if (p1
== p
|| *p1
!= ';')
2732 warning ("Malformed relocation packet: Packet '%s'", buf
);
2734 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2736 warning ("Malformed relocation packet: Packet '%s'", buf
);
2738 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2739 &text_off
, &data_off
, &bss_off
)
2741 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2742 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2746 case 'W': /* Target exited */
2748 /* The remote process exited. */
2749 status
->kind
= TARGET_WAITKIND_EXITED
;
2750 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2754 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2755 status
->value
.sig
= (enum target_signal
)
2756 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2760 case 'O': /* Console output */
2761 remote_console_output (buf
+ 1);
2764 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2766 /* Zero length reply means that we tried 'S' or 'C' and
2767 the remote system doesn't support it. */
2768 target_terminal_ours_for_output ();
2770 ("Can't send signals to this remote system. %s not sent.\n",
2771 target_signal_to_name (last_sent_signal
));
2772 last_sent_signal
= TARGET_SIGNAL_0
;
2773 target_terminal_inferior ();
2775 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2776 putpkt ((char *) buf
);
2779 /* else fallthrough */
2781 warning ("Invalid remote reply: %s", buf
);
2786 if (thread_num
!= -1)
2790 return inferior_pid
;
2793 /* Async version of remote_wait. */
2795 remote_async_wait (int pid
, struct target_waitstatus
*status
)
2797 unsigned char *buf
= alloca (PBUFSIZ
);
2798 int thread_num
= -1;
2800 status
->kind
= TARGET_WAITKIND_EXITED
;
2801 status
->value
.integer
= 0;
2807 if (!target_is_async_p ())
2808 ofunc
= signal (SIGINT
, remote_interrupt
);
2809 /* FIXME: cagney/1999-09-27: If we're in async mode we should
2810 _never_ wait for ever -> test on target_is_async_p().
2811 However, before we do that we need to ensure that the caller
2812 knows how to take the target into/out of async mode. */
2813 getpkt (buf
, PBUFSIZ
, wait_forever_enabled_p
);
2814 if (!target_is_async_p ())
2815 signal (SIGINT
, ofunc
);
2817 /* This is a hook for when we need to do something (perhaps the
2818 collection of trace data) every time the target stops. */
2819 if (target_wait_loop_hook
)
2820 (*target_wait_loop_hook
) ();
2824 case 'E': /* Error of some sort */
2825 warning ("Remote failure reply: %s", buf
);
2827 case 'T': /* Status with PC, SP, FP, ... */
2831 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
2833 /* Expedited reply, containing Signal, {regno, reg} repeat */
2834 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2836 n... = register number
2837 r... = register contents
2839 p
= &buf
[3]; /* after Txx */
2846 /* Read the register number */
2847 regno
= strtol ((const char *) p
, &p_temp
, 16);
2848 p1
= (unsigned char *) p_temp
;
2850 if (p1
== p
) /* No register number present here */
2852 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2854 warning ("Malformed packet(a) (missing colon): %s\n\
2857 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2859 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2860 record_currthread (thread_num
);
2861 p
= (unsigned char *) p_temp
;
2869 warning ("Malformed packet(b) (missing colon): %s\n\
2873 if (regno
>= NUM_REGS
)
2874 warning ("Remote sent bad register number %ld: %s\n\
2878 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
2880 if (p
[0] == 0 || p
[1] == 0)
2881 warning ("Remote reply is too short: %s", buf
);
2882 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2885 supply_register (regno
, regs
);
2890 warning ("Remote register badly formatted: %s", buf
);
2891 warning (" here: %s", p
);
2896 case 'S': /* Old style status, just signal only */
2897 status
->kind
= TARGET_WAITKIND_STOPPED
;
2898 status
->value
.sig
= (enum target_signal
)
2899 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2903 /* Export Cisco kernel mode as a convenience variable
2904 (so that it can be used in the GDB prompt if desired). */
2906 if (cisco_kernel_mode
== 1)
2907 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2908 value_from_string ("PDEBUG-"));
2909 cisco_kernel_mode
= 0;
2910 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2911 record_currthread (thread_num
);
2913 else if (buf
[3] == 'k')
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 ("KDEBUG-"));
2921 cisco_kernel_mode
= 1;
2924 case 'N': /* Cisco special: status and offsets */
2926 bfd_vma text_addr
, data_addr
, bss_addr
;
2927 bfd_signed_vma text_off
, data_off
, bss_off
;
2930 status
->kind
= TARGET_WAITKIND_STOPPED
;
2931 status
->value
.sig
= (enum target_signal
)
2932 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2934 if (symfile_objfile
== NULL
)
2936 warning ("Relocation packet recieved with no symbol file. \
2941 /* Relocate object file. Buffer format is NAATT;DD;BB
2942 * where AA is the signal number, TT is the new text
2943 * address, DD * is the new data address, and BB is the
2944 * new bss address. */
2947 text_addr
= strtoul (p
, (char **) &p1
, 16);
2948 if (p1
== p
|| *p1
!= ';')
2949 warning ("Malformed relocation packet: Packet '%s'", buf
);
2951 data_addr
= strtoul (p
, (char **) &p1
, 16);
2952 if (p1
== p
|| *p1
!= ';')
2953 warning ("Malformed relocation packet: Packet '%s'", buf
);
2955 bss_addr
= strtoul (p
, (char **) &p1
, 16);
2957 warning ("Malformed relocation packet: Packet '%s'", buf
);
2959 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
2960 &text_off
, &data_off
, &bss_off
)
2962 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2963 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
2967 case 'W': /* Target exited */
2969 /* The remote process exited. */
2970 status
->kind
= TARGET_WAITKIND_EXITED
;
2971 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2975 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2976 status
->value
.sig
= (enum target_signal
)
2977 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2981 case 'O': /* Console output */
2982 remote_console_output (buf
+ 1);
2983 /* Return immediately to the event loop. The event loop will
2984 still be waiting on the inferior afterwards. */
2985 status
->kind
= TARGET_WAITKIND_IGNORE
;
2988 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2990 /* Zero length reply means that we tried 'S' or 'C' and
2991 the remote system doesn't support it. */
2992 target_terminal_ours_for_output ();
2994 ("Can't send signals to this remote system. %s not sent.\n",
2995 target_signal_to_name (last_sent_signal
));
2996 last_sent_signal
= TARGET_SIGNAL_0
;
2997 target_terminal_inferior ();
2999 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3000 putpkt ((char *) buf
);
3003 /* else fallthrough */
3005 warning ("Invalid remote reply: %s", buf
);
3010 if (thread_num
!= -1)
3014 return inferior_pid
;
3017 /* Number of bytes of registers this stub implements. */
3019 static int register_bytes_found
;
3021 /* Read the remote registers into the block REGS. */
3022 /* Currently we just read all the registers, so we don't use regno. */
3026 remote_fetch_registers (int regno
)
3028 char *buf
= alloca (PBUFSIZ
);
3031 char *regs
= alloca (REGISTER_BYTES
);
3033 set_thread (inferior_pid
, 1);
3036 remote_send (buf
, PBUFSIZ
);
3038 /* Save the size of the packet sent to us by the target. Its used
3039 as a heuristic when determining the max size of packets that the
3040 target can safely receive. */
3041 if (actual_register_packet_size
== 0)
3042 actual_register_packet_size
= strlen (buf
);
3044 /* Unimplemented registers read as all bits zero. */
3045 memset (regs
, 0, REGISTER_BYTES
);
3047 /* We can get out of synch in various cases. If the first character
3048 in the buffer is not a hex character, assume that has happened
3049 and try to fetch another packet to read. */
3050 while ((buf
[0] < '0' || buf
[0] > '9')
3051 && (buf
[0] < 'a' || buf
[0] > 'f')
3052 && buf
[0] != 'x') /* New: unavailable register value */
3055 fprintf_unfiltered (gdb_stdlog
,
3056 "Bad register packet; fetching a new packet\n");
3057 getpkt (buf
, PBUFSIZ
, 0);
3060 /* Reply describes registers byte by byte, each byte encoded as two
3061 hex characters. Suck them all up, then supply them to the
3062 register cacheing/storage mechanism. */
3065 for (i
= 0; i
< REGISTER_BYTES
; i
++)
3071 warning ("Remote reply is of odd length: %s", buf
);
3072 /* Don't change register_bytes_found in this case, and don't
3073 print a second warning. */
3076 if (p
[0] == 'x' && p
[1] == 'x')
3077 regs
[i
] = 0; /* 'x' */
3079 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3083 if (i
!= register_bytes_found
)
3085 register_bytes_found
= i
;
3086 if (REGISTER_BYTES_OK_P ()
3087 && !REGISTER_BYTES_OK (i
))
3088 warning ("Remote reply is too short: %s", buf
);
3092 for (i
= 0; i
< NUM_REGS
; i
++)
3094 supply_register (i
, ®s
[REGISTER_BYTE (i
)]);
3095 if (buf
[REGISTER_BYTE (i
) * 2] == 'x')
3096 set_register_cached (i
, -1);
3100 /* Prepare to store registers. Since we may send them all (using a
3101 'G' request), we have to read out the ones we don't want to change
3105 remote_prepare_to_store (void)
3107 /* Make sure the entire registers array is valid. */
3108 switch (remote_protocol_P
.support
)
3110 case PACKET_DISABLE
:
3111 case PACKET_SUPPORT_UNKNOWN
:
3112 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
);
3119 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
3120 packet was not recognized. */
3123 store_register_using_P (int regno
)
3125 /* Try storing a single register. */
3126 char *buf
= alloca (PBUFSIZ
);
3131 sprintf (buf
, "P%x=", regno
);
3132 p
= buf
+ strlen (buf
);
3133 regp
= register_buffer (regno
);
3134 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
3136 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
3137 *p
++ = tohex (regp
[i
] & 0xf);
3140 remote_send (buf
, PBUFSIZ
);
3142 return buf
[0] != '\0';
3146 /* Store register REGNO, or all registers if REGNO == -1, from the contents
3147 of the register cache buffer. FIXME: ignores errors. */
3150 remote_store_registers (int regno
)
3152 char *buf
= alloca (PBUFSIZ
);
3157 set_thread (inferior_pid
, 1);
3161 switch (remote_protocol_P
.support
)
3163 case PACKET_DISABLE
:
3166 if (store_register_using_P (regno
))
3169 error ("Protocol error: P packet not recognized by stub");
3170 case PACKET_SUPPORT_UNKNOWN
:
3171 if (store_register_using_P (regno
))
3173 /* The stub recognized the 'P' packet. Remember this. */
3174 remote_protocol_P
.support
= PACKET_ENABLE
;
3179 /* The stub does not support the 'P' packet. Use 'G'
3180 instead, and don't try using 'P' in the future (it
3181 will just waste our time). */
3182 remote_protocol_P
.support
= PACKET_DISABLE
;
3190 /* Command describes registers byte by byte,
3191 each byte encoded as two hex characters. */
3193 regs
= register_buffer (-1);
3195 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3196 for (i
= 0; i
< register_bytes_found
; i
++)
3198 *p
++ = tohex ((regs
[i
] >> 4) & 0xf);
3199 *p
++ = tohex (regs
[i
] & 0xf);
3203 remote_send (buf
, PBUFSIZ
);
3207 /* Return the number of hex digits in num. */
3210 hexnumlen (ULONGEST num
)
3214 for (i
= 0; num
!= 0; i
++)
3220 /* Set BUF to the minimum number of hex digits representing NUM. */
3223 hexnumstr (char *buf
, ULONGEST num
)
3225 int len
= hexnumlen (num
);
3226 return hexnumnstr (buf
, num
, len
);
3230 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3233 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3239 for (i
= width
- 1; i
>= 0; i
--)
3241 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3248 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3251 remote_address_masked (CORE_ADDR addr
)
3253 if (remote_address_size
> 0
3254 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3256 /* Only create a mask when that mask can safely be constructed
3257 in a ULONGEST variable. */
3259 mask
= (mask
<< remote_address_size
) - 1;
3265 /* Determine whether the remote target supports binary downloading.
3266 This is accomplished by sending a no-op memory write of zero length
3267 to the target at the specified address. It does not suffice to send
3268 the whole packet, since many stubs strip the eighth bit and subsequently
3269 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3271 NOTE: This can still lose if the serial line is not eight-bit
3272 clean. In cases like this, the user should clear "remote
3276 check_binary_download (CORE_ADDR addr
)
3278 switch (remote_protocol_binary_download
.support
)
3280 case PACKET_DISABLE
:
3284 case PACKET_SUPPORT_UNKNOWN
:
3286 char *buf
= alloca (PBUFSIZ
);
3291 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3293 p
+= hexnumstr (p
, (ULONGEST
) 0);
3297 putpkt_binary (buf
, (int) (p
- buf
));
3298 getpkt (buf
, PBUFSIZ
, 0);
3303 fprintf_unfiltered (gdb_stdlog
,
3304 "binary downloading NOT suppported by target\n");
3305 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3310 fprintf_unfiltered (gdb_stdlog
,
3311 "binary downloading suppported by target\n");
3312 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3319 /* Write memory data directly to the remote machine.
3320 This does not inform the data cache; the data cache uses this.
3321 MEMADDR is the address in the remote memory space.
3322 MYADDR is the address of the buffer in our space.
3323 LEN is the number of bytes.
3325 Returns number of bytes transferred, or 0 (setting errno) for
3326 error. Only transfer a single packet. */
3329 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3332 int max_buf_size
; /* Max size of packet output buffer */
3334 unsigned char *plen
;
3340 /* Verify that the target can support a binary download */
3341 check_binary_download (memaddr
);
3343 /* Determine the max packet size. */
3344 max_buf_size
= get_memory_write_packet_size ();
3345 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3346 buf
= alloca (sizeof_buf
);
3348 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3349 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3351 /* construct "M"<memaddr>","<len>":" */
3352 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3355 /* Append [XM]. Compute a best guess of the number of bytes
3356 actually transfered. */
3357 switch (remote_protocol_binary_download
.support
)
3361 /* Best guess at number of bytes that will fit. */
3362 todo
= min (len
, max_buf_size
);
3364 case PACKET_DISABLE
:
3366 /* num bytes that will fit */
3367 todo
= min (len
, max_buf_size
/ 2);
3369 case PACKET_SUPPORT_UNKNOWN
:
3370 internal_error (__FILE__
, __LINE__
,
3371 "remote_write_bytes: bad internal state");
3373 internal_error (__FILE__
, __LINE__
, "bad switch");
3376 /* Append <memaddr> */
3377 memaddr
= remote_address_masked (memaddr
);
3378 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3381 /* Append <len>. Retain the location/size of <len>. It may
3382 need to be adjusted once the packet body has been created. */
3384 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3389 /* Append the packet body. */
3390 switch (remote_protocol_binary_download
.support
)
3393 /* Binary mode. Send target system values byte by byte, in
3394 increasing byte addresses. Only escape certain critical
3397 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3400 switch (myaddr
[nr_bytes
] & 0xff)
3405 /* These must be escaped */
3407 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3410 *p
++ = myaddr
[nr_bytes
] & 0xff;
3414 if (nr_bytes
< todo
)
3416 /* Escape chars have filled up the buffer prematurely,
3417 and we have actually sent fewer bytes than planned.
3418 Fix-up the length field of the packet. Use the same
3419 number of characters as before. */
3421 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3422 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3425 case PACKET_DISABLE
:
3426 /* Normal mode: Send target system values byte by byte, in
3427 increasing byte addresses. Each byte is encoded as a two hex
3429 for (nr_bytes
= 0; nr_bytes
< todo
; nr_bytes
++)
3431 *p
++ = tohex ((myaddr
[nr_bytes
] >> 4) & 0xf);
3432 *p
++ = tohex (myaddr
[nr_bytes
] & 0xf);
3436 case PACKET_SUPPORT_UNKNOWN
:
3437 internal_error (__FILE__
, __LINE__
,
3438 "remote_write_bytes: bad internal state");
3440 internal_error (__FILE__
, __LINE__
, "bad switch");
3443 putpkt_binary (buf
, (int) (p
- buf
));
3444 getpkt (buf
, sizeof_buf
, 0);
3448 /* There is no correspondance between what the remote protocol
3449 uses for errors and errno codes. We would like a cleaner way
3450 of representing errors (big enough to include errno codes,
3451 bfd_error codes, and others). But for now just return EIO. */
3456 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3457 bytes than we'd planned. */
3461 /* Read memory data directly from the remote machine.
3462 This does not use the data cache; the data cache uses this.
3463 MEMADDR is the address in the remote memory space.
3464 MYADDR is the address of the buffer in our space.
3465 LEN is the number of bytes.
3467 Returns number of bytes transferred, or 0 for error. */
3469 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3470 remote targets) shouldn't attempt to read the entire buffer.
3471 Instead it should read a single packet worth of data and then
3472 return the byte size of that packet to the caller. The caller (its
3473 caller and its callers caller ;-) already contains code for
3474 handling partial reads. */
3477 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3480 int max_buf_size
; /* Max size of packet output buffer */
3484 /* Create a buffer big enough for this packet. */
3485 max_buf_size
= get_memory_read_packet_size ();
3486 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3487 buf
= alloca (sizeof_buf
);
3496 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3498 /* construct "m"<memaddr>","<len>" */
3499 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3500 memaddr
= remote_address_masked (memaddr
);
3503 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3505 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3509 getpkt (buf
, sizeof_buf
, 0);
3513 /* There is no correspondance between what the remote protocol uses
3514 for errors and errno codes. We would like a cleaner way of
3515 representing errors (big enough to include errno codes, bfd_error
3516 codes, and others). But for now just return EIO. */
3521 /* Reply describes memory byte by byte,
3522 each byte encoded as two hex characters. */
3525 for (i
= 0; i
< todo
; i
++)
3527 if (p
[0] == 0 || p
[1] == 0)
3528 /* Reply is short. This means that we were able to read
3529 only part of what we wanted to. */
3530 return i
+ (origlen
- len
);
3531 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3541 /* Read or write LEN bytes from inferior memory at MEMADDR,
3542 transferring to or from debugger address BUFFER. Write to inferior if
3543 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3544 for error. TARGET is unused. */
3548 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3550 struct mem_attrib
*attrib ATTRIBUTE_UNUSED
,
3551 struct target_ops
*target
)
3553 CORE_ADDR targ_addr
;
3557 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3562 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3564 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3571 /* Enable after 4.12. */
3574 remote_search (int len
, char *data
, char *mask
, CORE_ADDR startaddr
,
3575 int increment
, CORE_ADDR lorange
, CORE_ADDR hirange
,
3576 CORE_ADDR
*addr_found
, char *data_found
)
3578 if (increment
== -4 && len
== 4)
3580 long mask_long
, data_long
;
3581 long data_found_long
;
3582 CORE_ADDR addr_we_found
;
3583 char *buf
= alloca (PBUFSIZ
);
3584 long returned_long
[2];
3587 mask_long
= extract_unsigned_integer (mask
, len
);
3588 data_long
= extract_unsigned_integer (data
, len
);
3589 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
3591 getpkt (buf
, PBUFSIZ
, 0);
3594 /* The stub doesn't support the 't' request. We might want to
3595 remember this fact, but on the other hand the stub could be
3596 switched on us. Maybe we should remember it only until
3597 the next "target remote". */
3598 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3599 hirange
, addr_found
, data_found
);
3604 /* There is no correspondance between what the remote protocol uses
3605 for errors and errno codes. We would like a cleaner way of
3606 representing errors (big enough to include errno codes, bfd_error
3607 codes, and others). But for now just use EIO. */
3608 memory_error (EIO
, startaddr
);
3611 while (*p
!= '\0' && *p
!= ',')
3612 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
3614 error ("Protocol error: short return for search");
3616 data_found_long
= 0;
3617 while (*p
!= '\0' && *p
!= ',')
3618 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
3619 /* Ignore anything after this comma, for future extensions. */
3621 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
3627 *addr_found
= addr_we_found
;
3628 *data_found
= store_unsigned_integer (data_we_found
, len
);
3631 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3632 hirange
, addr_found
, data_found
);
3637 remote_files_info (struct target_ops
*ignore
)
3639 puts_filtered ("Debugging a target over a serial line.\n");
3642 /* Stuff for dealing with the packets which are part of this protocol.
3643 See comment at top of file for details. */
3645 /* Read a single character from the remote end, masking it down to 7 bits. */
3648 readchar (int timeout
)
3652 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
3657 switch ((enum serial_rc
) ch
)
3660 target_mourn_inferior ();
3661 error ("Remote connection closed");
3664 perror_with_name ("Remote communication error");
3666 case SERIAL_TIMEOUT
:
3672 /* Send the command in BUF to the remote machine, and read the reply
3673 into BUF. Report an error if we get an error reply. */
3676 remote_send (char *buf
,
3680 getpkt (buf
, sizeof_buf
, 0);
3683 error ("Remote failure reply: %s", buf
);
3686 /* Display a null-terminated packet on stdout, for debugging, using C
3690 print_packet (char *buf
)
3692 puts_filtered ("\"");
3693 fputstr_filtered (buf
, '"', gdb_stdout
);
3694 puts_filtered ("\"");
3700 return putpkt_binary (buf
, strlen (buf
));
3703 /* Send a packet to the remote machine, with error checking. The data
3704 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3705 to account for the $, # and checksum, and for a possible /0 if we are
3706 debugging (remote_debug) and want to print the sent packet as a string */
3709 putpkt_binary (char *buf
, int cnt
)
3712 unsigned char csum
= 0;
3713 char *buf2
= alloca (cnt
+ 6);
3714 long sizeof_junkbuf
= PBUFSIZ
;
3715 char *junkbuf
= alloca (sizeof_junkbuf
);
3721 /* Copy the packet into buffer BUF2, encapsulating it
3722 and giving it a checksum. */
3727 for (i
= 0; i
< cnt
; i
++)
3733 *p
++ = tohex ((csum
>> 4) & 0xf);
3734 *p
++ = tohex (csum
& 0xf);
3736 /* Send it over and over until we get a positive ack. */
3740 int started_error_output
= 0;
3745 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
3746 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
3747 fprintf_unfiltered (gdb_stdlog
, "...");
3748 gdb_flush (gdb_stdlog
);
3750 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
3751 perror_with_name ("putpkt: write failed");
3753 /* read until either a timeout occurs (-2) or '+' is read */
3756 ch
= readchar (remote_timeout
);
3764 case SERIAL_TIMEOUT
:
3766 if (started_error_output
)
3768 putchar_unfiltered ('\n');
3769 started_error_output
= 0;
3778 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
3782 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
3783 case SERIAL_TIMEOUT
:
3787 break; /* Retransmit buffer */
3791 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
3792 /* It's probably an old response, and we're out of sync.
3793 Just gobble up the packet and ignore it. */
3794 read_frame (junkbuf
, sizeof_junkbuf
);
3795 continue; /* Now, go look for + */
3800 if (!started_error_output
)
3802 started_error_output
= 1;
3803 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
3805 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
3809 break; /* Here to retransmit */
3813 /* This is wrong. If doing a long backtrace, the user should be
3814 able to get out next time we call QUIT, without anything as
3815 violent as interrupt_query. If we want to provide a way out of
3816 here without getting to the next QUIT, it should be based on
3817 hitting ^C twice as in remote_wait. */
3827 static int remote_cisco_mode
;
3829 /* Come here after finding the start of the frame. Collect the rest
3830 into BUF, verifying the checksum, length, and handling run-length
3831 compression. No more than sizeof_buf-1 characters are read so that
3832 the buffer can be NUL terminated.
3834 Returns -1 on error, number of characters in buffer (ignoring the
3835 trailing NULL) on success. (could be extended to return one of the
3836 SERIAL status indications). */
3839 read_frame (char *buf
,
3851 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
3852 c
= readchar (remote_timeout
);
3855 case SERIAL_TIMEOUT
:
3857 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
3861 fputs_filtered ("Saw new packet start in middle of old one\n",
3863 return -1; /* Start a new packet, count retries */
3866 unsigned char pktcsum
;
3872 check_0
= readchar (remote_timeout
);
3874 check_1
= readchar (remote_timeout
);
3876 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
3879 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
3882 else if (check_0
< 0 || check_1
< 0)
3885 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
3889 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
3890 if (csum
== pktcsum
)
3895 fprintf_filtered (gdb_stdlog
,
3896 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3898 fputs_filtered (buf
, gdb_stdlog
);
3899 fputs_filtered ("\n", gdb_stdlog
);
3901 /* Number of characters in buffer ignoring trailing
3905 case '*': /* Run length encoding */
3910 if (remote_cisco_mode
== 0)
3912 c
= readchar (remote_timeout
);
3914 repeat
= c
- ' ' + 3; /* Compute repeat count */
3918 /* Cisco's run-length encoding variant uses two
3919 hex chars to represent the repeat count. */
3921 c
= readchar (remote_timeout
);
3923 repeat
= fromhex (c
) << 4;
3924 c
= readchar (remote_timeout
);
3926 repeat
+= fromhex (c
);
3929 /* The character before ``*'' is repeated. */
3931 if (repeat
> 0 && repeat
<= 255
3933 && bc
+ repeat
< sizeof_buf
- 1)
3935 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
3941 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
3942 puts_filtered (buf
);
3943 puts_filtered ("\n");
3947 if (bc
< sizeof_buf
- 1)
3955 puts_filtered ("Remote packet too long: ");
3956 puts_filtered (buf
);
3957 puts_filtered ("\n");
3964 /* Read a packet from the remote machine, with error checking, and
3965 store it in BUF. If FOREVER, wait forever rather than timing out;
3966 this is used (in synchronous mode) to wait for a target that is is
3967 executing user code to stop. */
3968 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
3969 don't have to change all the calls to getpkt to deal with the
3970 return value, because at the moment I don't know what the right
3971 thing to do it for those. */
3979 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
3983 /* Read a packet from the remote machine, with error checking, and
3984 store it in BUF. If FOREVER, wait forever rather than timing out;
3985 this is used (in synchronous mode) to wait for a target that is is
3986 executing user code to stop. If FOREVER == 0, this function is
3987 allowed to time out gracefully and return an indication of this to
3990 getpkt_sane (char *buf
,
3999 strcpy (buf
, "timeout");
4003 timeout
= watchdog
> 0 ? watchdog
: -1;
4007 timeout
= remote_timeout
;
4011 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4013 /* This can loop forever if the remote side sends us characters
4014 continuously, but if it pauses, we'll get a zero from readchar
4015 because of timeout. Then we'll count that as a retry. */
4017 /* Note that we will only wait forever prior to the start of a packet.
4018 After that, we expect characters to arrive at a brisk pace. They
4019 should show up within remote_timeout intervals. */
4023 c
= readchar (timeout
);
4025 if (c
== SERIAL_TIMEOUT
)
4027 if (forever
) /* Watchdog went off? Kill the target. */
4030 target_mourn_inferior ();
4031 error ("Watchdog has expired. Target detached.\n");
4034 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4040 /* We've found the start of a packet, now collect the data. */
4042 val
= read_frame (buf
, sizeof_buf
);
4048 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4049 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4050 fprintf_unfiltered (gdb_stdlog
, "\n");
4052 SERIAL_WRITE (remote_desc
, "+", 1);
4056 /* Try the whole thing again. */
4058 SERIAL_WRITE (remote_desc
, "-", 1);
4061 /* We have tried hard enough, and just can't receive the packet. Give up. */
4063 printf_unfiltered ("Ignoring packet error, continuing...\n");
4064 SERIAL_WRITE (remote_desc
, "+", 1);
4071 /* For some mysterious reason, wait_for_inferior calls kill instead of
4072 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4076 target_mourn_inferior ();
4080 /* Use catch_errors so the user can quit from gdb even when we aren't on
4081 speaking terms with the remote system. */
4082 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4084 /* Don't wait for it to die. I'm not really sure it matters whether
4085 we do or not. For the existing stubs, kill is a noop. */
4086 target_mourn_inferior ();
4089 /* Async version of remote_kill. */
4091 remote_async_kill (void)
4093 /* Unregister the file descriptor from the event loop. */
4094 if (target_is_async_p ())
4095 SERIAL_ASYNC (remote_desc
, NULL
, 0);
4097 /* For some mysterious reason, wait_for_inferior calls kill instead of
4098 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4102 target_mourn_inferior ();
4106 /* Use catch_errors so the user can quit from gdb even when we aren't on
4107 speaking terms with the remote system. */
4108 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4110 /* Don't wait for it to die. I'm not really sure it matters whether
4111 we do or not. For the existing stubs, kill is a noop. */
4112 target_mourn_inferior ();
4118 remote_mourn_1 (&remote_ops
);
4122 remote_async_mourn (void)
4124 remote_mourn_1 (&remote_async_ops
);
4128 extended_remote_mourn (void)
4130 /* We do _not_ want to mourn the target like this; this will
4131 remove the extended remote target from the target stack,
4132 and the next time the user says "run" it'll fail.
4134 FIXME: What is the right thing to do here? */
4136 remote_mourn_1 (&extended_remote_ops
);
4140 /* Worker function for remote_mourn. */
4142 remote_mourn_1 (struct target_ops
*target
)
4144 unpush_target (target
);
4145 generic_mourn_inferior ();
4148 /* In the extended protocol we want to be able to do things like
4149 "run" and have them basically work as expected. So we need
4150 a special create_inferior function.
4152 FIXME: One day add support for changing the exec file
4153 we're debugging, arguments and an environment. */
4156 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4158 /* Rip out the breakpoints; we'll reinsert them after restarting
4159 the remote server. */
4160 remove_breakpoints ();
4162 /* Now restart the remote server. */
4163 extended_remote_restart ();
4165 /* Now put the breakpoints back in. This way we're safe if the
4166 restart function works via a unix fork on the remote side. */
4167 insert_breakpoints ();
4169 /* Clean up from the last time we were running. */
4170 clear_proceed_status ();
4172 /* Let the remote process run. */
4173 proceed (-1, TARGET_SIGNAL_0
, 0);
4176 /* Async version of extended_remote_create_inferior. */
4178 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4180 /* Rip out the breakpoints; we'll reinsert them after restarting
4181 the remote server. */
4182 remove_breakpoints ();
4184 /* If running asynchronously, register the target file descriptor
4185 with the event loop. */
4186 if (event_loop_p
&& target_can_async_p ())
4187 target_async (inferior_event_handler
, 0);
4189 /* Now restart the remote server. */
4190 extended_remote_restart ();
4192 /* Now put the breakpoints back in. This way we're safe if the
4193 restart function works via a unix fork on the remote side. */
4194 insert_breakpoints ();
4196 /* Clean up from the last time we were running. */
4197 clear_proceed_status ();
4199 /* Let the remote process run. */
4200 proceed (-1, TARGET_SIGNAL_0
, 0);
4204 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4205 than other targets; in those use REMOTE_BREAKPOINT instead of just
4206 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4207 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4208 the standard routines that are in mem-break.c. */
4210 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4211 the choice of breakpoint instruction affects target program design and
4212 vice versa, and by making it user-tweakable, the special code here
4213 goes away and we need fewer special GDB configurations. */
4215 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4216 #define REMOTE_BREAKPOINT
4219 #ifdef REMOTE_BREAKPOINT
4221 /* If the target isn't bi-endian, just pretend it is. */
4222 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4223 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4224 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4227 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
4228 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
4230 #endif /* REMOTE_BREAKPOINT */
4232 /* Insert a breakpoint on targets that don't have any better breakpoint
4233 support. We read the contents of the target location and stash it,
4234 then overwrite it with a breakpoint instruction. ADDR is the target
4235 location in the target machine. CONTENTS_CACHE is a pointer to
4236 memory allocated for saving the target contents. It is guaranteed
4237 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4238 is accomplished via BREAKPOINT_MAX). */
4241 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4243 #ifdef REMOTE_BREAKPOINT
4248 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4249 If it succeeds, then set the support to PACKET_ENABLE. If it
4250 fails, and the user has explicitly requested the Z support then
4251 report an error, otherwise, mark it disabled and go on. */
4253 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4255 char *buf
= alloca (PBUFSIZ
);
4258 addr
= remote_address_masked (addr
);
4262 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4263 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4264 sprintf (p
, ",%d", bp_size
);
4267 getpkt (buf
, PBUFSIZ
, 0);
4269 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4275 case PACKET_UNKNOWN
:
4280 #ifdef REMOTE_BREAKPOINT
4281 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4285 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
4286 val
= target_write_memory (addr
, (char *) big_break_insn
,
4287 sizeof big_break_insn
);
4289 val
= target_write_memory (addr
, (char *) little_break_insn
,
4290 sizeof little_break_insn
);
4295 return memory_insert_breakpoint (addr
, contents_cache
);
4296 #endif /* REMOTE_BREAKPOINT */
4300 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4304 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4306 char *buf
= alloca (PBUFSIZ
);
4313 addr
= remote_address_masked (addr
);
4314 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4315 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4316 sprintf (p
, ",%d", bp_size
);
4319 getpkt (buf
, PBUFSIZ
, 0);
4321 return (buf
[0] == 'E');
4324 #ifdef REMOTE_BREAKPOINT
4325 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4327 return memory_remove_breakpoint (addr
, contents_cache
);
4328 #endif /* REMOTE_BREAKPOINT */
4332 watchpoint_to_Z_packet (int type
)
4346 internal_error (__FILE__
, __LINE__
,
4347 "hw_bp_to_z: bad watchpoint type %d", type
);
4351 /* FIXME: This function should be static and a member of the remote
4355 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4357 char *buf
= alloca (PBUFSIZ
);
4359 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4361 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4362 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4363 remote_protocol_Z
[packet
].name
,
4364 remote_protocol_Z
[packet
].title
);
4366 sprintf (buf
, "Z%x,", packet
);
4367 p
= strchr (buf
, '\0');
4368 addr
= remote_address_masked (addr
);
4369 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4370 sprintf (p
, ",%x", len
);
4373 getpkt (buf
, PBUFSIZ
, 0);
4375 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4378 case PACKET_UNKNOWN
:
4383 internal_error (__FILE__
, __LINE__
,
4384 "remote_insert_watchpoint: reached end of function");
4387 /* FIXME: This function should be static and a member of the remote
4391 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4393 char *buf
= alloca (PBUFSIZ
);
4395 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4397 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4398 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4399 remote_protocol_Z
[packet
].name
,
4400 remote_protocol_Z
[packet
].title
);
4402 sprintf (buf
, "z%x,", packet
);
4403 p
= strchr (buf
, '\0');
4404 addr
= remote_address_masked (addr
);
4405 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4406 sprintf (p
, ",%x", len
);
4408 getpkt (buf
, PBUFSIZ
, 0);
4410 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4413 case PACKET_UNKNOWN
:
4418 internal_error (__FILE__
, __LINE__
,
4419 "remote_remove_watchpoint: reached end of function");
4422 /* FIXME: This function should be static and a member of the remote
4426 remote_insert_hw_breakpoint (CORE_ADDR addr
, int len
)
4428 char *buf
= alloca (PBUFSIZ
);
4431 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4432 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4433 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4434 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4440 addr
= remote_address_masked (addr
);
4441 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4442 sprintf (p
, ",%x", len
);
4445 getpkt (buf
, PBUFSIZ
, 0);
4447 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4450 case PACKET_UNKNOWN
:
4455 internal_error (__FILE__
, __LINE__
,
4456 "remote_remove_watchpoint: reached end of function");
4459 /* FIXME: This function should be static and a member of the remote
4463 remote_remove_hw_breakpoint (CORE_ADDR addr
, int len
)
4465 char *buf
= alloca (PBUFSIZ
);
4468 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4469 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4470 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4471 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4477 addr
= remote_address_masked (addr
);
4478 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4479 sprintf (p
, ",%x", len
);
4482 getpkt (buf
, PBUFSIZ
, 0);
4484 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4487 case PACKET_UNKNOWN
:
4492 internal_error (__FILE__
, __LINE__
,
4493 "remote_remove_watchpoint: reached end of function");
4496 /* Some targets are only capable of doing downloads, and afterwards
4497 they switch to the remote serial protocol. This function provides
4498 a clean way to get from the download target to the remote target.
4499 It's basically just a wrapper so that we don't have to expose any
4500 of the internal workings of remote.c.
4502 Prior to calling this routine, you should shutdown the current
4503 target code, else you will get the "A program is being debugged
4504 already..." message. Usually a call to pop_target() suffices. */
4507 push_remote_target (char *name
, int from_tty
)
4509 printf_filtered ("Switching to remote protocol\n");
4510 remote_open (name
, from_tty
);
4513 /* Other targets want to use the entire remote serial module but with
4514 certain remote_ops overridden. */
4517 open_remote_target (char *name
, int from_tty
, struct target_ops
*target
,
4520 printf_filtered ("Selecting the %sremote protocol\n",
4521 (extended_p
? "extended-" : ""));
4522 remote_open_1 (name
, from_tty
, target
, extended_p
);
4525 /* Table used by the crc32 function to calcuate the checksum. */
4527 static unsigned long crc32_table
[256] =
4530 static unsigned long
4531 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4533 if (!crc32_table
[1])
4535 /* Initialize the CRC table and the decoding table. */
4539 for (i
= 0; i
< 256; i
++)
4541 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4542 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4549 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4555 /* compare-sections command
4557 With no arguments, compares each loadable section in the exec bfd
4558 with the same memory range on the target, and reports mismatches.
4559 Useful for verifying the image on the target against the exec file.
4560 Depends on the target understanding the new "qCRC:" request. */
4562 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4563 target method (target verify memory) and generic version of the
4564 actual command. This will allow other high-level code (especially
4565 generic_load()) to make use of this target functionality. */
4568 compare_sections_command (char *args
, int from_tty
)
4571 unsigned long host_crc
, target_crc
;
4572 extern bfd
*exec_bfd
;
4573 struct cleanup
*old_chain
;
4576 const char *sectname
;
4577 char *buf
= alloca (PBUFSIZ
);
4584 error ("command cannot be used without an exec file");
4585 if (!current_target
.to_shortname
||
4586 strcmp (current_target
.to_shortname
, "remote") != 0)
4587 error ("command can only be used with remote target");
4589 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4591 if (!(s
->flags
& SEC_LOAD
))
4592 continue; /* skip non-loadable section */
4594 size
= bfd_get_section_size_before_reloc (s
);
4596 continue; /* skip zero-length section */
4598 sectname
= bfd_get_section_name (exec_bfd
, s
);
4599 if (args
&& strcmp (args
, sectname
) != 0)
4600 continue; /* not the section selected by user */
4602 matched
= 1; /* do this section */
4604 /* FIXME: assumes lma can fit into long */
4605 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
4608 /* be clever; compute the host_crc before waiting for target reply */
4609 sectdata
= xmalloc (size
);
4610 old_chain
= make_cleanup (xfree
, sectdata
);
4611 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4612 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4614 getpkt (buf
, PBUFSIZ
, 0);
4616 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4617 sectname
, lma
, lma
+ size
);
4619 error ("remote target does not support this operation");
4621 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4622 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4624 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4625 sectname
, paddr (lma
), paddr (lma
+ size
));
4626 if (host_crc
== target_crc
)
4627 printf_filtered ("matched.\n");
4630 printf_filtered ("MIS-MATCHED!\n");
4634 do_cleanups (old_chain
);
4637 warning ("One or more sections of the remote executable does not match\n\
4638 the loaded file\n");
4639 if (args
&& !matched
)
4640 printf_filtered ("No loaded section named '%s'.\n", args
);
4644 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
4647 char *buf2
= alloca (PBUFSIZ
);
4648 char *p2
= &buf2
[0];
4651 error ("null pointer to remote bufer size specified");
4653 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4654 the caller know and return what the minimum size is */
4655 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4656 if (*bufsiz
< PBUFSIZ
)
4662 /* except for querying the minimum buffer size, target must be open */
4664 error ("remote query is only available after target open");
4666 /* we only take uppercase letters as query types, at least for now */
4667 if ((query_type
< 'A') || (query_type
> 'Z'))
4668 error ("invalid remote query type");
4671 error ("null remote query specified");
4674 error ("remote query requires a buffer to receive data");
4681 /* we used one buffer char for the remote protocol q command and another
4682 for the query type. As the remote protocol encapsulation uses 4 chars
4683 plus one extra in case we are debugging (remote_debug),
4684 we have PBUFZIZ - 7 left to pack the query string */
4686 while (buf
[i
] && (i
< (PBUFSIZ
- 8)))
4688 /* bad caller may have sent forbidden characters */
4689 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
4690 error ("illegal characters in query string");
4698 error ("query larger than available buffer");
4704 getpkt (outbuf
, *bufsiz
, 0);
4710 remote_rcmd (char *command
,
4711 struct ui_file
*outbuf
)
4714 char *buf
= alloca (PBUFSIZ
);
4718 error ("remote rcmd is only available after target open");
4720 /* Send a NULL command across as an empty command */
4721 if (command
== NULL
)
4724 /* The query prefix */
4725 strcpy (buf
, "qRcmd,");
4726 p
= strchr (buf
, '\0');
4728 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > PBUFSIZ
)
4729 error ("\"monitor\" command ``%s'' is too long\n", command
);
4731 /* Encode the actual command */
4732 for (i
= 0; command
[i
]; i
++)
4734 *p
++ = tohex ((command
[i
] >> 4) & 0xf);
4735 *p
++ = tohex (command
[i
] & 0xf);
4739 if (putpkt (buf
) < 0)
4740 error ("Communication problem with target\n");
4742 /* get/display the response */
4745 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4747 getpkt (buf
, PBUFSIZ
, 0);
4749 error ("Target does not support this command\n");
4750 if (buf
[0] == 'O' && buf
[1] != 'K')
4752 remote_console_output (buf
+ 1); /* 'O' message from stub */
4755 if (strcmp (buf
, "OK") == 0)
4757 if (strlen (buf
) == 3 && buf
[0] == 'E'
4758 && isdigit (buf
[1]) && isdigit (buf
[2]))
4760 error ("Protocol error with Rcmd");
4762 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
4764 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
4765 fputc_unfiltered (c
, outbuf
);
4772 packet_command (char *args
, int from_tty
)
4774 char *buf
= alloca (PBUFSIZ
);
4777 error ("command can only be used with remote target");
4780 error ("remote-packet command requires packet text as argument");
4782 puts_filtered ("sending: ");
4783 print_packet (args
);
4784 puts_filtered ("\n");
4787 getpkt (buf
, PBUFSIZ
, 0);
4788 puts_filtered ("received: ");
4790 puts_filtered ("\n");
4794 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4796 static void display_thread_info (struct gdb_ext_thread_info
*info
);
4798 static void threadset_test_cmd (char *cmd
, int tty
);
4800 static void threadalive_test (char *cmd
, int tty
);
4802 static void threadlist_test_cmd (char *cmd
, int tty
);
4804 int get_and_display_threadinfo (threadref
* ref
);
4806 static void threadinfo_test_cmd (char *cmd
, int tty
);
4808 static int thread_display_step (threadref
* ref
, void *context
);
4810 static void threadlist_update_test_cmd (char *cmd
, int tty
);
4812 static void init_remote_threadtests (void);
4814 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4817 threadset_test_cmd (char *cmd
, int tty
)
4819 int sample_thread
= SAMPLE_THREAD
;
4821 printf_filtered ("Remote threadset test\n");
4822 set_thread (sample_thread
, 1);
4827 threadalive_test (char *cmd
, int tty
)
4829 int sample_thread
= SAMPLE_THREAD
;
4831 if (remote_thread_alive (sample_thread
))
4832 printf_filtered ("PASS: Thread alive test\n");
4834 printf_filtered ("FAIL: Thread alive test\n");
4837 void output_threadid (char *title
, threadref
* ref
);
4840 output_threadid (char *title
, threadref
*ref
)
4844 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
4846 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
4850 threadlist_test_cmd (char *cmd
, int tty
)
4853 threadref nextthread
;
4854 int done
, result_count
;
4855 threadref threadlist
[3];
4857 printf_filtered ("Remote Threadlist test\n");
4858 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
4859 &result_count
, &threadlist
[0]))
4860 printf_filtered ("FAIL: threadlist test\n");
4863 threadref
*scan
= threadlist
;
4864 threadref
*limit
= scan
+ result_count
;
4866 while (scan
< limit
)
4867 output_threadid (" thread ", scan
++);
4872 display_thread_info (struct gdb_ext_thread_info
*info
)
4874 output_threadid ("Threadid: ", &info
->threadid
);
4875 printf_filtered ("Name: %s\n ", info
->shortname
);
4876 printf_filtered ("State: %s\n", info
->display
);
4877 printf_filtered ("other: %s\n\n", info
->more_display
);
4881 get_and_display_threadinfo (threadref
*ref
)
4885 struct gdb_ext_thread_info threadinfo
;
4887 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
4888 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
4889 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
4890 display_thread_info (&threadinfo
);
4895 threadinfo_test_cmd (char *cmd
, int tty
)
4897 int athread
= SAMPLE_THREAD
;
4901 int_to_threadref (&thread
, athread
);
4902 printf_filtered ("Remote Threadinfo test\n");
4903 if (!get_and_display_threadinfo (&thread
))
4904 printf_filtered ("FAIL cannot get thread info\n");
4908 thread_display_step (threadref
*ref
, void *context
)
4910 /* output_threadid(" threadstep ",ref); *//* simple test */
4911 return get_and_display_threadinfo (ref
);
4915 threadlist_update_test_cmd (char *cmd
, int tty
)
4917 printf_filtered ("Remote Threadlist update test\n");
4918 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
4922 init_remote_threadtests (void)
4924 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
4925 "Fetch and print the remote list of thread identifiers, one pkt only");
4926 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
4927 "Fetch and display info about one thread");
4928 add_com ("tset", class_obscure
, threadset_test_cmd
,
4929 "Test setting to a different thread");
4930 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
4931 "Iterate through updating all remote thread info");
4932 add_com ("talive", class_obscure
, threadalive_test
,
4933 " Remote thread alive test ");
4939 init_remote_ops (void)
4941 remote_ops
.to_shortname
= "remote";
4942 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
4944 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4945 Specify the serial device it is connected to\n\
4946 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
4947 remote_ops
.to_open
= remote_open
;
4948 remote_ops
.to_close
= remote_close
;
4949 remote_ops
.to_detach
= remote_detach
;
4950 remote_ops
.to_resume
= remote_resume
;
4951 remote_ops
.to_wait
= remote_wait
;
4952 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
4953 remote_ops
.to_store_registers
= remote_store_registers
;
4954 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
4955 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
4956 remote_ops
.to_files_info
= remote_files_info
;
4957 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
4958 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
4959 remote_ops
.to_kill
= remote_kill
;
4960 remote_ops
.to_load
= generic_load
;
4961 remote_ops
.to_mourn_inferior
= remote_mourn
;
4962 remote_ops
.to_thread_alive
= remote_thread_alive
;
4963 remote_ops
.to_find_new_threads
= remote_threads_info
;
4964 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
4965 remote_ops
.to_stop
= remote_stop
;
4966 remote_ops
.to_query
= remote_query
;
4967 remote_ops
.to_rcmd
= remote_rcmd
;
4968 remote_ops
.to_stratum
= process_stratum
;
4969 remote_ops
.to_has_all_memory
= 1;
4970 remote_ops
.to_has_memory
= 1;
4971 remote_ops
.to_has_stack
= 1;
4972 remote_ops
.to_has_registers
= 1;
4973 remote_ops
.to_has_execution
= 1;
4974 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
4975 remote_ops
.to_magic
= OPS_MAGIC
;
4978 /* Set up the extended remote vector by making a copy of the standard
4979 remote vector and adding to it. */
4982 init_extended_remote_ops (void)
4984 extended_remote_ops
= remote_ops
;
4986 extended_remote_ops
.to_shortname
= "extended-remote";
4987 extended_remote_ops
.to_longname
=
4988 "Extended remote serial target in gdb-specific protocol";
4989 extended_remote_ops
.to_doc
=
4990 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4991 Specify the serial device it is connected to (e.g. /dev/ttya).",
4992 extended_remote_ops
.to_open
= extended_remote_open
;
4993 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
4994 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
4998 * Command: info remote-process
5000 * This implements Cisco's version of the "info proc" command.
5002 * This query allows the target stub to return an arbitrary string
5003 * (or strings) giving arbitrary information about the target process.
5004 * This is optional; the target stub isn't required to implement it.
5006 * Syntax: qfProcessInfo request first string
5007 * qsProcessInfo request subsequent string
5008 * reply: 'O'<hex-encoded-string>
5009 * 'l' last reply (empty)
5013 remote_info_process (char *args
, int from_tty
)
5015 char *buf
= alloca (PBUFSIZ
);
5017 if (remote_desc
== 0)
5018 error ("Command can only be used when connected to the remote target.");
5020 putpkt ("qfProcessInfo");
5021 getpkt (buf
, PBUFSIZ
, 0);
5023 return; /* Silently: target does not support this feature. */
5026 error ("info proc: target error.");
5028 while (buf
[0] == 'O') /* Capitol-O packet */
5030 remote_console_output (&buf
[1]);
5031 putpkt ("qsProcessInfo");
5032 getpkt (buf
, PBUFSIZ
, 0);
5041 remote_cisco_open (char *name
, int from_tty
)
5045 "To open a remote debug connection, you need to specify what \n\
5046 device is attached to the remote system (e.g. host:port).");
5048 /* See FIXME above */
5049 wait_forever_enabled_p
= 1;
5051 target_preopen (from_tty
);
5053 unpush_target (&remote_cisco_ops
);
5055 remote_desc
= SERIAL_OPEN (name
);
5057 perror_with_name (name
);
5060 * If a baud rate was specified on the gdb command line it will
5061 * be greater than the initial value of -1. If it is, use it otherwise
5065 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5066 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
5068 SERIAL_CLOSE (remote_desc
);
5069 perror_with_name (name
);
5072 SERIAL_RAW (remote_desc
);
5074 /* If there is something sitting in the buffer we might take it as a
5075 response to a command, which would be bad. */
5076 SERIAL_FLUSH_INPUT (remote_desc
);
5080 puts_filtered ("Remote debugging using ");
5081 puts_filtered (name
);
5082 puts_filtered ("\n");
5085 remote_cisco_mode
= 1;
5087 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5089 init_all_packet_configs ();
5091 general_thread
= -2;
5092 continue_thread
= -2;
5094 /* Probe for ability to use "ThreadInfo" query, as required. */
5095 use_threadinfo_query
= 1;
5096 use_threadextra_query
= 1;
5098 /* Without this, some commands which require an active target (such
5099 as kill) won't work. This variable serves (at least) double duty
5100 as both the pid of the target process (if it has such), and as a
5101 flag indicating that a target is active. These functions should
5102 be split out into seperate variables, especially since GDB will
5103 someday have a notion of debugging several processes. */
5104 inferior_pid
= MAGIC_NULL_PID
;
5106 /* Start the remote connection; if error (0), discard this target. */
5108 if (!catch_errors (remote_start_remote_dummy
, (char *) 0,
5109 "Couldn't establish connection to remote target\n",
5118 remote_cisco_close (int quitting
)
5120 remote_cisco_mode
= 0;
5121 remote_close (quitting
);
5125 remote_cisco_mourn (void)
5127 remote_mourn_1 (&remote_cisco_ops
);
5139 /* shared between readsocket() and readtty() */
5140 static char *tty_input
;
5142 static int escape_count
;
5143 static int echo_check
;
5144 extern int quit_flag
;
5151 /* Loop until the socket doesn't have any more data */
5153 while ((data
= readchar (0)) >= 0)
5155 /* Check for the escape sequence */
5158 /* If this is the fourth escape, get out */
5159 if (++escape_count
== 4)
5164 { /* This is a '|', but not the fourth in a row.
5165 Continue without echoing it. If it isn't actually
5166 one of four in a row, it'll be echoed later. */
5173 /* Ensure any pending '|'s are flushed. */
5175 for (; escape_count
> 0; escape_count
--)
5179 if (data
== '\r') /* If this is a return character, */
5180 continue; /* - just supress it. */
5182 if (echo_check
!= -1) /* Check for echo of user input. */
5184 if (tty_input
[echo_check
] == data
)
5186 echo_check
++; /* Character matched user input: */
5187 continue; /* Continue without echoing it. */
5189 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5190 { /* End of the line (and of echo checking). */
5191 echo_check
= -1; /* No more echo supression */
5192 continue; /* Continue without echoing. */
5195 { /* Failed check for echo of user input.
5196 We now have some suppressed output to flush! */
5199 for (j
= 0; j
< echo_check
; j
++)
5200 putchar (tty_input
[j
]);
5204 putchar (data
); /* Default case: output the char. */
5207 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5208 return READ_MORE
; /* Try to read some more */
5210 return FATAL_ERROR
; /* Trouble, bail out */
5218 /* First, read a buffer full from the terminal */
5219 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5220 if (tty_bytecount
== -1)
5222 perror ("readtty: read failed");
5226 /* Remove a quoted newline. */
5227 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5228 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5230 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5231 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5234 /* Turn trailing newlines into returns */
5235 if (tty_input
[tty_bytecount
- 1] == '\n')
5236 tty_input
[tty_bytecount
- 1] = '\r';
5238 /* If the line consists of a ~, enter debugging mode. */
5239 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5242 /* Make this a zero terminated string and write it out */
5243 tty_input
[tty_bytecount
] = 0;
5244 if (SERIAL_WRITE (remote_desc
, tty_input
, tty_bytecount
))
5246 perror_with_name ("readtty: write failed");
5256 fd_set input
; /* file descriptors for select */
5257 int tablesize
; /* max number of FDs for select */
5261 extern int escape_count
; /* global shared by readsocket */
5262 extern int echo_check
; /* ditto */
5267 tablesize
= 8 * sizeof (input
);
5271 /* Check for anything from our socket - doesn't block. Note that
5272 this must be done *before* the select as there may be
5273 buffered I/O waiting to be processed. */
5275 if ((status
= readsocket ()) == FATAL_ERROR
)
5277 error ("Debugging terminated by communications error");
5279 else if (status
!= READ_MORE
)
5284 fflush (stdout
); /* Flush output before blocking */
5286 /* Now block on more socket input or TTY input */
5289 FD_SET (fileno (stdin
), &input
);
5290 FD_SET (DEPRECATED_SERIAL_FD (remote_desc
), &input
);
5292 status
= select (tablesize
, &input
, 0, 0, 0);
5293 if ((status
== -1) && (errno
!= EINTR
))
5295 error ("Communications error on select %d", errno
);
5298 /* Handle Control-C typed */
5302 if ((++quit_count
) == 2)
5304 if (query ("Interrupt GDB? "))
5306 printf_filtered ("Interrupted by user.\n");
5307 return_to_top_level (RETURN_QUIT
);
5314 SERIAL_SEND_BREAK (remote_desc
);
5316 SERIAL_WRITE (remote_desc
, "\003", 1);
5321 /* Handle console input */
5323 if (FD_ISSET (fileno (stdin
), &input
))
5327 status
= readtty ();
5328 if (status
== READ_MORE
)
5331 return status
; /* telnet session ended */
5337 remote_cisco_wait (int pid
, struct target_waitstatus
*status
)
5339 if (minitelnet () != ENTER_DEBUG
)
5341 error ("Debugging session terminated by protocol error");
5344 return remote_wait (pid
, status
);
5348 init_remote_cisco_ops (void)
5350 remote_cisco_ops
.to_shortname
= "cisco";
5351 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5352 remote_cisco_ops
.to_doc
=
5353 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5354 Specify the serial device it is connected to (e.g. host:2020).";
5355 remote_cisco_ops
.to_open
= remote_cisco_open
;
5356 remote_cisco_ops
.to_close
= remote_cisco_close
;
5357 remote_cisco_ops
.to_detach
= remote_detach
;
5358 remote_cisco_ops
.to_resume
= remote_resume
;
5359 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5360 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5361 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5362 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5363 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5364 remote_cisco_ops
.to_files_info
= remote_files_info
;
5365 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5366 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5367 remote_cisco_ops
.to_kill
= remote_kill
;
5368 remote_cisco_ops
.to_load
= generic_load
;
5369 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5370 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5371 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5372 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5373 remote_cisco_ops
.to_stratum
= process_stratum
;
5374 remote_cisco_ops
.to_has_all_memory
= 1;
5375 remote_cisco_ops
.to_has_memory
= 1;
5376 remote_cisco_ops
.to_has_stack
= 1;
5377 remote_cisco_ops
.to_has_registers
= 1;
5378 remote_cisco_ops
.to_has_execution
= 1;
5379 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5383 remote_can_async_p (void)
5385 /* We're async whenever the serial device is. */
5386 return (current_target
.to_async_mask_value
) && SERIAL_CAN_ASYNC_P (remote_desc
);
5390 remote_is_async_p (void)
5392 /* We're async whenever the serial device is. */
5393 return (current_target
.to_async_mask_value
) && SERIAL_IS_ASYNC_P (remote_desc
);
5396 /* Pass the SERIAL event on and up to the client. One day this code
5397 will be able to delay notifying the client of an event until the
5398 point where an entire packet has been received. */
5400 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5401 static void *async_client_context
;
5402 static serial_event_ftype remote_async_serial_handler
;
5405 remote_async_serial_handler (serial_t scb
, void *context
)
5407 /* Don't propogate error information up to the client. Instead let
5408 the client find out about the error by querying the target. */
5409 async_client_callback (INF_REG_EVENT
, async_client_context
);
5413 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5415 if (current_target
.to_async_mask_value
== 0)
5416 internal_error (__FILE__
, __LINE__
,
5417 "Calling remote_async when async is masked");
5419 if (callback
!= NULL
)
5421 SERIAL_ASYNC (remote_desc
, remote_async_serial_handler
, NULL
);
5422 async_client_callback
= callback
;
5423 async_client_context
= context
;
5426 SERIAL_ASYNC (remote_desc
, NULL
, NULL
);
5429 /* Target async and target extended-async.
5431 This are temporary targets, until it is all tested. Eventually
5432 async support will be incorporated int the usual 'remote'
5436 init_remote_async_ops (void)
5438 remote_async_ops
.to_shortname
= "async";
5439 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5440 remote_async_ops
.to_doc
=
5441 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5442 Specify the serial device it is connected to (e.g. /dev/ttya).";
5443 remote_async_ops
.to_open
= remote_async_open
;
5444 remote_async_ops
.to_close
= remote_close
;
5445 remote_async_ops
.to_detach
= remote_async_detach
;
5446 remote_async_ops
.to_resume
= remote_async_resume
;
5447 remote_async_ops
.to_wait
= remote_async_wait
;
5448 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5449 remote_async_ops
.to_store_registers
= remote_store_registers
;
5450 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5451 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5452 remote_async_ops
.to_files_info
= remote_files_info
;
5453 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5454 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5455 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5456 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5457 remote_async_ops
.to_kill
= remote_async_kill
;
5458 remote_async_ops
.to_load
= generic_load
;
5459 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5460 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5461 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5462 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5463 remote_async_ops
.to_stop
= remote_stop
;
5464 remote_async_ops
.to_query
= remote_query
;
5465 remote_async_ops
.to_rcmd
= remote_rcmd
;
5466 remote_async_ops
.to_stratum
= process_stratum
;
5467 remote_async_ops
.to_has_all_memory
= 1;
5468 remote_async_ops
.to_has_memory
= 1;
5469 remote_async_ops
.to_has_stack
= 1;
5470 remote_async_ops
.to_has_registers
= 1;
5471 remote_async_ops
.to_has_execution
= 1;
5472 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5473 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5474 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5475 remote_async_ops
.to_async
= remote_async
;
5476 remote_async_ops
.to_async_mask_value
= 1;
5477 remote_async_ops
.to_magic
= OPS_MAGIC
;
5480 /* Set up the async extended remote vector by making a copy of the standard
5481 remote vector and adding to it. */
5484 init_extended_async_remote_ops (void)
5486 extended_async_remote_ops
= remote_async_ops
;
5488 extended_async_remote_ops
.to_shortname
= "extended-async";
5489 extended_async_remote_ops
.to_longname
=
5490 "Extended remote serial target in async gdb-specific protocol";
5491 extended_async_remote_ops
.to_doc
=
5492 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5493 Specify the serial device it is connected to (e.g. /dev/ttya).",
5494 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5495 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5496 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5500 set_remote_cmd (char *args
, int from_tty
)
5506 show_remote_cmd (char *args
, int from_tty
)
5508 show_remote_protocol_Z_packet_cmd (args
, from_tty
);
5509 show_remote_protocol_P_packet_cmd (args
, from_tty
);
5510 show_remote_protocol_binary_download_cmd (args
, from_tty
);
5514 build_remote_gdbarch_data (void)
5516 build_remote_packet_sizes ();
5519 tty_input
= xmalloc (PBUFSIZ
);
5520 remote_address_size
= TARGET_ADDR_BIT
;
5524 _initialize_remote (void)
5526 static struct cmd_list_element
*remote_set_cmdlist
;
5527 static struct cmd_list_element
*remote_show_cmdlist
;
5528 struct cmd_list_element
*tmpcmd
;
5530 /* architecture specific data */
5531 build_remote_gdbarch_data ();
5532 register_gdbarch_swap (&tty_input
, sizeof (&tty_input
), NULL
);
5533 register_remote_packet_sizes ();
5534 register_gdbarch_swap (&remote_address_size
,
5535 sizeof (&remote_address_size
), NULL
);
5536 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5539 add_target (&remote_ops
);
5541 init_extended_remote_ops ();
5542 add_target (&extended_remote_ops
);
5544 init_remote_async_ops ();
5545 add_target (&remote_async_ops
);
5547 init_extended_async_remote_ops ();
5548 add_target (&extended_async_remote_ops
);
5550 init_remote_cisco_ops ();
5551 add_target (&remote_cisco_ops
);
5554 init_remote_threadtests ();
5557 /* set/show remote ... */
5559 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5560 Remote protocol specific variables\n\
5561 Configure various remote-protocol specific variables such as\n\
5562 the packets being used",
5563 &remote_set_cmdlist
, "set remote ",
5564 0/*allow-unknown*/, &setlist
);
5565 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
5566 Remote protocol specific variables\n\
5567 Configure various remote-protocol specific variables such as\n\
5568 the packets being used",
5569 &remote_show_cmdlist
, "show remote ",
5570 0/*allow-unknown*/, &showlist
);
5572 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
5573 "Compare section data on target to the exec file.\n\
5574 Argument is a single section name (default: all loaded sections).",
5577 add_cmd ("packet", class_maintenance
, packet_command
,
5578 "Send an arbitrary packet to a remote target.\n\
5579 maintenance packet TEXT\n\
5580 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5581 this command sends the string TEXT to the inferior, and displays the\n\
5582 response packet. GDB supplies the initial `$' character, and the\n\
5583 terminating `#' character and checksum.",
5587 (add_set_cmd ("remotebreak", no_class
,
5588 var_boolean
, (char *) &remote_break
,
5589 "Set whether to send break if interrupted.\n",
5593 /* Install commands for configuring memory read/write packets. */
5595 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
5596 "Set the maximum number of bytes per memory write packet (deprecated).\n",
5598 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
5599 "Show the maximum number of bytes per memory write packet (deprecated).\n",
5601 add_cmd ("memory-write-packet-size", no_class
,
5602 set_memory_write_packet_size
,
5603 "Set the maximum number of bytes per memory-write packet.\n"
5604 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5605 "default packet size. The actual limit is further reduced\n"
5606 "dependent on the target. Specify ``fixed'' to disable the\n"
5607 "further restriction and ``limit'' to enable that restriction\n",
5608 &remote_set_cmdlist
);
5609 add_cmd ("memory-read-packet-size", no_class
,
5610 set_memory_read_packet_size
,
5611 "Set the maximum number of bytes per memory-read packet.\n"
5612 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5613 "default packet size. The actual limit is further reduced\n"
5614 "dependent on the target. Specify ``fixed'' to disable the\n"
5615 "further restriction and ``limit'' to enable that restriction\n",
5616 &remote_set_cmdlist
);
5617 add_cmd ("memory-write-packet-size", no_class
,
5618 show_memory_write_packet_size
,
5619 "Show the maximum number of bytes per memory-write packet.\n",
5620 &remote_show_cmdlist
);
5621 add_cmd ("memory-read-packet-size", no_class
,
5622 show_memory_read_packet_size
,
5623 "Show the maximum number of bytes per memory-read packet.\n",
5624 &remote_show_cmdlist
);
5627 (add_set_cmd ("remoteaddresssize", class_obscure
,
5628 var_integer
, (char *) &remote_address_size
,
5629 "Set the maximum size of the address (in bits) \
5630 in a memory packet.\n",
5634 add_packet_config_cmd (&remote_protocol_binary_download
,
5635 "X", "binary-download",
5636 set_remote_protocol_binary_download_cmd
,
5637 show_remote_protocol_binary_download_cmd
,
5638 &remote_set_cmdlist
, &remote_show_cmdlist
,
5641 /* XXXX - should ``set remotebinarydownload'' be retained for
5644 (add_set_cmd ("remotebinarydownload", no_class
,
5645 var_boolean
, (char *) &remote_binary_download
,
5646 "Set binary downloads.\n", &setlist
),
5650 add_info ("remote-process", remote_info_process
,
5651 "Query the remote system for process info.");
5653 add_packet_config_cmd (&remote_protocol_P
,
5654 "P", "set-register",
5655 set_remote_protocol_P_packet_cmd
,
5656 show_remote_protocol_P_packet_cmd
,
5657 &remote_set_cmdlist
, &remote_show_cmdlist
,
5660 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
5661 "Z0", "software-breakpoint",
5662 set_remote_protocol_Z_software_bp_packet_cmd
,
5663 show_remote_protocol_Z_software_bp_packet_cmd
,
5664 &remote_set_cmdlist
, &remote_show_cmdlist
,
5667 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
5668 "Z1", "hardware-breakpoint",
5669 set_remote_protocol_Z_hardware_bp_packet_cmd
,
5670 show_remote_protocol_Z_hardware_bp_packet_cmd
,
5671 &remote_set_cmdlist
, &remote_show_cmdlist
,
5674 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
5675 "Z2", "write-watchpoint",
5676 set_remote_protocol_Z_write_wp_packet_cmd
,
5677 show_remote_protocol_Z_write_wp_packet_cmd
,
5678 &remote_set_cmdlist
, &remote_show_cmdlist
,
5681 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
5682 "Z3", "read-watchpoint",
5683 set_remote_protocol_Z_read_wp_packet_cmd
,
5684 show_remote_protocol_Z_read_wp_packet_cmd
,
5685 &remote_set_cmdlist
, &remote_show_cmdlist
,
5688 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
5689 "Z4", "access-watchpoint",
5690 set_remote_protocol_Z_access_wp_packet_cmd
,
5691 show_remote_protocol_Z_access_wp_packet_cmd
,
5692 &remote_set_cmdlist
, &remote_show_cmdlist
,
5695 /* Keep the old ``set remote Z-packet ...'' working. */
5696 tmpcmd
= add_set_auto_boolean_cmd ("Z-packet", class_obscure
,
5697 &remote_Z_packet_detect
,
5699 Set use of remote protocol `Z' packets", &remote_set_cmdlist
);
5700 tmpcmd
->function
.sfunc
= set_remote_protocol_Z_packet_cmd
;
5701 add_cmd ("Z-packet", class_obscure
, show_remote_protocol_Z_packet_cmd
,
5702 "Show use of remote protocol `Z' packets ",
5703 &remote_show_cmdlist
);