Create new file regcache.h. Update all uses.
[deliverable/binutils-gdb.git] / gdb / remote.c
1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 1991-2000, 2001 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /* See the GDB User Guide for details of the GDB remote protocol. */
22
23 #include "defs.h"
24 #include "gdb_string.h"
25 #include <ctype.h>
26 #include <fcntl.h>
27 #include "frame.h"
28 #include "inferior.h"
29 #include "bfd.h"
30 #include "symfile.h"
31 #include "target.h"
32 /*#include "terminal.h" */
33 #include "gdbcmd.h"
34 #include "objfiles.h"
35 #include "gdb-stabs.h"
36 #include "gdbthread.h"
37 #include "remote.h"
38 #include "regcache.h"
39
40 #include <ctype.h>
41 #include <sys/time.h>
42 #ifdef USG
43 #include <sys/types.h>
44 #endif
45
46 #include "event-loop.h"
47 #include "event-top.h"
48 #include "inf-loop.h"
49
50 #include <signal.h>
51 #include "serial.h"
52
53 /* Prototypes for local functions */
54 static void cleanup_sigint_signal_handler (void *dummy);
55 static void initialize_sigint_signal_handler (void);
56 static int getpkt_sane (char *buf, long sizeof_buf, int forever);
57
58 static void handle_remote_sigint (int);
59 static void handle_remote_sigint_twice (int);
60 static void async_remote_interrupt (gdb_client_data);
61 void async_remote_interrupt_twice (gdb_client_data);
62
63 static void build_remote_gdbarch_data (void);
64
65 static int remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len);
66
67 static int remote_read_bytes (CORE_ADDR memaddr, char *myaddr, int len);
68
69 static void remote_files_info (struct target_ops *ignore);
70
71 static int remote_xfer_memory (CORE_ADDR memaddr, char *myaddr,
72 int len, int should_write,
73 struct mem_attrib *attrib,
74 struct target_ops *target);
75
76 static void remote_prepare_to_store (void);
77
78 static void remote_fetch_registers (int regno);
79
80 static void remote_resume (int pid, int step, enum target_signal siggnal);
81 static void remote_async_resume (int pid, int step,
82 enum target_signal siggnal);
83 static int remote_start_remote (PTR);
84
85 static void remote_open (char *name, int from_tty);
86 static void remote_async_open (char *name, int from_tty);
87
88 static void extended_remote_open (char *name, int from_tty);
89 static void extended_remote_async_open (char *name, int from_tty);
90
91 static void remote_open_1 (char *, int, struct target_ops *, int extended_p);
92 static void remote_async_open_1 (char *, int, struct target_ops *,
93 int extended_p);
94
95 static void remote_close (int quitting);
96
97 static void remote_store_registers (int regno);
98
99 static void remote_mourn (void);
100 static void remote_async_mourn (void);
101
102 static void extended_remote_restart (void);
103
104 static void extended_remote_mourn (void);
105
106 static void extended_remote_create_inferior (char *, char *, char **);
107 static void extended_remote_async_create_inferior (char *, char *, char **);
108
109 static void remote_mourn_1 (struct target_ops *);
110
111 static void remote_send (char *buf, long sizeof_buf);
112
113 static int readchar (int timeout);
114
115 static int remote_wait (int pid, struct target_waitstatus *status);
116 static int remote_async_wait (int pid, struct target_waitstatus *status);
117
118 static void remote_kill (void);
119 static void remote_async_kill (void);
120
121 static int tohex (int nib);
122
123 static void remote_detach (char *args, int from_tty);
124 static void remote_async_detach (char *args, int from_tty);
125
126 static void remote_interrupt (int signo);
127
128 static void remote_interrupt_twice (int signo);
129
130 static void interrupt_query (void);
131
132 static void set_thread (int, int);
133
134 static int remote_thread_alive (int);
135
136 static void get_offsets (void);
137
138 static long read_frame (char *buf, long sizeof_buf);
139
140 static int remote_insert_breakpoint (CORE_ADDR, char *);
141
142 static int remote_remove_breakpoint (CORE_ADDR, char *);
143
144 static int hexnumlen (ULONGEST num);
145
146 static void init_remote_ops (void);
147
148 static void init_extended_remote_ops (void);
149
150 static void init_remote_cisco_ops (void);
151
152 static struct target_ops remote_cisco_ops;
153
154 static void remote_stop (void);
155
156 static int ishex (int ch, int *val);
157
158 static int stubhex (int ch);
159
160 static int remote_query (int /*char */ , char *, char *, int *);
161
162 static int hexnumstr (char *, ULONGEST);
163
164 static int hexnumnstr (char *, ULONGEST, int);
165
166 static CORE_ADDR remote_address_masked (CORE_ADDR);
167
168 static void print_packet (char *);
169
170 static unsigned long crc32 (unsigned char *, int, unsigned int);
171
172 static void compare_sections_command (char *, int);
173
174 static void packet_command (char *, int);
175
176 static int stub_unpack_int (char *buff, int fieldlength);
177
178 static int remote_current_thread (int oldpid);
179
180 static void remote_find_new_threads (void);
181
182 static void record_currthread (int currthread);
183
184 /* exported functions */
185
186 extern int fromhex (int a);
187
188 static int putpkt_binary (char *buf, int cnt);
189
190 static void check_binary_download (CORE_ADDR addr);
191
192 struct packet_config;
193
194 static void show_packet_config_cmd (struct packet_config *config);
195
196 static void update_packet_config (struct packet_config *config);
197
198 /* Define the target subroutine names */
199
200 void open_remote_target (char *, int, struct target_ops *, int);
201
202 void _initialize_remote (void);
203
204 /* */
205
206 static struct target_ops remote_ops;
207
208 static struct target_ops extended_remote_ops;
209
210 /* Temporary target ops. Just like the remote_ops and
211 extended_remote_ops, but with asynchronous support. */
212 static struct target_ops remote_async_ops;
213
214 static struct target_ops extended_async_remote_ops;
215
216 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
217 ``forever'' still use the normal timeout mechanism. This is
218 currently used by the ASYNC code to guarentee that target reads
219 during the initial connect always time-out. Once getpkt has been
220 modified to return a timeout indication and, in turn
221 remote_wait()/wait_for_inferior() have gained a timeout parameter
222 this can go away. */
223 static int wait_forever_enabled_p = 1;
224
225
226 /* This variable chooses whether to send a ^C or a break when the user
227 requests program interruption. Although ^C is usually what remote
228 systems expect, and that is the default here, sometimes a break is
229 preferable instead. */
230
231 static int remote_break;
232
233 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
234 remote_open knows that we don't have a file open when the program
235 starts. */
236 static serial_t remote_desc = NULL;
237
238 /* This is set by the target (thru the 'S' message)
239 to denote that the target is in kernel mode. */
240 static int cisco_kernel_mode = 0;
241
242 /* This variable sets the number of bits in an address that are to be
243 sent in a memory ("M" or "m") packet. Normally, after stripping
244 leading zeros, the entire address would be sent. This variable
245 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
246 initial implementation of remote.c restricted the address sent in
247 memory packets to ``host::sizeof long'' bytes - (typically 32
248 bits). Consequently, for 64 bit targets, the upper 32 bits of an
249 address was never sent. Since fixing this bug may cause a break in
250 some remote targets this variable is principly provided to
251 facilitate backward compatibility. */
252
253 static int remote_address_size;
254
255 /* Tempoary to track who currently owns the terminal. See
256 target_async_terminal_* for more details. */
257
258 static int remote_async_terminal_ours_p;
259
260 \f
261 /* This is the size (in chars) of the first response to the ``g''
262 packet. It is used as a heuristic when determining the maximum
263 size of memory-read and memory-write packets. A target will
264 typically only reserve a buffer large enough to hold the ``g''
265 packet. The size does not include packet overhead (headers and
266 trailers). */
267
268 static long actual_register_packet_size;
269
270 /* This is the maximum size (in chars) of a non read/write packet. It
271 is also used as a cap on the size of read/write packets. */
272
273 static long remote_packet_size;
274 /* compatibility. */
275 #define PBUFSIZ (remote_packet_size)
276
277 /* User configurable variables for the number of characters in a
278 memory read/write packet. MIN (PBUFSIZ, g-packet-size) is the
279 default. Some targets need smaller values (fifo overruns, et.al.)
280 and some users need larger values (speed up transfers). The
281 variables ``preferred_*'' (the user request), ``current_*'' (what
282 was actually set) and ``forced_*'' (Positive - a soft limit,
283 negative - a hard limit). */
284
285 struct memory_packet_config
286 {
287 char *name;
288 long size;
289 int fixed_p;
290 };
291
292 /* Compute the current size of a read/write packet. Since this makes
293 use of ``actual_register_packet_size'' the computation is dynamic. */
294
295 static long
296 get_memory_packet_size (struct memory_packet_config *config)
297 {
298 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
299 law?) that some hosts don't cope very well with large alloca()
300 calls. Eventually the alloca() code will be replaced by calls to
301 xmalloc() and make_cleanups() allowing this restriction to either
302 be lifted or removed. */
303 #ifndef MAX_REMOTE_PACKET_SIZE
304 #define MAX_REMOTE_PACKET_SIZE 16384
305 #endif
306 /* NOTE: 16 is just chosen at random. */
307 #ifndef MIN_REMOTE_PACKET_SIZE
308 #define MIN_REMOTE_PACKET_SIZE 16
309 #endif
310 long what_they_get;
311 if (config->fixed_p)
312 {
313 if (config->size <= 0)
314 what_they_get = MAX_REMOTE_PACKET_SIZE;
315 else
316 what_they_get = config->size;
317 }
318 else
319 {
320 what_they_get = remote_packet_size;
321 /* Limit the packet to the size specified by the user. */
322 if (config->size > 0
323 && what_they_get > config->size)
324 what_they_get = config->size;
325 /* Limit it to the size of the targets ``g'' response. */
326 if (actual_register_packet_size > 0
327 && what_they_get > actual_register_packet_size)
328 what_they_get = actual_register_packet_size;
329 }
330 if (what_they_get > MAX_REMOTE_PACKET_SIZE)
331 what_they_get = MAX_REMOTE_PACKET_SIZE;
332 if (what_they_get < MIN_REMOTE_PACKET_SIZE)
333 what_they_get = MIN_REMOTE_PACKET_SIZE;
334 return what_they_get;
335 }
336
337 /* Update the size of a read/write packet. If they user wants
338 something really big then do a sanity check. */
339
340 static void
341 set_memory_packet_size (char *args, struct memory_packet_config *config)
342 {
343 int fixed_p = config->fixed_p;
344 long size = config->size;
345 if (args == NULL)
346 error ("Argument required (integer, `fixed' or `limited').");
347 else if (strcmp (args, "hard") == 0
348 || strcmp (args, "fixed") == 0)
349 fixed_p = 1;
350 else if (strcmp (args, "soft") == 0
351 || strcmp (args, "limit") == 0)
352 fixed_p = 0;
353 else
354 {
355 char *end;
356 size = strtoul (args, &end, 0);
357 if (args == end)
358 error ("Invalid %s (bad syntax).", config->name);
359 #if 0
360 /* Instead of explicitly capping the size of a packet to
361 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
362 instead allowed to set the size to something arbitrarily
363 large. */
364 if (size > MAX_REMOTE_PACKET_SIZE)
365 error ("Invalid %s (too large).", config->name);
366 #endif
367 }
368 /* Extra checks? */
369 if (fixed_p && !config->fixed_p)
370 {
371 if (! query ("The target may not be able to correctly handle a %s\n"
372 "of %ld bytes. Change the packet size? ",
373 config->name, size))
374 error ("Packet size not changed.");
375 }
376 /* Update the config. */
377 config->fixed_p = fixed_p;
378 config->size = size;
379 }
380
381 static void
382 show_memory_packet_size (struct memory_packet_config *config)
383 {
384 printf_filtered ("The %s is %ld. ", config->name, config->size);
385 if (config->fixed_p)
386 printf_filtered ("Packets are fixed at %ld bytes.\n",
387 get_memory_packet_size (config));
388 else
389 printf_filtered ("Packets are limited to %ld bytes.\n",
390 get_memory_packet_size (config));
391 }
392
393 static struct memory_packet_config memory_write_packet_config =
394 {
395 "memory-write-packet-size",
396 };
397
398 static void
399 set_memory_write_packet_size (char *args, int from_tty)
400 {
401 set_memory_packet_size (args, &memory_write_packet_config);
402 }
403
404 static void
405 show_memory_write_packet_size (char *args, int from_tty)
406 {
407 show_memory_packet_size (&memory_write_packet_config);
408 }
409
410 static long
411 get_memory_write_packet_size (void)
412 {
413 return get_memory_packet_size (&memory_write_packet_config);
414 }
415
416 static struct memory_packet_config memory_read_packet_config =
417 {
418 "memory-read-packet-size",
419 };
420
421 static void
422 set_memory_read_packet_size (char *args, int from_tty)
423 {
424 set_memory_packet_size (args, &memory_read_packet_config);
425 }
426
427 static void
428 show_memory_read_packet_size (char *args, int from_tty)
429 {
430 show_memory_packet_size (&memory_read_packet_config);
431 }
432
433 static long
434 get_memory_read_packet_size (void)
435 {
436 long size = get_memory_packet_size (&memory_read_packet_config);
437 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
438 extra buffer size argument before the memory read size can be
439 increased beyond PBUFSIZ. */
440 if (size > PBUFSIZ)
441 size = PBUFSIZ;
442 return size;
443 }
444
445 /* Register packet size initialization. Since the bounds change when
446 the architecture changes (namely REGISTER_BYTES) this all needs to
447 be multi-arched. */
448
449 static void
450 register_remote_packet_sizes (void)
451 {
452 REGISTER_GDBARCH_SWAP (remote_packet_size);
453 REGISTER_GDBARCH_SWAP (actual_register_packet_size);
454 }
455
456 static void
457 build_remote_packet_sizes (void)
458 {
459 /* Default maximum number of characters in a packet body. Many
460 remote stubs have a hardwired buffer size of 400 bytes
461 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
462 as the maximum packet-size to ensure that the packet and an extra
463 NUL character can always fit in the buffer. This stops GDB
464 trashing stubs that try to squeeze an extra NUL into what is
465 already a full buffer (As of 1999-12-04 that was most stubs. */
466 remote_packet_size = 400 - 1;
467 /* Should REGISTER_BYTES needs more space than the default, adjust
468 the size accordingly. Remember that each byte is encoded as two
469 characters. 32 is the overhead for the packet header /
470 footer. NOTE: cagney/1999-10-26: I suspect that 8
471 (``$NN:G...#NN'') is a better guess, the below has been padded a
472 little. */
473 if (REGISTER_BYTES > ((remote_packet_size - 32) / 2))
474 remote_packet_size = (REGISTER_BYTES * 2 + 32);
475
476 /* This one is filled in when a ``g'' packet is received. */
477 actual_register_packet_size = 0;
478 }
479 \f
480 /* Generic configuration support for packets the stub optionally
481 supports. Allows the user to specify the use of the packet as well
482 as allowing GDB to auto-detect support in the remote stub. */
483
484 enum packet_support
485 {
486 PACKET_SUPPORT_UNKNOWN = 0,
487 PACKET_ENABLE,
488 PACKET_DISABLE
489 };
490
491 struct packet_config
492 {
493 char *name;
494 char *title;
495 enum cmd_auto_boolean detect;
496 enum packet_support support;
497 };
498
499 /* Analyze a packet's return value and update the packet config
500 accordingly. */
501
502 enum packet_result
503 {
504 PACKET_ERROR,
505 PACKET_OK,
506 PACKET_UNKNOWN
507 };
508
509 static void
510 update_packet_config (struct packet_config *config)
511 {
512 switch (config->detect)
513 {
514 case CMD_AUTO_BOOLEAN_TRUE:
515 config->support = PACKET_ENABLE;
516 break;
517 case CMD_AUTO_BOOLEAN_FALSE:
518 config->support = PACKET_DISABLE;
519 break;
520 case CMD_AUTO_BOOLEAN_AUTO:
521 config->support = PACKET_SUPPORT_UNKNOWN;
522 break;
523 }
524 }
525
526 static void
527 show_packet_config_cmd (struct packet_config *config)
528 {
529 char *support = "internal-error";
530 switch (config->support)
531 {
532 case PACKET_ENABLE:
533 support = "enabled";
534 break;
535 case PACKET_DISABLE:
536 support = "disabled";
537 break;
538 case PACKET_SUPPORT_UNKNOWN:
539 support = "unknown";
540 break;
541 }
542 switch (config->detect)
543 {
544 case CMD_AUTO_BOOLEAN_AUTO:
545 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
546 config->name, config->title, support);
547 break;
548 case CMD_AUTO_BOOLEAN_TRUE:
549 case CMD_AUTO_BOOLEAN_FALSE:
550 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
551 config->name, config->title, support);
552 break;
553 }
554 }
555
556 static void
557 add_packet_config_cmd (struct packet_config *config,
558 char *name,
559 char *title,
560 void (*set_func) (char *args, int from_tty,
561 struct cmd_list_element *
562 c),
563 void (*show_func) (char *name,
564 int from_tty),
565 struct cmd_list_element **set_remote_list,
566 struct cmd_list_element **show_remote_list,
567 int legacy)
568 {
569 struct cmd_list_element *set_cmd;
570 struct cmd_list_element *show_cmd;
571 char *set_doc;
572 char *show_doc;
573 char *cmd_name;
574 config->name = name;
575 config->title = title;
576 config->detect = CMD_AUTO_BOOLEAN_AUTO;
577 config->support = PACKET_SUPPORT_UNKNOWN;
578 xasprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet",
579 name, title);
580 xasprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet",
581 name, title);
582 /* set/show TITLE-packet {auto,on,off} */
583 xasprintf (&cmd_name, "%s-packet", title);
584 set_cmd = add_set_auto_boolean_cmd (cmd_name, class_obscure,
585 &config->detect, set_doc,
586 set_remote_list);
587 set_cmd->function.sfunc = set_func;
588 show_cmd = add_cmd (cmd_name, class_obscure, show_func, show_doc,
589 show_remote_list);
590 /* set/show remote NAME-packet {auto,on,off} -- legacy */
591 if (legacy)
592 {
593 char *legacy_name;
594 xasprintf (&legacy_name, "%s-packet", name);
595 add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
596 set_remote_list);
597 add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
598 show_remote_list);
599 }
600 }
601
602 static enum packet_result
603 packet_ok (const char *buf, struct packet_config *config)
604 {
605 if (buf[0] != '\0')
606 {
607 /* The stub recognized the packet request. Check that the
608 operation succeeded. */
609 switch (config->support)
610 {
611 case PACKET_SUPPORT_UNKNOWN:
612 if (remote_debug)
613 fprintf_unfiltered (gdb_stdlog,
614 "Packet %s (%s) is supported\n",
615 config->name, config->title);
616 config->support = PACKET_ENABLE;
617 break;
618 case PACKET_DISABLE:
619 internal_error (__FILE__, __LINE__,
620 "packet_ok: attempt to use a disabled packet");
621 break;
622 case PACKET_ENABLE:
623 break;
624 }
625 if (buf[0] == 'O' && buf[1] == 'K' && buf[2] == '\0')
626 /* "OK" - definitly OK. */
627 return PACKET_OK;
628 if (buf[0] == 'E'
629 && isxdigit (buf[1]) && isxdigit (buf[2])
630 && buf[3] == '\0')
631 /* "Enn" - definitly an error. */
632 return PACKET_ERROR;
633 /* The packet may or may not be OK. Just assume it is */
634 return PACKET_OK;
635 }
636 else
637 {
638 /* The stub does not support the packet. */
639 switch (config->support)
640 {
641 case PACKET_ENABLE:
642 if (config->detect == CMD_AUTO_BOOLEAN_AUTO)
643 /* If the stub previously indicated that the packet was
644 supported then there is a protocol error.. */
645 error ("Protocol error: %s (%s) conflicting enabled responses.",
646 config->name, config->title);
647 else
648 /* The user set it wrong. */
649 error ("Enabled packet %s (%s) not recognized by stub",
650 config->name, config->title);
651 break;
652 case PACKET_SUPPORT_UNKNOWN:
653 if (remote_debug)
654 fprintf_unfiltered (gdb_stdlog,
655 "Packet %s (%s) is NOT supported\n",
656 config->name, config->title);
657 config->support = PACKET_DISABLE;
658 break;
659 case PACKET_DISABLE:
660 break;
661 }
662 return PACKET_UNKNOWN;
663 }
664 }
665
666 /* Should we try the 'P' (set register) request? */
667
668 static struct packet_config remote_protocol_P;
669
670 static void
671 set_remote_protocol_P_packet_cmd (char *args, int from_tty,
672 struct cmd_list_element *c)
673 {
674 update_packet_config (&remote_protocol_P);
675 }
676
677 static void
678 show_remote_protocol_P_packet_cmd (char *args, int from_tty)
679 {
680 show_packet_config_cmd (&remote_protocol_P);
681 }
682
683 /* Should we try one of the 'Z' requests? */
684
685 enum Z_packet_type
686 {
687 Z_PACKET_SOFTWARE_BP,
688 Z_PACKET_HARDWARE_BP,
689 Z_PACKET_WRITE_WP,
690 Z_PACKET_READ_WP,
691 Z_PACKET_ACCESS_WP,
692 NR_Z_PACKET_TYPES
693 };
694
695 static struct packet_config remote_protocol_Z[NR_Z_PACKET_TYPES];
696
697 /* FIXME: Instead of having all these boiler plate functions, the
698 command callback should include a context argument. */
699
700 static void
701 set_remote_protocol_Z_software_bp_packet_cmd (char *args, int from_tty,
702 struct cmd_list_element *c)
703 {
704 update_packet_config (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP]);
705 }
706
707 static void
708 show_remote_protocol_Z_software_bp_packet_cmd (char *args, int from_tty)
709 {
710 show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP]);
711 }
712
713 static void
714 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args, int from_tty,
715 struct cmd_list_element *c)
716 {
717 update_packet_config (&remote_protocol_Z[Z_PACKET_HARDWARE_BP]);
718 }
719
720 static void
721 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args, int from_tty)
722 {
723 show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_HARDWARE_BP]);
724 }
725
726 static void
727 set_remote_protocol_Z_write_wp_packet_cmd (char *args, int from_tty,
728 struct cmd_list_element *c)
729 {
730 update_packet_config (&remote_protocol_Z[Z_PACKET_WRITE_WP]);
731 }
732
733 static void
734 show_remote_protocol_Z_write_wp_packet_cmd (char *args, int from_tty)
735 {
736 show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_WRITE_WP]);
737 }
738
739 static void
740 set_remote_protocol_Z_read_wp_packet_cmd (char *args, int from_tty,
741 struct cmd_list_element *c)
742 {
743 update_packet_config (&remote_protocol_Z[Z_PACKET_READ_WP]);
744 }
745
746 static void
747 show_remote_protocol_Z_read_wp_packet_cmd (char *args, int from_tty)
748 {
749 show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_READ_WP]);
750 }
751
752 static void
753 set_remote_protocol_Z_access_wp_packet_cmd (char *args, int from_tty,
754 struct cmd_list_element *c)
755 {
756 update_packet_config (&remote_protocol_Z[Z_PACKET_ACCESS_WP]);
757 }
758
759 static void
760 show_remote_protocol_Z_access_wp_packet_cmd (char *args, int from_tty)
761 {
762 show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_ACCESS_WP]);
763 }
764
765 /* For compatibility with older distributions. Provide a ``set remote
766 Z-packet ...'' command that updates all the Z packet types. */
767
768 static enum cmd_auto_boolean remote_Z_packet_detect;
769
770 static void
771 set_remote_protocol_Z_packet_cmd (char *args, int from_tty,
772 struct cmd_list_element *c)
773 {
774 int i;
775 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
776 {
777 remote_protocol_Z[i].detect = remote_Z_packet_detect;
778 update_packet_config (&remote_protocol_Z[i]);
779 }
780 }
781
782 static void
783 show_remote_protocol_Z_packet_cmd (char *args, int from_tty)
784 {
785 int i;
786 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
787 {
788 show_packet_config_cmd (&remote_protocol_Z[i]);
789 }
790 }
791
792 /* Should we try the 'X' (remote binary download) packet?
793
794 This variable (available to the user via "set remote X-packet")
795 dictates whether downloads are sent in binary (via the 'X' packet).
796 We assume that the stub can, and attempt to do it. This will be
797 cleared if the stub does not understand it. This switch is still
798 needed, though in cases when the packet is supported in the stub,
799 but the connection does not allow it (i.e., 7-bit serial connection
800 only). */
801
802 static struct packet_config remote_protocol_binary_download;
803
804 /* Should we try the 'ThreadInfo' query packet?
805
806 This variable (NOT available to the user: auto-detect only!)
807 determines whether GDB will use the new, simpler "ThreadInfo"
808 query or the older, more complex syntax for thread queries.
809 This is an auto-detect variable (set to true at each connect,
810 and set to false when the target fails to recognize it). */
811
812 static int use_threadinfo_query;
813 static int use_threadextra_query;
814
815 static void
816 set_remote_protocol_binary_download_cmd (char *args,
817 int from_tty,
818 struct cmd_list_element *c)
819 {
820 update_packet_config (&remote_protocol_binary_download);
821 }
822
823 static void
824 show_remote_protocol_binary_download_cmd (char *args,
825 int from_tty)
826 {
827 show_packet_config_cmd (&remote_protocol_binary_download);
828 }
829
830
831 /* Tokens for use by the asynchronous signal handlers for SIGINT */
832 PTR sigint_remote_twice_token;
833 PTR sigint_remote_token;
834
835 /* These are pointers to hook functions that may be set in order to
836 modify resume/wait behavior for a particular architecture. */
837
838 void (*target_resume_hook) (void);
839 void (*target_wait_loop_hook) (void);
840 \f
841
842
843 /* These are the threads which we last sent to the remote system.
844 -1 for all or -2 for not sent yet. */
845 static int general_thread;
846 static int continue_thread;
847
848 /* Call this function as a result of
849 1) A halt indication (T packet) containing a thread id
850 2) A direct query of currthread
851 3) Successful execution of set thread
852 */
853
854 static void
855 record_currthread (int currthread)
856 {
857 general_thread = currthread;
858
859 /* If this is a new thread, add it to GDB's thread list.
860 If we leave it up to WFI to do this, bad things will happen. */
861 if (!in_thread_list (currthread))
862 {
863 add_thread (currthread);
864 #ifdef UI_OUT
865 ui_out_text (uiout, "[New ");
866 ui_out_text (uiout, target_pid_to_str (currthread));
867 ui_out_text (uiout, "]\n");
868 #else
869 printf_filtered ("[New %s]\n", target_pid_to_str (currthread));
870 #endif
871 }
872 }
873
874 #define MAGIC_NULL_PID 42000
875
876 static void
877 set_thread (int th, int gen)
878 {
879 char *buf = alloca (PBUFSIZ);
880 int state = gen ? general_thread : continue_thread;
881
882 if (state == th)
883 return;
884
885 buf[0] = 'H';
886 buf[1] = gen ? 'g' : 'c';
887 if (th == MAGIC_NULL_PID)
888 {
889 buf[2] = '0';
890 buf[3] = '\0';
891 }
892 else if (th < 0)
893 sprintf (&buf[2], "-%x", -th);
894 else
895 sprintf (&buf[2], "%x", th);
896 putpkt (buf);
897 getpkt (buf, PBUFSIZ, 0);
898 if (gen)
899 general_thread = th;
900 else
901 continue_thread = th;
902 }
903 \f
904 /* Return nonzero if the thread TH is still alive on the remote system. */
905
906 static int
907 remote_thread_alive (int tid)
908 {
909 char buf[16];
910
911 if (tid < 0)
912 sprintf (buf, "T-%08x", -tid);
913 else
914 sprintf (buf, "T%08x", tid);
915 putpkt (buf);
916 getpkt (buf, sizeof (buf), 0);
917 return (buf[0] == 'O' && buf[1] == 'K');
918 }
919
920 /* About these extended threadlist and threadinfo packets. They are
921 variable length packets but, the fields within them are often fixed
922 length. They are redundent enough to send over UDP as is the
923 remote protocol in general. There is a matching unit test module
924 in libstub. */
925
926 #define OPAQUETHREADBYTES 8
927
928 /* a 64 bit opaque identifier */
929 typedef unsigned char threadref[OPAQUETHREADBYTES];
930
931 /* WARNING: This threadref data structure comes from the remote O.S., libstub
932 protocol encoding, and remote.c. it is not particularly changable */
933
934 /* Right now, the internal structure is int. We want it to be bigger.
935 Plan to fix this.
936 */
937
938 typedef int gdb_threadref; /* internal GDB thread reference */
939
940 /* gdb_ext_thread_info is an internal GDB data structure which is
941 equivalint to the reply of the remote threadinfo packet */
942
943 struct gdb_ext_thread_info
944 {
945 threadref threadid; /* External form of thread reference */
946 int active; /* Has state interesting to GDB? , regs, stack */
947 char display[256]; /* Brief state display, name, blocked/syspended */
948 char shortname[32]; /* To be used to name threads */
949 char more_display[256]; /* Long info, statistics, queue depth, whatever */
950 };
951
952 /* The volume of remote transfers can be limited by submitting
953 a mask containing bits specifying the desired information.
954 Use a union of these values as the 'selection' parameter to
955 get_thread_info. FIXME: Make these TAG names more thread specific.
956 */
957
958 #define TAG_THREADID 1
959 #define TAG_EXISTS 2
960 #define TAG_DISPLAY 4
961 #define TAG_THREADNAME 8
962 #define TAG_MOREDISPLAY 16
963
964 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
965
966 char *unpack_varlen_hex (char *buff, int *result);
967
968 static char *unpack_nibble (char *buf, int *val);
969
970 static char *pack_nibble (char *buf, int nibble);
971
972 static char *pack_hex_byte (char *pkt, int /*unsigned char */ byte);
973
974 static char *unpack_byte (char *buf, int *value);
975
976 static char *pack_int (char *buf, int value);
977
978 static char *unpack_int (char *buf, int *value);
979
980 static char *unpack_string (char *src, char *dest, int length);
981
982 static char *pack_threadid (char *pkt, threadref * id);
983
984 static char *unpack_threadid (char *inbuf, threadref * id);
985
986 void int_to_threadref (threadref * id, int value);
987
988 static int threadref_to_int (threadref * ref);
989
990 static void copy_threadref (threadref * dest, threadref * src);
991
992 static int threadmatch (threadref * dest, threadref * src);
993
994 static char *pack_threadinfo_request (char *pkt, int mode, threadref * id);
995
996 static int remote_unpack_thread_info_response (char *pkt,
997 threadref * expectedref,
998 struct gdb_ext_thread_info
999 *info);
1000
1001
1002 static int remote_get_threadinfo (threadref * threadid, int fieldset, /*TAG mask */
1003 struct gdb_ext_thread_info *info);
1004
1005 static int adapt_remote_get_threadinfo (gdb_threadref * ref,
1006 int selection,
1007 struct gdb_ext_thread_info *info);
1008
1009 static char *pack_threadlist_request (char *pkt, int startflag,
1010 int threadcount,
1011 threadref * nextthread);
1012
1013 static int parse_threadlist_response (char *pkt,
1014 int result_limit,
1015 threadref * original_echo,
1016 threadref * resultlist, int *doneflag);
1017
1018 static int remote_get_threadlist (int startflag,
1019 threadref * nextthread,
1020 int result_limit,
1021 int *done,
1022 int *result_count, threadref * threadlist);
1023
1024 typedef int (*rmt_thread_action) (threadref * ref, void *context);
1025
1026 static int remote_threadlist_iterator (rmt_thread_action stepfunction,
1027 void *context, int looplimit);
1028
1029 static int remote_newthread_step (threadref * ref, void *context);
1030
1031 /* encode 64 bits in 16 chars of hex */
1032
1033 static const char hexchars[] = "0123456789abcdef";
1034
1035 static int
1036 ishex (int ch, int *val)
1037 {
1038 if ((ch >= 'a') && (ch <= 'f'))
1039 {
1040 *val = ch - 'a' + 10;
1041 return 1;
1042 }
1043 if ((ch >= 'A') && (ch <= 'F'))
1044 {
1045 *val = ch - 'A' + 10;
1046 return 1;
1047 }
1048 if ((ch >= '0') && (ch <= '9'))
1049 {
1050 *val = ch - '0';
1051 return 1;
1052 }
1053 return 0;
1054 }
1055
1056 static int
1057 stubhex (int ch)
1058 {
1059 if (ch >= 'a' && ch <= 'f')
1060 return ch - 'a' + 10;
1061 if (ch >= '0' && ch <= '9')
1062 return ch - '0';
1063 if (ch >= 'A' && ch <= 'F')
1064 return ch - 'A' + 10;
1065 return -1;
1066 }
1067
1068 static int
1069 stub_unpack_int (char *buff, int fieldlength)
1070 {
1071 int nibble;
1072 int retval = 0;
1073
1074 while (fieldlength)
1075 {
1076 nibble = stubhex (*buff++);
1077 retval |= nibble;
1078 fieldlength--;
1079 if (fieldlength)
1080 retval = retval << 4;
1081 }
1082 return retval;
1083 }
1084
1085 char *
1086 unpack_varlen_hex (char *buff, /* packet to parse */
1087 int *result)
1088 {
1089 int nibble;
1090 int retval = 0;
1091
1092 while (ishex (*buff, &nibble))
1093 {
1094 buff++;
1095 retval = retval << 4;
1096 retval |= nibble & 0x0f;
1097 }
1098 *result = retval;
1099 return buff;
1100 }
1101
1102 static char *
1103 unpack_nibble (char *buf, int *val)
1104 {
1105 ishex (*buf++, val);
1106 return buf;
1107 }
1108
1109 static char *
1110 pack_nibble (char *buf, int nibble)
1111 {
1112 *buf++ = hexchars[(nibble & 0x0f)];
1113 return buf;
1114 }
1115
1116 static char *
1117 pack_hex_byte (char *pkt, int byte)
1118 {
1119 *pkt++ = hexchars[(byte >> 4) & 0xf];
1120 *pkt++ = hexchars[(byte & 0xf)];
1121 return pkt;
1122 }
1123
1124 static char *
1125 unpack_byte (char *buf, int *value)
1126 {
1127 *value = stub_unpack_int (buf, 2);
1128 return buf + 2;
1129 }
1130
1131 static char *
1132 pack_int (char *buf, int value)
1133 {
1134 buf = pack_hex_byte (buf, (value >> 24) & 0xff);
1135 buf = pack_hex_byte (buf, (value >> 16) & 0xff);
1136 buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
1137 buf = pack_hex_byte (buf, (value & 0xff));
1138 return buf;
1139 }
1140
1141 static char *
1142 unpack_int (char *buf, int *value)
1143 {
1144 *value = stub_unpack_int (buf, 8);
1145 return buf + 8;
1146 }
1147
1148 #if 0 /* currently unused, uncomment when needed */
1149 static char *pack_string (char *pkt, char *string);
1150
1151 static char *
1152 pack_string (char *pkt, char *string)
1153 {
1154 char ch;
1155 int len;
1156
1157 len = strlen (string);
1158 if (len > 200)
1159 len = 200; /* Bigger than most GDB packets, junk??? */
1160 pkt = pack_hex_byte (pkt, len);
1161 while (len-- > 0)
1162 {
1163 ch = *string++;
1164 if ((ch == '\0') || (ch == '#'))
1165 ch = '*'; /* Protect encapsulation */
1166 *pkt++ = ch;
1167 }
1168 return pkt;
1169 }
1170 #endif /* 0 (unused) */
1171
1172 static char *
1173 unpack_string (char *src, char *dest, int length)
1174 {
1175 while (length--)
1176 *dest++ = *src++;
1177 *dest = '\0';
1178 return src;
1179 }
1180
1181 static char *
1182 pack_threadid (char *pkt, threadref *id)
1183 {
1184 char *limit;
1185 unsigned char *altid;
1186
1187 altid = (unsigned char *) id;
1188 limit = pkt + BUF_THREAD_ID_SIZE;
1189 while (pkt < limit)
1190 pkt = pack_hex_byte (pkt, *altid++);
1191 return pkt;
1192 }
1193
1194
1195 static char *
1196 unpack_threadid (char *inbuf, threadref *id)
1197 {
1198 char *altref;
1199 char *limit = inbuf + BUF_THREAD_ID_SIZE;
1200 int x, y;
1201
1202 altref = (char *) id;
1203
1204 while (inbuf < limit)
1205 {
1206 x = stubhex (*inbuf++);
1207 y = stubhex (*inbuf++);
1208 *altref++ = (x << 4) | y;
1209 }
1210 return inbuf;
1211 }
1212
1213 /* Externally, threadrefs are 64 bits but internally, they are still
1214 ints. This is due to a mismatch of specifications. We would like
1215 to use 64bit thread references internally. This is an adapter
1216 function. */
1217
1218 void
1219 int_to_threadref (threadref *id, int value)
1220 {
1221 unsigned char *scan;
1222
1223 scan = (unsigned char *) id;
1224 {
1225 int i = 4;
1226 while (i--)
1227 *scan++ = 0;
1228 }
1229 *scan++ = (value >> 24) & 0xff;
1230 *scan++ = (value >> 16) & 0xff;
1231 *scan++ = (value >> 8) & 0xff;
1232 *scan++ = (value & 0xff);
1233 }
1234
1235 static int
1236 threadref_to_int (threadref *ref)
1237 {
1238 int i, value = 0;
1239 unsigned char *scan;
1240
1241 scan = (char *) ref;
1242 scan += 4;
1243 i = 4;
1244 while (i-- > 0)
1245 value = (value << 8) | ((*scan++) & 0xff);
1246 return value;
1247 }
1248
1249 static void
1250 copy_threadref (threadref *dest, threadref *src)
1251 {
1252 int i;
1253 unsigned char *csrc, *cdest;
1254
1255 csrc = (unsigned char *) src;
1256 cdest = (unsigned char *) dest;
1257 i = 8;
1258 while (i--)
1259 *cdest++ = *csrc++;
1260 }
1261
1262 static int
1263 threadmatch (threadref *dest, threadref *src)
1264 {
1265 /* things are broken right now, so just assume we got a match */
1266 #if 0
1267 unsigned char *srcp, *destp;
1268 int i, result;
1269 srcp = (char *) src;
1270 destp = (char *) dest;
1271
1272 result = 1;
1273 while (i-- > 0)
1274 result &= (*srcp++ == *destp++) ? 1 : 0;
1275 return result;
1276 #endif
1277 return 1;
1278 }
1279
1280 /*
1281 threadid:1, # always request threadid
1282 context_exists:2,
1283 display:4,
1284 unique_name:8,
1285 more_display:16
1286 */
1287
1288 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1289
1290 static char *
1291 pack_threadinfo_request (char *pkt, int mode, threadref *id)
1292 {
1293 *pkt++ = 'q'; /* Info Query */
1294 *pkt++ = 'P'; /* process or thread info */
1295 pkt = pack_int (pkt, mode); /* mode */
1296 pkt = pack_threadid (pkt, id); /* threadid */
1297 *pkt = '\0'; /* terminate */
1298 return pkt;
1299 }
1300
1301 /* These values tag the fields in a thread info response packet */
1302 /* Tagging the fields allows us to request specific fields and to
1303 add more fields as time goes by */
1304
1305 #define TAG_THREADID 1 /* Echo the thread identifier */
1306 #define TAG_EXISTS 2 /* Is this process defined enough to
1307 fetch registers and its stack */
1308 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1309 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1310 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1311 the process */
1312
1313 static int
1314 remote_unpack_thread_info_response (char *pkt, threadref *expectedref,
1315 struct gdb_ext_thread_info *info)
1316 {
1317 int mask, length;
1318 unsigned int tag;
1319 threadref ref;
1320 char *limit = pkt + PBUFSIZ; /* plausable parsing limit */
1321 int retval = 1;
1322
1323 /* info->threadid = 0; FIXME: implement zero_threadref */
1324 info->active = 0;
1325 info->display[0] = '\0';
1326 info->shortname[0] = '\0';
1327 info->more_display[0] = '\0';
1328
1329 /* Assume the characters indicating the packet type have been stripped */
1330 pkt = unpack_int (pkt, &mask); /* arg mask */
1331 pkt = unpack_threadid (pkt, &ref);
1332
1333 if (mask == 0)
1334 warning ("Incomplete response to threadinfo request\n");
1335 if (!threadmatch (&ref, expectedref))
1336 { /* This is an answer to a different request */
1337 warning ("ERROR RMT Thread info mismatch\n");
1338 return 0;
1339 }
1340 copy_threadref (&info->threadid, &ref);
1341
1342 /* Loop on tagged fields , try to bail if somthing goes wrong */
1343
1344 while ((pkt < limit) && mask && *pkt) /* packets are terminated with nulls */
1345 {
1346 pkt = unpack_int (pkt, &tag); /* tag */
1347 pkt = unpack_byte (pkt, &length); /* length */
1348 if (!(tag & mask)) /* tags out of synch with mask */
1349 {
1350 warning ("ERROR RMT: threadinfo tag mismatch\n");
1351 retval = 0;
1352 break;
1353 }
1354 if (tag == TAG_THREADID)
1355 {
1356 if (length != 16)
1357 {
1358 warning ("ERROR RMT: length of threadid is not 16\n");
1359 retval = 0;
1360 break;
1361 }
1362 pkt = unpack_threadid (pkt, &ref);
1363 mask = mask & ~TAG_THREADID;
1364 continue;
1365 }
1366 if (tag == TAG_EXISTS)
1367 {
1368 info->active = stub_unpack_int (pkt, length);
1369 pkt += length;
1370 mask = mask & ~(TAG_EXISTS);
1371 if (length > 8)
1372 {
1373 warning ("ERROR RMT: 'exists' length too long\n");
1374 retval = 0;
1375 break;
1376 }
1377 continue;
1378 }
1379 if (tag == TAG_THREADNAME)
1380 {
1381 pkt = unpack_string (pkt, &info->shortname[0], length);
1382 mask = mask & ~TAG_THREADNAME;
1383 continue;
1384 }
1385 if (tag == TAG_DISPLAY)
1386 {
1387 pkt = unpack_string (pkt, &info->display[0], length);
1388 mask = mask & ~TAG_DISPLAY;
1389 continue;
1390 }
1391 if (tag == TAG_MOREDISPLAY)
1392 {
1393 pkt = unpack_string (pkt, &info->more_display[0], length);
1394 mask = mask & ~TAG_MOREDISPLAY;
1395 continue;
1396 }
1397 warning ("ERROR RMT: unknown thread info tag\n");
1398 break; /* Not a tag we know about */
1399 }
1400 return retval;
1401 }
1402
1403 static int
1404 remote_get_threadinfo (threadref *threadid, int fieldset, /* TAG mask */
1405 struct gdb_ext_thread_info *info)
1406 {
1407 int result;
1408 char *threadinfo_pkt = alloca (PBUFSIZ);
1409
1410 pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
1411 putpkt (threadinfo_pkt);
1412 getpkt (threadinfo_pkt, PBUFSIZ, 0);
1413 result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
1414 info);
1415 return result;
1416 }
1417
1418 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1419 representation of a threadid. */
1420
1421 static int
1422 adapt_remote_get_threadinfo (gdb_threadref *ref, int selection,
1423 struct gdb_ext_thread_info *info)
1424 {
1425 threadref lclref;
1426
1427 int_to_threadref (&lclref, *ref);
1428 return remote_get_threadinfo (&lclref, selection, info);
1429 }
1430
1431 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1432
1433 static char *
1434 pack_threadlist_request (char *pkt, int startflag, int threadcount,
1435 threadref *nextthread)
1436 {
1437 *pkt++ = 'q'; /* info query packet */
1438 *pkt++ = 'L'; /* Process LIST or threadLIST request */
1439 pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */
1440 pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */
1441 pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */
1442 *pkt = '\0';
1443 return pkt;
1444 }
1445
1446 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1447
1448 static int
1449 parse_threadlist_response (char *pkt, int result_limit,
1450 threadref *original_echo, threadref *resultlist,
1451 int *doneflag)
1452 {
1453 char *limit;
1454 int count, resultcount, done;
1455
1456 resultcount = 0;
1457 /* Assume the 'q' and 'M chars have been stripped. */
1458 limit = pkt + (PBUFSIZ - BUF_THREAD_ID_SIZE); /* done parse past here */
1459 pkt = unpack_byte (pkt, &count); /* count field */
1460 pkt = unpack_nibble (pkt, &done);
1461 /* The first threadid is the argument threadid. */
1462 pkt = unpack_threadid (pkt, original_echo); /* should match query packet */
1463 while ((count-- > 0) && (pkt < limit))
1464 {
1465 pkt = unpack_threadid (pkt, resultlist++);
1466 if (resultcount++ >= result_limit)
1467 break;
1468 }
1469 if (doneflag)
1470 *doneflag = done;
1471 return resultcount;
1472 }
1473
1474 static int
1475 remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
1476 int *done, int *result_count, threadref *threadlist)
1477 {
1478 static threadref echo_nextthread;
1479 char *threadlist_packet = alloca (PBUFSIZ);
1480 char *t_response = alloca (PBUFSIZ);
1481 int result = 1;
1482
1483 /* Trancate result limit to be smaller than the packet size */
1484 if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= PBUFSIZ)
1485 result_limit = (PBUFSIZ / BUF_THREAD_ID_SIZE) - 2;
1486
1487 pack_threadlist_request (threadlist_packet,
1488 startflag, result_limit, nextthread);
1489 putpkt (threadlist_packet);
1490 getpkt (t_response, PBUFSIZ, 0);
1491
1492 *result_count =
1493 parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
1494 threadlist, done);
1495
1496 if (!threadmatch (&echo_nextthread, nextthread))
1497 {
1498 /* FIXME: This is a good reason to drop the packet */
1499 /* Possably, there is a duplicate response */
1500 /* Possabilities :
1501 retransmit immediatly - race conditions
1502 retransmit after timeout - yes
1503 exit
1504 wait for packet, then exit
1505 */
1506 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1507 return 0; /* I choose simply exiting */
1508 }
1509 if (*result_count <= 0)
1510 {
1511 if (*done != 1)
1512 {
1513 warning ("RMT ERROR : failed to get remote thread list\n");
1514 result = 0;
1515 }
1516 return result; /* break; */
1517 }
1518 if (*result_count > result_limit)
1519 {
1520 *result_count = 0;
1521 warning ("RMT ERROR: threadlist response longer than requested\n");
1522 return 0;
1523 }
1524 return result;
1525 }
1526
1527 /* This is the interface between remote and threads, remotes upper interface */
1528
1529 /* remote_find_new_threads retrieves the thread list and for each
1530 thread in the list, looks up the thread in GDB's internal list,
1531 ading the thread if it does not already exist. This involves
1532 getting partial thread lists from the remote target so, polling the
1533 quit_flag is required. */
1534
1535
1536 /* About this many threadisds fit in a packet. */
1537
1538 #define MAXTHREADLISTRESULTS 32
1539
1540 static int
1541 remote_threadlist_iterator (rmt_thread_action stepfunction, void *context,
1542 int looplimit)
1543 {
1544 int done, i, result_count;
1545 int startflag = 1;
1546 int result = 1;
1547 int loopcount = 0;
1548 static threadref nextthread;
1549 static threadref resultthreadlist[MAXTHREADLISTRESULTS];
1550
1551 done = 0;
1552 while (!done)
1553 {
1554 if (loopcount++ > looplimit)
1555 {
1556 result = 0;
1557 warning ("Remote fetch threadlist -infinite loop-\n");
1558 break;
1559 }
1560 if (!remote_get_threadlist (startflag, &nextthread, MAXTHREADLISTRESULTS,
1561 &done, &result_count, resultthreadlist))
1562 {
1563 result = 0;
1564 break;
1565 }
1566 /* clear for later iterations */
1567 startflag = 0;
1568 /* Setup to resume next batch of thread references, set nextthread. */
1569 if (result_count >= 1)
1570 copy_threadref (&nextthread, &resultthreadlist[result_count - 1]);
1571 i = 0;
1572 while (result_count--)
1573 if (!(result = (*stepfunction) (&resultthreadlist[i++], context)))
1574 break;
1575 }
1576 return result;
1577 }
1578
1579 static int
1580 remote_newthread_step (threadref *ref, void *context)
1581 {
1582 int pid;
1583
1584 pid = threadref_to_int (ref);
1585 if (!in_thread_list (pid))
1586 add_thread (pid);
1587 return 1; /* continue iterator */
1588 }
1589
1590 #define CRAZY_MAX_THREADS 1000
1591
1592 static int
1593 remote_current_thread (int oldpid)
1594 {
1595 char *buf = alloca (PBUFSIZ);
1596
1597 putpkt ("qC");
1598 getpkt (buf, PBUFSIZ, 0);
1599 if (buf[0] == 'Q' && buf[1] == 'C')
1600 return strtol (&buf[2], NULL, 16);
1601 else
1602 return oldpid;
1603 }
1604
1605 /* Find new threads for info threads command.
1606 * Original version, using John Metzler's thread protocol.
1607 */
1608
1609 static void
1610 remote_find_new_threads (void)
1611 {
1612 remote_threadlist_iterator (remote_newthread_step, 0,
1613 CRAZY_MAX_THREADS);
1614 if (inferior_pid == MAGIC_NULL_PID) /* ack ack ack */
1615 inferior_pid = remote_current_thread (inferior_pid);
1616 }
1617
1618 /*
1619 * Find all threads for info threads command.
1620 * Uses new thread protocol contributed by Cisco.
1621 * Falls back and attempts to use the older method (above)
1622 * if the target doesn't respond to the new method.
1623 */
1624
1625 static void
1626 remote_threads_info (void)
1627 {
1628 char *buf = alloca (PBUFSIZ);
1629 char *bufp;
1630 int tid;
1631
1632 if (remote_desc == 0) /* paranoia */
1633 error ("Command can only be used when connected to the remote target.");
1634
1635 if (use_threadinfo_query)
1636 {
1637 putpkt ("qfThreadInfo");
1638 bufp = buf;
1639 getpkt (bufp, PBUFSIZ, 0);
1640 if (bufp[0] != '\0') /* q packet recognized */
1641 {
1642 while (*bufp++ == 'm') /* reply contains one or more TID */
1643 {
1644 do
1645 {
1646 tid = strtol (bufp, &bufp, 16);
1647 if (tid != 0 && !in_thread_list (tid))
1648 add_thread (tid);
1649 }
1650 while (*bufp++ == ','); /* comma-separated list */
1651 putpkt ("qsThreadInfo");
1652 bufp = buf;
1653 getpkt (bufp, PBUFSIZ, 0);
1654 }
1655 return; /* done */
1656 }
1657 }
1658
1659 /* Else fall back to old method based on jmetzler protocol. */
1660 use_threadinfo_query = 0;
1661 remote_find_new_threads ();
1662 return;
1663 }
1664
1665 /*
1666 * Collect a descriptive string about the given thread.
1667 * The target may say anything it wants to about the thread
1668 * (typically info about its blocked / runnable state, name, etc.).
1669 * This string will appear in the info threads display.
1670 *
1671 * Optional: targets are not required to implement this function.
1672 */
1673
1674 static char *
1675 remote_threads_extra_info (struct thread_info *tp)
1676 {
1677 int result;
1678 int set;
1679 threadref id;
1680 struct gdb_ext_thread_info threadinfo;
1681 static char display_buf[100]; /* arbitrary... */
1682 char *bufp = alloca (PBUFSIZ);
1683 int n = 0; /* position in display_buf */
1684
1685 if (remote_desc == 0) /* paranoia */
1686 internal_error (__FILE__, __LINE__,
1687 "remote_threads_extra_info");
1688
1689 if (use_threadextra_query)
1690 {
1691 sprintf (bufp, "qThreadExtraInfo,%x", tp->pid);
1692 putpkt (bufp);
1693 getpkt (bufp, PBUFSIZ, 0);
1694 if (bufp[0] != 0)
1695 {
1696 char *p;
1697
1698 for (p = display_buf;
1699 p < display_buf + sizeof(display_buf) - 1 &&
1700 bufp[0] != 0 &&
1701 bufp[1] != 0;
1702 p++, bufp+=2)
1703 {
1704 *p = fromhex (bufp[0]) * 16 + fromhex (bufp[1]);
1705 }
1706 *p = 0;
1707 return display_buf;
1708 }
1709 }
1710
1711 /* If the above query fails, fall back to the old method. */
1712 use_threadextra_query = 0;
1713 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
1714 | TAG_MOREDISPLAY | TAG_DISPLAY;
1715 int_to_threadref (&id, tp->pid);
1716 if (remote_get_threadinfo (&id, set, &threadinfo))
1717 if (threadinfo.active)
1718 {
1719 if (*threadinfo.shortname)
1720 n += sprintf(&display_buf[0], " Name: %s,", threadinfo.shortname);
1721 if (*threadinfo.display)
1722 n += sprintf(&display_buf[n], " State: %s,", threadinfo.display);
1723 if (*threadinfo.more_display)
1724 n += sprintf(&display_buf[n], " Priority: %s",
1725 threadinfo.more_display);
1726
1727 if (n > 0)
1728 {
1729 /* for purely cosmetic reasons, clear up trailing commas */
1730 if (',' == display_buf[n-1])
1731 display_buf[n-1] = ' ';
1732 return display_buf;
1733 }
1734 }
1735 return NULL;
1736 }
1737
1738 \f
1739
1740 /* Restart the remote side; this is an extended protocol operation. */
1741
1742 static void
1743 extended_remote_restart (void)
1744 {
1745 char *buf = alloca (PBUFSIZ);
1746
1747 /* Send the restart command; for reasons I don't understand the
1748 remote side really expects a number after the "R". */
1749 buf[0] = 'R';
1750 sprintf (&buf[1], "%x", 0);
1751 putpkt (buf);
1752
1753 /* Now query for status so this looks just like we restarted
1754 gdbserver from scratch. */
1755 putpkt ("?");
1756 getpkt (buf, PBUFSIZ, 0);
1757 }
1758 \f
1759 /* Clean up connection to a remote debugger. */
1760
1761 /* ARGSUSED */
1762 static void
1763 remote_close (int quitting)
1764 {
1765 if (remote_desc)
1766 SERIAL_CLOSE (remote_desc);
1767 remote_desc = NULL;
1768 }
1769
1770 /* Query the remote side for the text, data and bss offsets. */
1771
1772 static void
1773 get_offsets (void)
1774 {
1775 char *buf = alloca (PBUFSIZ);
1776 char *ptr;
1777 int lose;
1778 CORE_ADDR text_addr, data_addr, bss_addr;
1779 struct section_offsets *offs;
1780
1781 putpkt ("qOffsets");
1782
1783 getpkt (buf, PBUFSIZ, 0);
1784
1785 if (buf[0] == '\000')
1786 return; /* Return silently. Stub doesn't support
1787 this command. */
1788 if (buf[0] == 'E')
1789 {
1790 warning ("Remote failure reply: %s", buf);
1791 return;
1792 }
1793
1794 /* Pick up each field in turn. This used to be done with scanf, but
1795 scanf will make trouble if CORE_ADDR size doesn't match
1796 conversion directives correctly. The following code will work
1797 with any size of CORE_ADDR. */
1798 text_addr = data_addr = bss_addr = 0;
1799 ptr = buf;
1800 lose = 0;
1801
1802 if (strncmp (ptr, "Text=", 5) == 0)
1803 {
1804 ptr += 5;
1805 /* Don't use strtol, could lose on big values. */
1806 while (*ptr && *ptr != ';')
1807 text_addr = (text_addr << 4) + fromhex (*ptr++);
1808 }
1809 else
1810 lose = 1;
1811
1812 if (!lose && strncmp (ptr, ";Data=", 6) == 0)
1813 {
1814 ptr += 6;
1815 while (*ptr && *ptr != ';')
1816 data_addr = (data_addr << 4) + fromhex (*ptr++);
1817 }
1818 else
1819 lose = 1;
1820
1821 if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
1822 {
1823 ptr += 5;
1824 while (*ptr && *ptr != ';')
1825 bss_addr = (bss_addr << 4) + fromhex (*ptr++);
1826 }
1827 else
1828 lose = 1;
1829
1830 if (lose)
1831 error ("Malformed response to offset query, %s", buf);
1832
1833 if (symfile_objfile == NULL)
1834 return;
1835
1836 offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
1837 memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
1838
1839 offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
1840
1841 /* This is a temporary kludge to force data and bss to use the same offsets
1842 because that's what nlmconv does now. The real solution requires changes
1843 to the stub and remote.c that I don't have time to do right now. */
1844
1845 offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_addr;
1846 offs->offsets[SECT_OFF_BSS (symfile_objfile)] = data_addr;
1847
1848 objfile_relocate (symfile_objfile, offs);
1849 }
1850
1851 /*
1852 * Cisco version of section offsets:
1853 *
1854 * Instead of having GDB query the target for the section offsets,
1855 * Cisco lets the target volunteer the information! It's also in
1856 * a different format, so here are the functions that will decode
1857 * a section offset packet from a Cisco target.
1858 */
1859
1860 /*
1861 * Function: remote_cisco_section_offsets
1862 *
1863 * Returns: zero for success, non-zero for failure
1864 */
1865
1866 static int
1867 remote_cisco_section_offsets (bfd_vma text_addr,
1868 bfd_vma data_addr,
1869 bfd_vma bss_addr,
1870 bfd_signed_vma *text_offs,
1871 bfd_signed_vma *data_offs,
1872 bfd_signed_vma *bss_offs)
1873 {
1874 bfd_vma text_base, data_base, bss_base;
1875 struct minimal_symbol *start;
1876 asection *sect;
1877 bfd *abfd;
1878 int len;
1879 char *p;
1880
1881 if (symfile_objfile == NULL)
1882 return -1; /* no can do nothin' */
1883
1884 start = lookup_minimal_symbol ("_start", NULL, NULL);
1885 if (start == NULL)
1886 return -1; /* Can't find "_start" symbol */
1887
1888 data_base = bss_base = 0;
1889 text_base = SYMBOL_VALUE_ADDRESS (start);
1890
1891 abfd = symfile_objfile->obfd;
1892 for (sect = abfd->sections;
1893 sect != 0;
1894 sect = sect->next)
1895 {
1896 p = (unsigned char *) bfd_get_section_name (abfd, sect);
1897 len = strlen (p);
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);
1906 }
1907 *text_offs = text_addr - text_base;
1908 *data_offs = data_addr - data_base;
1909 *bss_offs = bss_addr - bss_base;
1910 if (remote_debug)
1911 {
1912 char tmp[128];
1913
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));
1926 }
1927
1928 return 0;
1929 }
1930
1931 /*
1932 * Function: remote_cisco_objfile_relocate
1933 *
1934 * Relocate the symbol file for a remote target.
1935 */
1936
1937 void
1938 remote_cisco_objfile_relocate (bfd_signed_vma text_off, bfd_signed_vma data_off,
1939 bfd_signed_vma bss_off)
1940 {
1941 struct section_offsets *offs;
1942
1943 if (text_off != 0 || data_off != 0 || bss_off != 0)
1944 {
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. */
1948
1949 offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
1950 memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
1951
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;
1955
1956 /* First call the standard objfile_relocate. */
1957 objfile_relocate (symfile_objfile, offs);
1958
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. */
1962
1963 exec_set_section_offsets (text_off, data_off, bss_off);
1964 }
1965 }
1966
1967 /* Stub for catch_errors. */
1968
1969 static int
1970 remote_start_remote_dummy (void *dummy)
1971 {
1972 start_remote (); /* Initialize gdb process mechanisms */
1973 return 1;
1974 }
1975
1976 static int
1977 remote_start_remote (PTR dummy)
1978 {
1979 immediate_quit++; /* Allow user to interrupt it */
1980
1981 /* Ack any packet which the remote side has already sent. */
1982 SERIAL_WRITE (remote_desc, "+", 1);
1983
1984 /* Let the stub know that we want it to return the thread. */
1985 set_thread (-1, 0);
1986
1987 inferior_pid = remote_current_thread (inferior_pid);
1988
1989 get_offsets (); /* Get text, data & bss offsets */
1990
1991 putpkt ("?"); /* initiate a query from remote machine */
1992 immediate_quit--;
1993
1994 return remote_start_remote_dummy (dummy);
1995 }
1996
1997 /* Open a connection to a remote debugger.
1998 NAME is the filename used for communication. */
1999
2000 static void
2001 remote_open (char *name, int from_tty)
2002 {
2003 remote_open_1 (name, from_tty, &remote_ops, 0);
2004 }
2005
2006 /* Just like remote_open, but with asynchronous support. */
2007 static void
2008 remote_async_open (char *name, int from_tty)
2009 {
2010 remote_async_open_1 (name, from_tty, &remote_async_ops, 0);
2011 }
2012
2013 /* Open a connection to a remote debugger using the extended
2014 remote gdb protocol. NAME is the filename used for communication. */
2015
2016 static void
2017 extended_remote_open (char *name, int from_tty)
2018 {
2019 remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */ );
2020 }
2021
2022 /* Just like extended_remote_open, but with asynchronous support. */
2023 static void
2024 extended_remote_async_open (char *name, int from_tty)
2025 {
2026 remote_async_open_1 (name, from_tty, &extended_async_remote_ops, 1 /*extended_p */ );
2027 }
2028
2029 /* Generic code for opening a connection to a remote target. */
2030
2031 static void
2032 init_all_packet_configs (void)
2033 {
2034 int i;
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
2039 downloading. */
2040 update_packet_config (&remote_protocol_binary_download);
2041 }
2042
2043 static void
2044 remote_open_1 (char *name, int from_tty, struct target_ops *target,
2045 int extended_p)
2046 {
2047 if (name == 0)
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.).");
2051
2052 /* See FIXME above */
2053 wait_forever_enabled_p = 1;
2054
2055 target_preopen (from_tty);
2056
2057 unpush_target (target);
2058
2059 remote_desc = SERIAL_OPEN (name);
2060 if (!remote_desc)
2061 perror_with_name (name);
2062
2063 if (baud_rate != -1)
2064 {
2065 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
2066 {
2067 SERIAL_CLOSE (remote_desc);
2068 perror_with_name (name);
2069 }
2070 }
2071
2072 SERIAL_RAW (remote_desc);
2073
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);
2077
2078 if (from_tty)
2079 {
2080 puts_filtered ("Remote debugging using ");
2081 puts_filtered (name);
2082 puts_filtered ("\n");
2083 }
2084 push_target (target); /* Switch to using remote target now */
2085
2086 init_all_packet_configs ();
2087
2088 general_thread = -2;
2089 continue_thread = -2;
2090
2091 /* Probe for ability to use "ThreadInfo" query, as required. */
2092 use_threadinfo_query = 1;
2093 use_threadextra_query = 1;
2094
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. */
2101
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",
2108 RETURN_MASK_ALL))
2109 {
2110 pop_target ();
2111 return;
2112 }
2113
2114 if (extended_p)
2115 {
2116 /* tell the remote that we're using the extended protocol. */
2117 char *buf = alloca (PBUFSIZ);
2118 putpkt ("!");
2119 getpkt (buf, PBUFSIZ, 0);
2120 }
2121 }
2122
2123 /* Just like remote_open but with asynchronous support. */
2124 static void
2125 remote_async_open_1 (char *name, int from_tty, struct target_ops *target,
2126 int extended_p)
2127 {
2128 if (name == 0)
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.).");
2132
2133 target_preopen (from_tty);
2134
2135 unpush_target (target);
2136
2137 remote_desc = SERIAL_OPEN (name);
2138 if (!remote_desc)
2139 perror_with_name (name);
2140
2141 if (baud_rate != -1)
2142 {
2143 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
2144 {
2145 SERIAL_CLOSE (remote_desc);
2146 perror_with_name (name);
2147 }
2148 }
2149
2150 SERIAL_RAW (remote_desc);
2151
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);
2155
2156 if (from_tty)
2157 {
2158 puts_filtered ("Remote debugging using ");
2159 puts_filtered (name);
2160 puts_filtered ("\n");
2161 }
2162
2163 push_target (target); /* Switch to using remote target now */
2164
2165 init_all_packet_configs ();
2166
2167 general_thread = -2;
2168 continue_thread = -2;
2169
2170 /* Probe for ability to use "ThreadInfo" query, as required. */
2171 use_threadinfo_query = 1;
2172 use_threadextra_query = 1;
2173
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;
2181
2182 /* With this target we start out by owning the terminal. */
2183 remote_async_terminal_ours_p = 1;
2184
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
2191 implemented. */
2192 wait_forever_enabled_p = 0;
2193
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",
2199 RETURN_MASK_ALL))
2200 {
2201 pop_target ();
2202 wait_forever_enabled_p = 1;
2203 return;
2204 }
2205
2206 wait_forever_enabled_p = 1;
2207
2208 if (extended_p)
2209 {
2210 /* tell the remote that we're using the extended protocol. */
2211 char *buf = alloca (PBUFSIZ);
2212 putpkt ("!");
2213 getpkt (buf, PBUFSIZ, 0);
2214 }
2215 }
2216
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. */
2221
2222 static void
2223 remote_detach (char *args, int from_tty)
2224 {
2225 char *buf = alloca (PBUFSIZ);
2226
2227 if (args)
2228 error ("Argument given to \"detach\" when remotely debugging.");
2229
2230 /* Tell the remote target to detach. */
2231 strcpy (buf, "D");
2232 remote_send (buf, PBUFSIZ);
2233
2234 target_mourn_inferior ();
2235 if (from_tty)
2236 puts_filtered ("Ending remote debugging.\n");
2237
2238 }
2239
2240 /* Same as remote_detach, but with async support. */
2241 static void
2242 remote_async_detach (char *args, int from_tty)
2243 {
2244 char *buf = alloca (PBUFSIZ);
2245
2246 if (args)
2247 error ("Argument given to \"detach\" when remotely debugging.");
2248
2249 /* Tell the remote target to detach. */
2250 strcpy (buf, "D");
2251 remote_send (buf, PBUFSIZ);
2252
2253 /* Unregister the file descriptor from the event loop. */
2254 if (target_is_async_p ())
2255 SERIAL_ASYNC (remote_desc, NULL, 0);
2256
2257 target_mourn_inferior ();
2258 if (from_tty)
2259 puts_filtered ("Ending remote debugging.\n");
2260 }
2261
2262 /* Convert hex digit A to a number. */
2263
2264 int
2265 fromhex (int a)
2266 {
2267 if (a >= '0' && a <= '9')
2268 return a - '0';
2269 else if (a >= 'a' && a <= 'f')
2270 return a - 'a' + 10;
2271 else if (a >= 'A' && a <= 'F')
2272 return a - 'A' + 10;
2273 else
2274 error ("Reply contains invalid hex digit %d", a);
2275 }
2276
2277 /* Convert number NIB to a hex digit. */
2278
2279 static int
2280 tohex (int nib)
2281 {
2282 if (nib < 10)
2283 return '0' + nib;
2284 else
2285 return 'a' + nib - 10;
2286 }
2287 \f
2288 /* Tell the remote machine to resume. */
2289
2290 static enum target_signal last_sent_signal = TARGET_SIGNAL_0;
2291
2292 static int last_sent_step;
2293
2294 static void
2295 remote_resume (int pid, int step, enum target_signal siggnal)
2296 {
2297 char *buf = alloca (PBUFSIZ);
2298
2299 if (pid == -1)
2300 set_thread (0, 0); /* run any thread */
2301 else
2302 set_thread (pid, 0); /* run this thread */
2303
2304 last_sent_signal = siggnal;
2305 last_sent_step = step;
2306
2307 /* A hook for when we need to do something at the last moment before
2308 resumption. */
2309 if (target_resume_hook)
2310 (*target_resume_hook) ();
2311
2312 if (siggnal != TARGET_SIGNAL_0)
2313 {
2314 buf[0] = step ? 'S' : 'C';
2315 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2316 buf[2] = tohex ((int) siggnal & 0xf);
2317 buf[3] = '\0';
2318 }
2319 else
2320 strcpy (buf, step ? "s" : "c");
2321
2322 putpkt (buf);
2323 }
2324
2325 /* Same as remote_resume, but with async support. */
2326 static void
2327 remote_async_resume (int pid, int step, enum target_signal siggnal)
2328 {
2329 char *buf = alloca (PBUFSIZ);
2330
2331 if (pid == -1)
2332 set_thread (0, 0); /* run any thread */
2333 else
2334 set_thread (pid, 0); /* run this thread */
2335
2336 last_sent_signal = siggnal;
2337 last_sent_step = step;
2338
2339 /* A hook for when we need to do something at the last moment before
2340 resumption. */
2341 if (target_resume_hook)
2342 (*target_resume_hook) ();
2343
2344 if (siggnal != TARGET_SIGNAL_0)
2345 {
2346 buf[0] = step ? 'S' : 'C';
2347 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2348 buf[2] = tohex ((int) siggnal & 0xf);
2349 buf[3] = '\0';
2350 }
2351 else
2352 strcpy (buf, step ? "s" : "c");
2353
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;
2370 putpkt (buf);
2371 }
2372 \f
2373
2374 /* Set up the signal handler for SIGINT, while the target is
2375 executing, ovewriting the 'regular' SIGINT signal handler. */
2376 static void
2377 initialize_sigint_signal_handler (void)
2378 {
2379 sigint_remote_token =
2380 create_async_signal_handler (async_remote_interrupt, NULL);
2381 signal (SIGINT, handle_remote_sigint);
2382 }
2383
2384 /* Signal handler for SIGINT, while the target is executing. */
2385 static void
2386 handle_remote_sigint (int sig)
2387 {
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);
2392 }
2393
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
2396 a ^C. */
2397 static void
2398 handle_remote_sigint_twice (int sig)
2399 {
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);
2404 }
2405
2406 /* Perform the real interruption of the target execution, in response
2407 to a ^C. */
2408 static void
2409 async_remote_interrupt (gdb_client_data arg)
2410 {
2411 if (remote_debug)
2412 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2413
2414 target_stop ();
2415 }
2416
2417 /* Perform interrupt, if the first attempt did not succeed. Just give
2418 up on the target alltogether. */
2419 void
2420 async_remote_interrupt_twice (gdb_client_data arg)
2421 {
2422 if (remote_debug)
2423 fprintf_unfiltered (gdb_stdlog, "remote_interrupt_twice called\n");
2424 /* Do something only if the target was not killed by the previous
2425 cntl-C. */
2426 if (target_executing)
2427 {
2428 interrupt_query ();
2429 signal (SIGINT, handle_remote_sigint);
2430 }
2431 }
2432
2433 /* Reinstall the usual SIGINT handlers, after the target has
2434 stopped. */
2435 static void
2436 cleanup_sigint_signal_handler (void *dummy)
2437 {
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);
2443 }
2444
2445 /* Send ^C to target to halt it. Target will respond, and send us a
2446 packet. */
2447 static void (*ofunc) (int);
2448
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. */
2454 static void
2455 remote_interrupt (int signo)
2456 {
2457 /* If this doesn't work, try more severe steps. */
2458 signal (signo, remote_interrupt_twice);
2459
2460 if (remote_debug)
2461 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2462
2463 target_stop ();
2464 }
2465
2466 /* The user typed ^C twice. */
2467
2468 static void
2469 remote_interrupt_twice (int signo)
2470 {
2471 signal (signo, ofunc);
2472 interrupt_query ();
2473 signal (signo, remote_interrupt);
2474 }
2475
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. */
2479 static void
2480 remote_stop (void)
2481 {
2482 /* Send a break or a ^C, depending on user preference. */
2483 if (remote_debug)
2484 fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
2485
2486 if (remote_break)
2487 SERIAL_SEND_BREAK (remote_desc);
2488 else
2489 SERIAL_WRITE (remote_desc, "\003", 1);
2490 }
2491
2492 /* Ask the user what to do when an interrupt is received. */
2493
2494 static void
2495 interrupt_query (void)
2496 {
2497 target_terminal_ours ();
2498
2499 if (query ("Interrupted while waiting for the program.\n\
2500 Give up (and stop debugging it)? "))
2501 {
2502 target_mourn_inferior ();
2503 return_to_top_level (RETURN_QUIT);
2504 }
2505
2506 target_terminal_inferior ();
2507 }
2508
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
2512 is required. */
2513
2514 static void
2515 remote_async_terminal_inferior (void)
2516 {
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)
2523 return;
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)
2531 return;
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. */
2538 }
2539
2540 static void
2541 remote_async_terminal_ours (void)
2542 {
2543 /* See FIXME in remote_async_terminal_inferior. */
2544 if (!sync_execution)
2545 return;
2546 /* See FIXME in remote_async_terminal_inferior. */
2547 if (remote_async_terminal_ours_p)
2548 return;
2549 cleanup_sigint_signal_handler (NULL);
2550 add_file_handler (input_fd, stdin_event_handler, 0);
2551 remote_async_terminal_ours_p = 1;
2552 }
2553
2554 /* If nonzero, ignore the next kill. */
2555
2556 int kill_kludge;
2557
2558 void
2559 remote_console_output (char *msg)
2560 {
2561 char *p;
2562
2563 for (p = msg; p[0] && p[1]; p += 2)
2564 {
2565 char tb[2];
2566 char c = fromhex (p[0]) * 16 + fromhex (p[1]);
2567 tb[0] = c;
2568 tb[1] = 0;
2569 fputs_unfiltered (tb, gdb_stdtarg);
2570 }
2571 gdb_flush (gdb_stdtarg);
2572 }
2573
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. */
2578
2579 static int
2580 remote_wait (int pid, struct target_waitstatus *status)
2581 {
2582 unsigned char *buf = alloca (PBUFSIZ);
2583 int thread_num = -1;
2584
2585 status->kind = TARGET_WAITKIND_EXITED;
2586 status->value.integer = 0;
2587
2588 while (1)
2589 {
2590 unsigned char *p;
2591
2592 ofunc = signal (SIGINT, remote_interrupt);
2593 getpkt (buf, PBUFSIZ, 1);
2594 signal (SIGINT, ofunc);
2595
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) ();
2600
2601 switch (buf[0])
2602 {
2603 case 'E': /* Error of some sort */
2604 warning ("Remote failure reply: %s", buf);
2605 continue;
2606 case 'T': /* Status with PC, SP, FP, ... */
2607 {
2608 int i;
2609 long regno;
2610 char* regs = (char*) alloca (MAX_REGISTER_RAW_SIZE);
2611
2612 /* Expedited reply, containing Signal, {regno, reg} repeat */
2613 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2614 ss = signal number
2615 n... = register number
2616 r... = register contents
2617 */
2618 p = &buf[3]; /* after Txx */
2619
2620 while (*p)
2621 {
2622 unsigned char *p1;
2623 char *p_temp;
2624
2625 /* Read the register number */
2626 regno = strtol ((const char *) p, &p_temp, 16);
2627 p1 = (unsigned char *) p_temp;
2628
2629 if (p1 == p) /* No register number present here */
2630 {
2631 p1 = (unsigned char *) strchr ((const char *) p, ':');
2632 if (p1 == NULL)
2633 warning ("Malformed packet(a) (missing colon): %s\n\
2634 Packet: '%s'\n",
2635 p, buf);
2636 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2637 {
2638 p_temp = unpack_varlen_hex (++p1, &thread_num);
2639 record_currthread (thread_num);
2640 p = (unsigned char *) p_temp;
2641 }
2642 }
2643 else
2644 {
2645 p = p1;
2646
2647 if (*p++ != ':')
2648 warning ("Malformed packet(b) (missing colon): %s\n\
2649 Packet: '%s'\n",
2650 p, buf);
2651
2652 if (regno >= NUM_REGS)
2653 warning ("Remote sent bad register number %ld: %s\n\
2654 Packet: '%s'\n",
2655 regno, p, buf);
2656
2657 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2658 {
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]);
2662 p += 2;
2663 }
2664 supply_register (regno, regs);
2665 }
2666
2667 if (*p++ != ';')
2668 {
2669 warning ("Remote register badly formatted: %s", buf);
2670 warning (" here: %s", p);
2671 }
2672 }
2673 }
2674 /* fall through */
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])));
2679
2680 if (buf[3] == 'p')
2681 {
2682 /* Export Cisco kernel mode as a convenience variable
2683 (so that it can be used in the GDB prompt if desired). */
2684
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);
2691 }
2692 else if (buf[3] == 'k')
2693 {
2694 /* Export Cisco kernel mode as a convenience variable
2695 (so that it can be used in the GDB prompt if desired). */
2696
2697 if (cisco_kernel_mode == 1)
2698 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2699 value_from_string ("KDEBUG-"));
2700 cisco_kernel_mode = 1;
2701 }
2702 goto got_status;
2703 case 'N': /* Cisco special: status and offsets */
2704 {
2705 bfd_vma text_addr, data_addr, bss_addr;
2706 bfd_signed_vma text_off, data_off, bss_off;
2707 unsigned char *p1;
2708
2709 status->kind = TARGET_WAITKIND_STOPPED;
2710 status->value.sig = (enum target_signal)
2711 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2712
2713 if (symfile_objfile == NULL)
2714 {
2715 warning ("Relocation packet received with no symbol file. \
2716 Packet Dropped");
2717 goto got_status;
2718 }
2719
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. */
2724
2725 p = &buf[3];
2726 text_addr = strtoul (p, (char **) &p1, 16);
2727 if (p1 == p || *p1 != ';')
2728 warning ("Malformed relocation packet: Packet '%s'", buf);
2729 p = p1 + 1;
2730 data_addr = strtoul (p, (char **) &p1, 16);
2731 if (p1 == p || *p1 != ';')
2732 warning ("Malformed relocation packet: Packet '%s'", buf);
2733 p = p1 + 1;
2734 bss_addr = strtoul (p, (char **) &p1, 16);
2735 if (p1 == p)
2736 warning ("Malformed relocation packet: Packet '%s'", buf);
2737
2738 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2739 &text_off, &data_off, &bss_off)
2740 == 0)
2741 if (text_off != 0 || data_off != 0 || bss_off != 0)
2742 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2743
2744 goto got_status;
2745 }
2746 case 'W': /* Target exited */
2747 {
2748 /* The remote process exited. */
2749 status->kind = TARGET_WAITKIND_EXITED;
2750 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2751 goto got_status;
2752 }
2753 case 'X':
2754 status->kind = TARGET_WAITKIND_SIGNALLED;
2755 status->value.sig = (enum target_signal)
2756 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2757 kill_kludge = 1;
2758
2759 goto got_status;
2760 case 'O': /* Console output */
2761 remote_console_output (buf + 1);
2762 continue;
2763 case '\0':
2764 if (last_sent_signal != TARGET_SIGNAL_0)
2765 {
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 ();
2769 printf_filtered
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 ();
2774
2775 strcpy ((char *) buf, last_sent_step ? "s" : "c");
2776 putpkt ((char *) buf);
2777 continue;
2778 }
2779 /* else fallthrough */
2780 default:
2781 warning ("Invalid remote reply: %s", buf);
2782 continue;
2783 }
2784 }
2785 got_status:
2786 if (thread_num != -1)
2787 {
2788 return thread_num;
2789 }
2790 return inferior_pid;
2791 }
2792
2793 /* Async version of remote_wait. */
2794 static int
2795 remote_async_wait (int pid, struct target_waitstatus *status)
2796 {
2797 unsigned char *buf = alloca (PBUFSIZ);
2798 int thread_num = -1;
2799
2800 status->kind = TARGET_WAITKIND_EXITED;
2801 status->value.integer = 0;
2802
2803 while (1)
2804 {
2805 unsigned char *p;
2806
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);
2816
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) ();
2821
2822 switch (buf[0])
2823 {
2824 case 'E': /* Error of some sort */
2825 warning ("Remote failure reply: %s", buf);
2826 continue;
2827 case 'T': /* Status with PC, SP, FP, ... */
2828 {
2829 int i;
2830 long regno;
2831 char* regs = (char*) alloca (MAX_REGISTER_RAW_SIZE);
2832
2833 /* Expedited reply, containing Signal, {regno, reg} repeat */
2834 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2835 ss = signal number
2836 n... = register number
2837 r... = register contents
2838 */
2839 p = &buf[3]; /* after Txx */
2840
2841 while (*p)
2842 {
2843 unsigned char *p1;
2844 char *p_temp;
2845
2846 /* Read the register number */
2847 regno = strtol ((const char *) p, &p_temp, 16);
2848 p1 = (unsigned char *) p_temp;
2849
2850 if (p1 == p) /* No register number present here */
2851 {
2852 p1 = (unsigned char *) strchr ((const char *) p, ':');
2853 if (p1 == NULL)
2854 warning ("Malformed packet(a) (missing colon): %s\n\
2855 Packet: '%s'\n",
2856 p, buf);
2857 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2858 {
2859 p_temp = unpack_varlen_hex (++p1, &thread_num);
2860 record_currthread (thread_num);
2861 p = (unsigned char *) p_temp;
2862 }
2863 }
2864 else
2865 {
2866 p = p1;
2867
2868 if (*p++ != ':')
2869 warning ("Malformed packet(b) (missing colon): %s\n\
2870 Packet: '%s'\n",
2871 p, buf);
2872
2873 if (regno >= NUM_REGS)
2874 warning ("Remote sent bad register number %ld: %s\n\
2875 Packet: '%s'\n",
2876 regno, p, buf);
2877
2878 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2879 {
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]);
2883 p += 2;
2884 }
2885 supply_register (regno, regs);
2886 }
2887
2888 if (*p++ != ';')
2889 {
2890 warning ("Remote register badly formatted: %s", buf);
2891 warning (" here: %s", p);
2892 }
2893 }
2894 }
2895 /* fall through */
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])));
2900
2901 if (buf[3] == 'p')
2902 {
2903 /* Export Cisco kernel mode as a convenience variable
2904 (so that it can be used in the GDB prompt if desired). */
2905
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);
2912 }
2913 else if (buf[3] == 'k')
2914 {
2915 /* Export Cisco kernel mode as a convenience variable
2916 (so that it can be used in the GDB prompt if desired). */
2917
2918 if (cisco_kernel_mode == 1)
2919 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2920 value_from_string ("KDEBUG-"));
2921 cisco_kernel_mode = 1;
2922 }
2923 goto got_status;
2924 case 'N': /* Cisco special: status and offsets */
2925 {
2926 bfd_vma text_addr, data_addr, bss_addr;
2927 bfd_signed_vma text_off, data_off, bss_off;
2928 unsigned char *p1;
2929
2930 status->kind = TARGET_WAITKIND_STOPPED;
2931 status->value.sig = (enum target_signal)
2932 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2933
2934 if (symfile_objfile == NULL)
2935 {
2936 warning ("Relocation packet recieved with no symbol file. \
2937 Packet Dropped");
2938 goto got_status;
2939 }
2940
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. */
2945
2946 p = &buf[3];
2947 text_addr = strtoul (p, (char **) &p1, 16);
2948 if (p1 == p || *p1 != ';')
2949 warning ("Malformed relocation packet: Packet '%s'", buf);
2950 p = p1 + 1;
2951 data_addr = strtoul (p, (char **) &p1, 16);
2952 if (p1 == p || *p1 != ';')
2953 warning ("Malformed relocation packet: Packet '%s'", buf);
2954 p = p1 + 1;
2955 bss_addr = strtoul (p, (char **) &p1, 16);
2956 if (p1 == p)
2957 warning ("Malformed relocation packet: Packet '%s'", buf);
2958
2959 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2960 &text_off, &data_off, &bss_off)
2961 == 0)
2962 if (text_off != 0 || data_off != 0 || bss_off != 0)
2963 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2964
2965 goto got_status;
2966 }
2967 case 'W': /* Target exited */
2968 {
2969 /* The remote process exited. */
2970 status->kind = TARGET_WAITKIND_EXITED;
2971 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2972 goto got_status;
2973 }
2974 case 'X':
2975 status->kind = TARGET_WAITKIND_SIGNALLED;
2976 status->value.sig = (enum target_signal)
2977 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2978 kill_kludge = 1;
2979
2980 goto got_status;
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;
2986 goto got_status;
2987 case '\0':
2988 if (last_sent_signal != TARGET_SIGNAL_0)
2989 {
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 ();
2993 printf_filtered
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 ();
2998
2999 strcpy ((char *) buf, last_sent_step ? "s" : "c");
3000 putpkt ((char *) buf);
3001 continue;
3002 }
3003 /* else fallthrough */
3004 default:
3005 warning ("Invalid remote reply: %s", buf);
3006 continue;
3007 }
3008 }
3009 got_status:
3010 if (thread_num != -1)
3011 {
3012 return thread_num;
3013 }
3014 return inferior_pid;
3015 }
3016
3017 /* Number of bytes of registers this stub implements. */
3018
3019 static int register_bytes_found;
3020
3021 /* Read the remote registers into the block REGS. */
3022 /* Currently we just read all the registers, so we don't use regno. */
3023
3024 /* ARGSUSED */
3025 static void
3026 remote_fetch_registers (int regno)
3027 {
3028 char *buf = alloca (PBUFSIZ);
3029 int i;
3030 char *p;
3031 char *regs = alloca (REGISTER_BYTES);
3032
3033 set_thread (inferior_pid, 1);
3034
3035 sprintf (buf, "g");
3036 remote_send (buf, PBUFSIZ);
3037
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);
3043
3044 /* Unimplemented registers read as all bits zero. */
3045 memset (regs, 0, REGISTER_BYTES);
3046
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 */
3053 {
3054 if (remote_debug)
3055 fprintf_unfiltered (gdb_stdlog,
3056 "Bad register packet; fetching a new packet\n");
3057 getpkt (buf, PBUFSIZ, 0);
3058 }
3059
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. */
3063
3064 p = buf;
3065 for (i = 0; i < REGISTER_BYTES; i++)
3066 {
3067 if (p[0] == 0)
3068 break;
3069 if (p[1] == 0)
3070 {
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. */
3074 goto supply_them;
3075 }
3076 if (p[0] == 'x' && p[1] == 'x')
3077 regs[i] = 0; /* 'x' */
3078 else
3079 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
3080 p += 2;
3081 }
3082
3083 if (i != register_bytes_found)
3084 {
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);
3089 }
3090
3091 supply_them:
3092 for (i = 0; i < NUM_REGS; i++)
3093 {
3094 supply_register (i, &regs[REGISTER_BYTE (i)]);
3095 if (buf[REGISTER_BYTE (i) * 2] == 'x')
3096 set_register_cached (i, -1);
3097 }
3098 }
3099
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
3102 first. */
3103
3104 static void
3105 remote_prepare_to_store (void)
3106 {
3107 /* Make sure the entire registers array is valid. */
3108 switch (remote_protocol_P.support)
3109 {
3110 case PACKET_DISABLE:
3111 case PACKET_SUPPORT_UNKNOWN:
3112 read_register_bytes (0, (char *) NULL, REGISTER_BYTES);
3113 break;
3114 case PACKET_ENABLE:
3115 break;
3116 }
3117 }
3118
3119 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
3120 packet was not recognized. */
3121
3122 static int
3123 store_register_using_P (int regno)
3124 {
3125 /* Try storing a single register. */
3126 char *buf = alloca (PBUFSIZ);
3127 char *regp;
3128 char *p;
3129 int i;
3130
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)
3135 {
3136 *p++ = tohex ((regp[i] >> 4) & 0xf);
3137 *p++ = tohex (regp[i] & 0xf);
3138 }
3139 *p = '\0';
3140 remote_send (buf, PBUFSIZ);
3141
3142 return buf[0] != '\0';
3143 }
3144
3145
3146 /* Store register REGNO, or all registers if REGNO == -1, from the contents
3147 of the register cache buffer. FIXME: ignores errors. */
3148
3149 static void
3150 remote_store_registers (int regno)
3151 {
3152 char *buf = alloca (PBUFSIZ);
3153 int i;
3154 char *p;
3155 char *regs;
3156
3157 set_thread (inferior_pid, 1);
3158
3159 if (regno >= 0)
3160 {
3161 switch (remote_protocol_P.support)
3162 {
3163 case PACKET_DISABLE:
3164 break;
3165 case PACKET_ENABLE:
3166 if (store_register_using_P (regno))
3167 return;
3168 else
3169 error ("Protocol error: P packet not recognized by stub");
3170 case PACKET_SUPPORT_UNKNOWN:
3171 if (store_register_using_P (regno))
3172 {
3173 /* The stub recognized the 'P' packet. Remember this. */
3174 remote_protocol_P.support = PACKET_ENABLE;
3175 return;
3176 }
3177 else
3178 {
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;
3183 break;
3184 }
3185 }
3186 }
3187
3188 buf[0] = 'G';
3189
3190 /* Command describes registers byte by byte,
3191 each byte encoded as two hex characters. */
3192
3193 regs = register_buffer (-1);
3194 p = buf + 1;
3195 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3196 for (i = 0; i < register_bytes_found; i++)
3197 {
3198 *p++ = tohex ((regs[i] >> 4) & 0xf);
3199 *p++ = tohex (regs[i] & 0xf);
3200 }
3201 *p = '\0';
3202
3203 remote_send (buf, PBUFSIZ);
3204 }
3205 \f
3206
3207 /* Return the number of hex digits in num. */
3208
3209 static int
3210 hexnumlen (ULONGEST num)
3211 {
3212 int i;
3213
3214 for (i = 0; num != 0; i++)
3215 num >>= 4;
3216
3217 return max (i, 1);
3218 }
3219
3220 /* Set BUF to the minimum number of hex digits representing NUM. */
3221
3222 static int
3223 hexnumstr (char *buf, ULONGEST num)
3224 {
3225 int len = hexnumlen (num);
3226 return hexnumnstr (buf, num, len);
3227 }
3228
3229
3230 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3231
3232 static int
3233 hexnumnstr (char *buf, ULONGEST num, int width)
3234 {
3235 int i;
3236
3237 buf[width] = '\0';
3238
3239 for (i = width - 1; i >= 0; i--)
3240 {
3241 buf[i] = "0123456789abcdef"[(num & 0xf)];
3242 num >>= 4;
3243 }
3244
3245 return width;
3246 }
3247
3248 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3249
3250 static CORE_ADDR
3251 remote_address_masked (CORE_ADDR addr)
3252 {
3253 if (remote_address_size > 0
3254 && remote_address_size < (sizeof (ULONGEST) * 8))
3255 {
3256 /* Only create a mask when that mask can safely be constructed
3257 in a ULONGEST variable. */
3258 ULONGEST mask = 1;
3259 mask = (mask << remote_address_size) - 1;
3260 addr &= mask;
3261 }
3262 return addr;
3263 }
3264
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.
3270
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
3273 X-packet". */
3274
3275 static void
3276 check_binary_download (CORE_ADDR addr)
3277 {
3278 switch (remote_protocol_binary_download.support)
3279 {
3280 case PACKET_DISABLE:
3281 break;
3282 case PACKET_ENABLE:
3283 break;
3284 case PACKET_SUPPORT_UNKNOWN:
3285 {
3286 char *buf = alloca (PBUFSIZ);
3287 char *p;
3288
3289 p = buf;
3290 *p++ = 'X';
3291 p += hexnumstr (p, (ULONGEST) addr);
3292 *p++ = ',';
3293 p += hexnumstr (p, (ULONGEST) 0);
3294 *p++ = ':';
3295 *p = '\0';
3296
3297 putpkt_binary (buf, (int) (p - buf));
3298 getpkt (buf, PBUFSIZ, 0);
3299
3300 if (buf[0] == '\0')
3301 {
3302 if (remote_debug)
3303 fprintf_unfiltered (gdb_stdlog,
3304 "binary downloading NOT suppported by target\n");
3305 remote_protocol_binary_download.support = PACKET_DISABLE;
3306 }
3307 else
3308 {
3309 if (remote_debug)
3310 fprintf_unfiltered (gdb_stdlog,
3311 "binary downloading suppported by target\n");
3312 remote_protocol_binary_download.support = PACKET_ENABLE;
3313 }
3314 break;
3315 }
3316 }
3317 }
3318
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.
3324
3325 Returns number of bytes transferred, or 0 (setting errno) for
3326 error. Only transfer a single packet. */
3327
3328 static int
3329 remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
3330 {
3331 unsigned char *buf;
3332 int max_buf_size; /* Max size of packet output buffer */
3333 unsigned char *p;
3334 unsigned char *plen;
3335 long sizeof_buf;
3336 int plenlen;
3337 int todo;
3338 int nr_bytes;
3339
3340 /* Verify that the target can support a binary download */
3341 check_binary_download (memaddr);
3342
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);
3347
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;
3350
3351 /* construct "M"<memaddr>","<len>":" */
3352 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3353 p = buf;
3354
3355 /* Append [XM]. Compute a best guess of the number of bytes
3356 actually transfered. */
3357 switch (remote_protocol_binary_download.support)
3358 {
3359 case PACKET_ENABLE:
3360 *p++ = 'X';
3361 /* Best guess at number of bytes that will fit. */
3362 todo = min (len, max_buf_size);
3363 break;
3364 case PACKET_DISABLE:
3365 *p++ = 'M';
3366 /* num bytes that will fit */
3367 todo = min (len, max_buf_size / 2);
3368 break;
3369 case PACKET_SUPPORT_UNKNOWN:
3370 internal_error (__FILE__, __LINE__,
3371 "remote_write_bytes: bad internal state");
3372 default:
3373 internal_error (__FILE__, __LINE__, "bad switch");
3374 }
3375
3376 /* Append <memaddr> */
3377 memaddr = remote_address_masked (memaddr);
3378 p += hexnumstr (p, (ULONGEST) memaddr);
3379 *p++ = ',';
3380
3381 /* Append <len>. Retain the location/size of <len>. It may
3382 need to be adjusted once the packet body has been created. */
3383 plen = p;
3384 plenlen = hexnumstr (p, (ULONGEST) todo);
3385 p += plenlen;
3386 *p++ = ':';
3387 *p = '\0';
3388
3389 /* Append the packet body. */
3390 switch (remote_protocol_binary_download.support)
3391 {
3392 case PACKET_ENABLE:
3393 /* Binary mode. Send target system values byte by byte, in
3394 increasing byte addresses. Only escape certain critical
3395 characters. */
3396 for (nr_bytes = 0;
3397 (nr_bytes < todo) && (p - buf) < (max_buf_size - 2);
3398 nr_bytes++)
3399 {
3400 switch (myaddr[nr_bytes] & 0xff)
3401 {
3402 case '$':
3403 case '#':
3404 case 0x7d:
3405 /* These must be escaped */
3406 *p++ = 0x7d;
3407 *p++ = (myaddr[nr_bytes] & 0xff) ^ 0x20;
3408 break;
3409 default:
3410 *p++ = myaddr[nr_bytes] & 0xff;
3411 break;
3412 }
3413 }
3414 if (nr_bytes < todo)
3415 {
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. */
3420
3421 plen += hexnumnstr (plen, (ULONGEST) nr_bytes, plenlen);
3422 *plen = ':'; /* overwrite \0 from hexnumnstr() */
3423 }
3424 break;
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
3428 value. */
3429 for (nr_bytes = 0; nr_bytes < todo; nr_bytes++)
3430 {
3431 *p++ = tohex ((myaddr[nr_bytes] >> 4) & 0xf);
3432 *p++ = tohex (myaddr[nr_bytes] & 0xf);
3433 }
3434 *p = '\0';
3435 break;
3436 case PACKET_SUPPORT_UNKNOWN:
3437 internal_error (__FILE__, __LINE__,
3438 "remote_write_bytes: bad internal state");
3439 default:
3440 internal_error (__FILE__, __LINE__, "bad switch");
3441 }
3442
3443 putpkt_binary (buf, (int) (p - buf));
3444 getpkt (buf, sizeof_buf, 0);
3445
3446 if (buf[0] == 'E')
3447 {
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. */
3452 errno = EIO;
3453 return 0;
3454 }
3455
3456 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3457 bytes than we'd planned. */
3458 return nr_bytes;
3459 }
3460
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.
3466
3467 Returns number of bytes transferred, or 0 for error. */
3468
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. */
3475
3476 static int
3477 remote_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
3478 {
3479 char *buf;
3480 int max_buf_size; /* Max size of packet output buffer */
3481 long sizeof_buf;
3482 int origlen;
3483
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);
3488
3489 origlen = len;
3490 while (len > 0)
3491 {
3492 char *p;
3493 int todo;
3494 int i;
3495
3496 todo = min (len, max_buf_size / 2); /* num bytes that will fit */
3497
3498 /* construct "m"<memaddr>","<len>" */
3499 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3500 memaddr = remote_address_masked (memaddr);
3501 p = buf;
3502 *p++ = 'm';
3503 p += hexnumstr (p, (ULONGEST) memaddr);
3504 *p++ = ',';
3505 p += hexnumstr (p, (ULONGEST) todo);
3506 *p = '\0';
3507
3508 putpkt (buf);
3509 getpkt (buf, sizeof_buf, 0);
3510
3511 if (buf[0] == 'E')
3512 {
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. */
3517 errno = EIO;
3518 return 0;
3519 }
3520
3521 /* Reply describes memory byte by byte,
3522 each byte encoded as two hex characters. */
3523
3524 p = buf;
3525 for (i = 0; i < todo; i++)
3526 {
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]);
3532 p += 2;
3533 }
3534 myaddr += todo;
3535 memaddr += todo;
3536 len -= todo;
3537 }
3538 return origlen;
3539 }
3540 \f
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. */
3545
3546 /* ARGSUSED */
3547 static int
3548 remote_xfer_memory (CORE_ADDR mem_addr, char *buffer, int mem_len,
3549 int should_write,
3550 struct mem_attrib *attrib ATTRIBUTE_UNUSED,
3551 struct target_ops *target)
3552 {
3553 CORE_ADDR targ_addr;
3554 int targ_len;
3555 int res;
3556
3557 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr, mem_len, &targ_addr, &targ_len);
3558 if (targ_len <= 0)
3559 return 0;
3560
3561 if (should_write)
3562 res = remote_write_bytes (targ_addr, buffer, targ_len);
3563 else
3564 res = remote_read_bytes (targ_addr, buffer, targ_len);
3565
3566 return res;
3567 }
3568
3569
3570 #if 0
3571 /* Enable after 4.12. */
3572
3573 void
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)
3577 {
3578 if (increment == -4 && len == 4)
3579 {
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];
3585 char *p;
3586
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);
3590 putpkt (buf);
3591 getpkt (buf, PBUFSIZ, 0);
3592 if (buf[0] == '\0')
3593 {
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);
3600 return;
3601 }
3602
3603 if (buf[0] == 'E')
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);
3609 p = buf;
3610 addr_we_found = 0;
3611 while (*p != '\0' && *p != ',')
3612 addr_we_found = (addr_we_found << 4) + fromhex (*p++);
3613 if (*p == '\0')
3614 error ("Protocol error: short return for search");
3615
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. */
3620
3621 if (addr_we_found < lorange || addr_we_found >= hirange)
3622 {
3623 *addr_found = 0;
3624 return;
3625 }
3626
3627 *addr_found = addr_we_found;
3628 *data_found = store_unsigned_integer (data_we_found, len);
3629 return;
3630 }
3631 generic_search (len, data, mask, startaddr, increment, lorange,
3632 hirange, addr_found, data_found);
3633 }
3634 #endif /* 0 */
3635 \f
3636 static void
3637 remote_files_info (struct target_ops *ignore)
3638 {
3639 puts_filtered ("Debugging a target over a serial line.\n");
3640 }
3641 \f
3642 /* Stuff for dealing with the packets which are part of this protocol.
3643 See comment at top of file for details. */
3644
3645 /* Read a single character from the remote end, masking it down to 7 bits. */
3646
3647 static int
3648 readchar (int timeout)
3649 {
3650 int ch;
3651
3652 ch = SERIAL_READCHAR (remote_desc, timeout);
3653
3654 if (ch >= 0)
3655 return (ch & 0x7f);
3656
3657 switch ((enum serial_rc) ch)
3658 {
3659 case SERIAL_EOF:
3660 target_mourn_inferior ();
3661 error ("Remote connection closed");
3662 /* no return */
3663 case SERIAL_ERROR:
3664 perror_with_name ("Remote communication error");
3665 /* no return */
3666 case SERIAL_TIMEOUT:
3667 break;
3668 }
3669 return ch;
3670 }
3671
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. */
3674
3675 static void
3676 remote_send (char *buf,
3677 long sizeof_buf)
3678 {
3679 putpkt (buf);
3680 getpkt (buf, sizeof_buf, 0);
3681
3682 if (buf[0] == 'E')
3683 error ("Remote failure reply: %s", buf);
3684 }
3685
3686 /* Display a null-terminated packet on stdout, for debugging, using C
3687 string notation. */
3688
3689 static void
3690 print_packet (char *buf)
3691 {
3692 puts_filtered ("\"");
3693 fputstr_filtered (buf, '"', gdb_stdout);
3694 puts_filtered ("\"");
3695 }
3696
3697 int
3698 putpkt (char *buf)
3699 {
3700 return putpkt_binary (buf, strlen (buf));
3701 }
3702
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 */
3707
3708 static int
3709 putpkt_binary (char *buf, int cnt)
3710 {
3711 int i;
3712 unsigned char csum = 0;
3713 char *buf2 = alloca (cnt + 6);
3714 long sizeof_junkbuf = PBUFSIZ;
3715 char *junkbuf = alloca (sizeof_junkbuf);
3716
3717 int ch;
3718 int tcount = 0;
3719 char *p;
3720
3721 /* Copy the packet into buffer BUF2, encapsulating it
3722 and giving it a checksum. */
3723
3724 p = buf2;
3725 *p++ = '$';
3726
3727 for (i = 0; i < cnt; i++)
3728 {
3729 csum += buf[i];
3730 *p++ = buf[i];
3731 }
3732 *p++ = '#';
3733 *p++ = tohex ((csum >> 4) & 0xf);
3734 *p++ = tohex (csum & 0xf);
3735
3736 /* Send it over and over until we get a positive ack. */
3737
3738 while (1)
3739 {
3740 int started_error_output = 0;
3741
3742 if (remote_debug)
3743 {
3744 *p = '\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);
3749 }
3750 if (SERIAL_WRITE (remote_desc, buf2, p - buf2))
3751 perror_with_name ("putpkt: write failed");
3752
3753 /* read until either a timeout occurs (-2) or '+' is read */
3754 while (1)
3755 {
3756 ch = readchar (remote_timeout);
3757
3758 if (remote_debug)
3759 {
3760 switch (ch)
3761 {
3762 case '+':
3763 case '-':
3764 case SERIAL_TIMEOUT:
3765 case '$':
3766 if (started_error_output)
3767 {
3768 putchar_unfiltered ('\n');
3769 started_error_output = 0;
3770 }
3771 }
3772 }
3773
3774 switch (ch)
3775 {
3776 case '+':
3777 if (remote_debug)
3778 fprintf_unfiltered (gdb_stdlog, "Ack\n");
3779 return 1;
3780 case '-':
3781 if (remote_debug)
3782 fprintf_unfiltered (gdb_stdlog, "Nak\n");
3783 case SERIAL_TIMEOUT:
3784 tcount++;
3785 if (tcount > 3)
3786 return 0;
3787 break; /* Retransmit buffer */
3788 case '$':
3789 {
3790 if (remote_debug)
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 + */
3796 }
3797 default:
3798 if (remote_debug)
3799 {
3800 if (!started_error_output)
3801 {
3802 started_error_output = 1;
3803 fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
3804 }
3805 fputc_unfiltered (ch & 0177, gdb_stdlog);
3806 }
3807 continue;
3808 }
3809 break; /* Here to retransmit */
3810 }
3811
3812 #if 0
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. */
3818 if (quit_flag)
3819 {
3820 quit_flag = 0;
3821 interrupt_query ();
3822 }
3823 #endif
3824 }
3825 }
3826
3827 static int remote_cisco_mode;
3828
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.
3833
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). */
3837
3838 static long
3839 read_frame (char *buf,
3840 long sizeof_buf)
3841 {
3842 unsigned char csum;
3843 long bc;
3844 int c;
3845
3846 csum = 0;
3847 bc = 0;
3848
3849 while (1)
3850 {
3851 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
3852 c = readchar (remote_timeout);
3853 switch (c)
3854 {
3855 case SERIAL_TIMEOUT:
3856 if (remote_debug)
3857 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
3858 return -1;
3859 case '$':
3860 if (remote_debug)
3861 fputs_filtered ("Saw new packet start in middle of old one\n",
3862 gdb_stdlog);
3863 return -1; /* Start a new packet, count retries */
3864 case '#':
3865 {
3866 unsigned char pktcsum;
3867 int check_0 = 0;
3868 int check_1 = 0;
3869
3870 buf[bc] = '\0';
3871
3872 check_0 = readchar (remote_timeout);
3873 if (check_0 >= 0)
3874 check_1 = readchar (remote_timeout);
3875
3876 if (check_0 == SERIAL_TIMEOUT || check_1 == SERIAL_TIMEOUT)
3877 {
3878 if (remote_debug)
3879 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog);
3880 return -1;
3881 }
3882 else if (check_0 < 0 || check_1 < 0)
3883 {
3884 if (remote_debug)
3885 fputs_filtered ("Communication error in checksum\n", gdb_stdlog);
3886 return -1;
3887 }
3888
3889 pktcsum = (fromhex (check_0) << 4) | fromhex (check_1);
3890 if (csum == pktcsum)
3891 return bc;
3892
3893 if (remote_debug)
3894 {
3895 fprintf_filtered (gdb_stdlog,
3896 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3897 pktcsum, csum);
3898 fputs_filtered (buf, gdb_stdlog);
3899 fputs_filtered ("\n", gdb_stdlog);
3900 }
3901 /* Number of characters in buffer ignoring trailing
3902 NUL. */
3903 return -1;
3904 }
3905 case '*': /* Run length encoding */
3906 {
3907 int repeat;
3908 csum += c;
3909
3910 if (remote_cisco_mode == 0)
3911 {
3912 c = readchar (remote_timeout);
3913 csum += c;
3914 repeat = c - ' ' + 3; /* Compute repeat count */
3915 }
3916 else
3917 {
3918 /* Cisco's run-length encoding variant uses two
3919 hex chars to represent the repeat count. */
3920
3921 c = readchar (remote_timeout);
3922 csum += c;
3923 repeat = fromhex (c) << 4;
3924 c = readchar (remote_timeout);
3925 csum += c;
3926 repeat += fromhex (c);
3927 }
3928
3929 /* The character before ``*'' is repeated. */
3930
3931 if (repeat > 0 && repeat <= 255
3932 && bc > 0
3933 && bc + repeat < sizeof_buf - 1)
3934 {
3935 memset (&buf[bc], buf[bc - 1], repeat);
3936 bc += repeat;
3937 continue;
3938 }
3939
3940 buf[bc] = '\0';
3941 printf_filtered ("Repeat count %d too large for buffer: ", repeat);
3942 puts_filtered (buf);
3943 puts_filtered ("\n");
3944 return -1;
3945 }
3946 default:
3947 if (bc < sizeof_buf - 1)
3948 {
3949 buf[bc++] = c;
3950 csum += c;
3951 continue;
3952 }
3953
3954 buf[bc] = '\0';
3955 puts_filtered ("Remote packet too long: ");
3956 puts_filtered (buf);
3957 puts_filtered ("\n");
3958
3959 return -1;
3960 }
3961 }
3962 }
3963
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. */
3972 void
3973 getpkt (char *buf,
3974 long sizeof_buf,
3975 int forever)
3976 {
3977 int timed_out;
3978
3979 timed_out = getpkt_sane (buf, sizeof_buf, forever);
3980 }
3981
3982
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
3988 the caller. */
3989 int
3990 getpkt_sane (char *buf,
3991 long sizeof_buf,
3992 int forever)
3993 {
3994 int c;
3995 int tries;
3996 int timeout;
3997 int val;
3998
3999 strcpy (buf, "timeout");
4000
4001 if (forever)
4002 {
4003 timeout = watchdog > 0 ? watchdog : -1;
4004 }
4005
4006 else
4007 timeout = remote_timeout;
4008
4009 #define MAX_TRIES 3
4010
4011 for (tries = 1; tries <= MAX_TRIES; tries++)
4012 {
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. */
4016
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. */
4020
4021 do
4022 {
4023 c = readchar (timeout);
4024
4025 if (c == SERIAL_TIMEOUT)
4026 {
4027 if (forever) /* Watchdog went off? Kill the target. */
4028 {
4029 QUIT;
4030 target_mourn_inferior ();
4031 error ("Watchdog has expired. Target detached.\n");
4032 }
4033 if (remote_debug)
4034 fputs_filtered ("Timed out.\n", gdb_stdlog);
4035 goto retry;
4036 }
4037 }
4038 while (c != '$');
4039
4040 /* We've found the start of a packet, now collect the data. */
4041
4042 val = read_frame (buf, sizeof_buf);
4043
4044 if (val >= 0)
4045 {
4046 if (remote_debug)
4047 {
4048 fprintf_unfiltered (gdb_stdlog, "Packet received: ");
4049 fputstr_unfiltered (buf, 0, gdb_stdlog);
4050 fprintf_unfiltered (gdb_stdlog, "\n");
4051 }
4052 SERIAL_WRITE (remote_desc, "+", 1);
4053 return 0;
4054 }
4055
4056 /* Try the whole thing again. */
4057 retry:
4058 SERIAL_WRITE (remote_desc, "-", 1);
4059 }
4060
4061 /* We have tried hard enough, and just can't receive the packet. Give up. */
4062
4063 printf_unfiltered ("Ignoring packet error, continuing...\n");
4064 SERIAL_WRITE (remote_desc, "+", 1);
4065 return 1;
4066 }
4067 \f
4068 static void
4069 remote_kill (void)
4070 {
4071 /* For some mysterious reason, wait_for_inferior calls kill instead of
4072 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4073 if (kill_kludge)
4074 {
4075 kill_kludge = 0;
4076 target_mourn_inferior ();
4077 return;
4078 }
4079
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);
4083
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 ();
4087 }
4088
4089 /* Async version of remote_kill. */
4090 static void
4091 remote_async_kill (void)
4092 {
4093 /* Unregister the file descriptor from the event loop. */
4094 if (target_is_async_p ())
4095 SERIAL_ASYNC (remote_desc, NULL, 0);
4096
4097 /* For some mysterious reason, wait_for_inferior calls kill instead of
4098 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4099 if (kill_kludge)
4100 {
4101 kill_kludge = 0;
4102 target_mourn_inferior ();
4103 return;
4104 }
4105
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);
4109
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 ();
4113 }
4114
4115 static void
4116 remote_mourn (void)
4117 {
4118 remote_mourn_1 (&remote_ops);
4119 }
4120
4121 static void
4122 remote_async_mourn (void)
4123 {
4124 remote_mourn_1 (&remote_async_ops);
4125 }
4126
4127 static void
4128 extended_remote_mourn (void)
4129 {
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.
4133
4134 FIXME: What is the right thing to do here? */
4135 #if 0
4136 remote_mourn_1 (&extended_remote_ops);
4137 #endif
4138 }
4139
4140 /* Worker function for remote_mourn. */
4141 static void
4142 remote_mourn_1 (struct target_ops *target)
4143 {
4144 unpush_target (target);
4145 generic_mourn_inferior ();
4146 }
4147
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.
4151
4152 FIXME: One day add support for changing the exec file
4153 we're debugging, arguments and an environment. */
4154
4155 static void
4156 extended_remote_create_inferior (char *exec_file, char *args, char **env)
4157 {
4158 /* Rip out the breakpoints; we'll reinsert them after restarting
4159 the remote server. */
4160 remove_breakpoints ();
4161
4162 /* Now restart the remote server. */
4163 extended_remote_restart ();
4164
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 ();
4168
4169 /* Clean up from the last time we were running. */
4170 clear_proceed_status ();
4171
4172 /* Let the remote process run. */
4173 proceed (-1, TARGET_SIGNAL_0, 0);
4174 }
4175
4176 /* Async version of extended_remote_create_inferior. */
4177 static void
4178 extended_remote_async_create_inferior (char *exec_file, char *args, char **env)
4179 {
4180 /* Rip out the breakpoints; we'll reinsert them after restarting
4181 the remote server. */
4182 remove_breakpoints ();
4183
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);
4188
4189 /* Now restart the remote server. */
4190 extended_remote_restart ();
4191
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 ();
4195
4196 /* Clean up from the last time we were running. */
4197 clear_proceed_status ();
4198
4199 /* Let the remote process run. */
4200 proceed (-1, TARGET_SIGNAL_0, 0);
4201 }
4202 \f
4203
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. */
4209
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. */
4214
4215 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4216 #define REMOTE_BREAKPOINT
4217 #endif
4218
4219 #ifdef REMOTE_BREAKPOINT
4220
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
4225 #endif
4226
4227 static unsigned char big_break_insn[] = BIG_REMOTE_BREAKPOINT;
4228 static unsigned char little_break_insn[] = LITTLE_REMOTE_BREAKPOINT;
4229
4230 #endif /* REMOTE_BREAKPOINT */
4231
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). */
4239
4240 static int
4241 remote_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
4242 {
4243 #ifdef REMOTE_BREAKPOINT
4244 int val;
4245 #endif
4246 int bp_size;
4247
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. */
4252
4253 if (remote_protocol_Z[Z_PACKET_SOFTWARE_BP].support != PACKET_DISABLE)
4254 {
4255 char *buf = alloca (PBUFSIZ);
4256 char *p = buf;
4257
4258 addr = remote_address_masked (addr);
4259 *(p++) = 'Z';
4260 *(p++) = '0';
4261 *(p++) = ',';
4262 p += hexnumstr (p, (ULONGEST) addr);
4263 BREAKPOINT_FROM_PC (&addr, &bp_size);
4264 sprintf (p, ",%d", bp_size);
4265
4266 putpkt (buf);
4267 getpkt (buf, PBUFSIZ, 0);
4268
4269 switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_SOFTWARE_BP]))
4270 {
4271 case PACKET_ERROR:
4272 return -1;
4273 case PACKET_OK:
4274 return 0;
4275 case PACKET_UNKNOWN:
4276 break;
4277 }
4278 }
4279
4280 #ifdef REMOTE_BREAKPOINT
4281 val = target_read_memory (addr, contents_cache, sizeof big_break_insn);
4282
4283 if (val == 0)
4284 {
4285 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
4286 val = target_write_memory (addr, (char *) big_break_insn,
4287 sizeof big_break_insn);
4288 else
4289 val = target_write_memory (addr, (char *) little_break_insn,
4290 sizeof little_break_insn);
4291 }
4292
4293 return val;
4294 #else
4295 return memory_insert_breakpoint (addr, contents_cache);
4296 #endif /* REMOTE_BREAKPOINT */
4297 }
4298
4299 static int
4300 remote_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
4301 {
4302 int bp_size;
4303
4304 if (remote_protocol_Z[Z_PACKET_SOFTWARE_BP].support != PACKET_DISABLE)
4305 {
4306 char *buf = alloca (PBUFSIZ);
4307 char *p = buf;
4308
4309 *(p++) = 'z';
4310 *(p++) = '0';
4311 *(p++) = ',';
4312
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);
4317
4318 putpkt (buf);
4319 getpkt (buf, PBUFSIZ, 0);
4320
4321 return (buf[0] == 'E');
4322 }
4323
4324 #ifdef REMOTE_BREAKPOINT
4325 return target_write_memory (addr, contents_cache, sizeof big_break_insn);
4326 #else
4327 return memory_remove_breakpoint (addr, contents_cache);
4328 #endif /* REMOTE_BREAKPOINT */
4329 }
4330
4331 static int
4332 watchpoint_to_Z_packet (int type)
4333 {
4334 switch (type)
4335 {
4336 case hw_write:
4337 return 2;
4338 break;
4339 case hw_read:
4340 return 3;
4341 break;
4342 case hw_access:
4343 return 4;
4344 break;
4345 default:
4346 internal_error (__FILE__, __LINE__,
4347 "hw_bp_to_z: bad watchpoint type %d", type);
4348 }
4349 }
4350
4351 /* FIXME: This function should be static and a member of the remote
4352 target vector. */
4353
4354 int
4355 remote_insert_watchpoint (CORE_ADDR addr, int len, int type)
4356 {
4357 char *buf = alloca (PBUFSIZ);
4358 char *p;
4359 enum Z_packet_type packet = watchpoint_to_Z_packet (type);
4360
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);
4365
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);
4371
4372 putpkt (buf);
4373 getpkt (buf, PBUFSIZ, 0);
4374
4375 switch (packet_ok (buf, &remote_protocol_Z[packet]))
4376 {
4377 case PACKET_ERROR:
4378 case PACKET_UNKNOWN:
4379 return -1;
4380 case PACKET_OK:
4381 return 0;
4382 }
4383 internal_error (__FILE__, __LINE__,
4384 "remote_insert_watchpoint: reached end of function");
4385 }
4386
4387 /* FIXME: This function should be static and a member of the remote
4388 target vector. */
4389
4390 int
4391 remote_remove_watchpoint (CORE_ADDR addr, int len, int type)
4392 {
4393 char *buf = alloca (PBUFSIZ);
4394 char *p;
4395 enum Z_packet_type packet = watchpoint_to_Z_packet (type);
4396
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);
4401
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);
4407 putpkt (buf);
4408 getpkt (buf, PBUFSIZ, 0);
4409
4410 switch (packet_ok (buf, &remote_protocol_Z[packet]))
4411 {
4412 case PACKET_ERROR:
4413 case PACKET_UNKNOWN:
4414 return -1;
4415 case PACKET_OK:
4416 return 0;
4417 }
4418 internal_error (__FILE__, __LINE__,
4419 "remote_remove_watchpoint: reached end of function");
4420 }
4421
4422 /* FIXME: This function should be static and a member of the remote
4423 target vector. */
4424
4425 int
4426 remote_insert_hw_breakpoint (CORE_ADDR addr, int len)
4427 {
4428 char *buf = alloca (PBUFSIZ);
4429 char *p = buf;
4430
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);
4435
4436 *(p++) = 'Z';
4437 *(p++) = '1';
4438 *(p++) = ',';
4439
4440 addr = remote_address_masked (addr);
4441 p += hexnumstr (p, (ULONGEST) addr);
4442 sprintf (p, ",%x", len);
4443
4444 putpkt (buf);
4445 getpkt (buf, PBUFSIZ, 0);
4446
4447 switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP]))
4448 {
4449 case PACKET_ERROR:
4450 case PACKET_UNKNOWN:
4451 return -1;
4452 case PACKET_OK:
4453 return 0;
4454 }
4455 internal_error (__FILE__, __LINE__,
4456 "remote_remove_watchpoint: reached end of function");
4457 }
4458
4459 /* FIXME: This function should be static and a member of the remote
4460 target vector. */
4461
4462 int
4463 remote_remove_hw_breakpoint (CORE_ADDR addr, int len)
4464 {
4465 char *buf = alloca (PBUFSIZ);
4466 char *p = buf;
4467
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);
4472
4473 *(p++) = 'z';
4474 *(p++) = '1';
4475 *(p++) = ',';
4476
4477 addr = remote_address_masked (addr);
4478 p += hexnumstr (p, (ULONGEST) addr);
4479 sprintf (p, ",%x", len);
4480
4481 putpkt(buf);
4482 getpkt (buf, PBUFSIZ, 0);
4483
4484 switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP]))
4485 {
4486 case PACKET_ERROR:
4487 case PACKET_UNKNOWN:
4488 return -1;
4489 case PACKET_OK:
4490 return 0;
4491 }
4492 internal_error (__FILE__, __LINE__,
4493 "remote_remove_watchpoint: reached end of function");
4494 }
4495
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.
4501
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. */
4505
4506 void
4507 push_remote_target (char *name, int from_tty)
4508 {
4509 printf_filtered ("Switching to remote protocol\n");
4510 remote_open (name, from_tty);
4511 }
4512
4513 /* Other targets want to use the entire remote serial module but with
4514 certain remote_ops overridden. */
4515
4516 void
4517 open_remote_target (char *name, int from_tty, struct target_ops *target,
4518 int extended_p)
4519 {
4520 printf_filtered ("Selecting the %sremote protocol\n",
4521 (extended_p ? "extended-" : ""));
4522 remote_open_1 (name, from_tty, target, extended_p);
4523 }
4524
4525 /* Table used by the crc32 function to calcuate the checksum. */
4526
4527 static unsigned long crc32_table[256] =
4528 {0, 0};
4529
4530 static unsigned long
4531 crc32 (unsigned char *buf, int len, unsigned int crc)
4532 {
4533 if (!crc32_table[1])
4534 {
4535 /* Initialize the CRC table and the decoding table. */
4536 int i, j;
4537 unsigned int c;
4538
4539 for (i = 0; i < 256; i++)
4540 {
4541 for (c = i << 24, j = 8; j > 0; --j)
4542 c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
4543 crc32_table[i] = c;
4544 }
4545 }
4546
4547 while (len--)
4548 {
4549 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255];
4550 buf++;
4551 }
4552 return crc;
4553 }
4554
4555 /* compare-sections command
4556
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. */
4561
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. */
4566
4567 static void
4568 compare_sections_command (char *args, int from_tty)
4569 {
4570 asection *s;
4571 unsigned long host_crc, target_crc;
4572 extern bfd *exec_bfd;
4573 struct cleanup *old_chain;
4574 char *tmp;
4575 char *sectdata;
4576 char *sectname;
4577 char *buf = alloca (PBUFSIZ);
4578 bfd_size_type size;
4579 bfd_vma lma;
4580 int matched = 0;
4581 int mismatched = 0;
4582
4583 if (!exec_bfd)
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");
4588
4589 for (s = exec_bfd->sections; s; s = s->next)
4590 {
4591 if (!(s->flags & SEC_LOAD))
4592 continue; /* skip non-loadable section */
4593
4594 size = bfd_get_section_size_before_reloc (s);
4595 if (size == 0)
4596 continue; /* skip zero-length section */
4597
4598 sectname = (char *) bfd_get_section_name (exec_bfd, s);
4599 if (args && strcmp (args, sectname) != 0)
4600 continue; /* not the section selected by user */
4601
4602 matched = 1; /* do this section */
4603 lma = s->lma;
4604 /* FIXME: assumes lma can fit into long */
4605 sprintf (buf, "qCRC:%lx,%lx", (long) lma, (long) size);
4606 putpkt (buf);
4607
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);
4613
4614 getpkt (buf, PBUFSIZ, 0);
4615 if (buf[0] == 'E')
4616 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4617 sectname, lma, lma + size);
4618 if (buf[0] != 'C')
4619 error ("remote target does not support this operation");
4620
4621 for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++)
4622 target_crc = target_crc * 16 + fromhex (*tmp);
4623
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");
4628 else
4629 {
4630 printf_filtered ("MIS-MATCHED!\n");
4631 mismatched++;
4632 }
4633
4634 do_cleanups (old_chain);
4635 }
4636 if (mismatched > 0)
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);
4641 }
4642
4643 static int
4644 remote_query (int query_type, char *buf, char *outbuf, int *bufsiz)
4645 {
4646 int i;
4647 char *buf2 = alloca (PBUFSIZ);
4648 char *p2 = &buf2[0];
4649
4650 if (!bufsiz)
4651 error ("null pointer to remote bufer size specified");
4652
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)
4657 {
4658 *bufsiz = PBUFSIZ;
4659 return -1;
4660 }
4661
4662 /* except for querying the minimum buffer size, target must be open */
4663 if (!remote_desc)
4664 error ("remote query is only available after target open");
4665
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");
4669
4670 if (!buf)
4671 error ("null remote query specified");
4672
4673 if (!outbuf)
4674 error ("remote query requires a buffer to receive data");
4675
4676 outbuf[0] = '\0';
4677
4678 *p2++ = 'q';
4679 *p2++ = query_type;
4680
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 */
4685 i = 0;
4686 while (buf[i] && (i < (PBUFSIZ - 8)))
4687 {
4688 /* bad caller may have sent forbidden characters */
4689 if ((!isprint (buf[i])) || (buf[i] == '$') || (buf[i] == '#'))
4690 error ("illegal characters in query string");
4691
4692 *p2++ = buf[i];
4693 i++;
4694 }
4695 *p2 = buf[i];
4696
4697 if (buf[i])
4698 error ("query larger than available buffer");
4699
4700 i = putpkt (buf2);
4701 if (i < 0)
4702 return i;
4703
4704 getpkt (outbuf, *bufsiz, 0);
4705
4706 return 0;
4707 }
4708
4709 static void
4710 remote_rcmd (char *command,
4711 struct ui_file *outbuf)
4712 {
4713 int i;
4714 char *buf = alloca (PBUFSIZ);
4715 char *p = buf;
4716
4717 if (!remote_desc)
4718 error ("remote rcmd is only available after target open");
4719
4720 /* Send a NULL command across as an empty command */
4721 if (command == NULL)
4722 command = "";
4723
4724 /* The query prefix */
4725 strcpy (buf, "qRcmd,");
4726 p = strchr (buf, '\0');
4727
4728 if ((strlen (buf) + strlen (command) * 2 + 8/*misc*/) > PBUFSIZ)
4729 error ("\"monitor\" command ``%s'' is too long\n", command);
4730
4731 /* Encode the actual command */
4732 for (i = 0; command[i]; i++)
4733 {
4734 *p++ = tohex ((command[i] >> 4) & 0xf);
4735 *p++ = tohex (command[i] & 0xf);
4736 }
4737 *p = '\0';
4738
4739 if (putpkt (buf) < 0)
4740 error ("Communication problem with target\n");
4741
4742 /* get/display the response */
4743 while (1)
4744 {
4745 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4746 buf[0] = '\0';
4747 getpkt (buf, PBUFSIZ, 0);
4748 if (buf[0] == '\0')
4749 error ("Target does not support this command\n");
4750 if (buf[0] == 'O' && buf[1] != 'K')
4751 {
4752 remote_console_output (buf + 1); /* 'O' message from stub */
4753 continue;
4754 }
4755 if (strcmp (buf, "OK") == 0)
4756 break;
4757 if (strlen (buf) == 3 && buf[0] == 'E'
4758 && isdigit (buf[1]) && isdigit (buf[2]))
4759 {
4760 error ("Protocol error with Rcmd");
4761 }
4762 for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
4763 {
4764 char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
4765 fputc_unfiltered (c, outbuf);
4766 }
4767 break;
4768 }
4769 }
4770
4771 static void
4772 packet_command (char *args, int from_tty)
4773 {
4774 char *buf = alloca (PBUFSIZ);
4775
4776 if (!remote_desc)
4777 error ("command can only be used with remote target");
4778
4779 if (!args)
4780 error ("remote-packet command requires packet text as argument");
4781
4782 puts_filtered ("sending: ");
4783 print_packet (args);
4784 puts_filtered ("\n");
4785 putpkt (args);
4786
4787 getpkt (buf, PBUFSIZ, 0);
4788 puts_filtered ("received: ");
4789 print_packet (buf);
4790 puts_filtered ("\n");
4791 }
4792
4793 #if 0
4794 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4795
4796 static void display_thread_info (struct gdb_ext_thread_info *info);
4797
4798 static void threadset_test_cmd (char *cmd, int tty);
4799
4800 static void threadalive_test (char *cmd, int tty);
4801
4802 static void threadlist_test_cmd (char *cmd, int tty);
4803
4804 int get_and_display_threadinfo (threadref * ref);
4805
4806 static void threadinfo_test_cmd (char *cmd, int tty);
4807
4808 static int thread_display_step (threadref * ref, void *context);
4809
4810 static void threadlist_update_test_cmd (char *cmd, int tty);
4811
4812 static void init_remote_threadtests (void);
4813
4814 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4815
4816 static void
4817 threadset_test_cmd (char *cmd, int tty)
4818 {
4819 int sample_thread = SAMPLE_THREAD;
4820
4821 printf_filtered ("Remote threadset test\n");
4822 set_thread (sample_thread, 1);
4823 }
4824
4825
4826 static void
4827 threadalive_test (char *cmd, int tty)
4828 {
4829 int sample_thread = SAMPLE_THREAD;
4830
4831 if (remote_thread_alive (sample_thread))
4832 printf_filtered ("PASS: Thread alive test\n");
4833 else
4834 printf_filtered ("FAIL: Thread alive test\n");
4835 }
4836
4837 void output_threadid (char *title, threadref * ref);
4838
4839 void
4840 output_threadid (char *title, threadref *ref)
4841 {
4842 char hexid[20];
4843
4844 pack_threadid (&hexid[0], ref); /* Convert threead id into hex */
4845 hexid[16] = 0;
4846 printf_filtered ("%s %s\n", title, (&hexid[0]));
4847 }
4848
4849 static void
4850 threadlist_test_cmd (char *cmd, int tty)
4851 {
4852 int startflag = 1;
4853 threadref nextthread;
4854 int done, result_count;
4855 threadref threadlist[3];
4856
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");
4861 else
4862 {
4863 threadref *scan = threadlist;
4864 threadref *limit = scan + result_count;
4865
4866 while (scan < limit)
4867 output_threadid (" thread ", scan++);
4868 }
4869 }
4870
4871 void
4872 display_thread_info (struct gdb_ext_thread_info *info)
4873 {
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);
4878 }
4879
4880 int
4881 get_and_display_threadinfo (threadref *ref)
4882 {
4883 int result;
4884 int set;
4885 struct gdb_ext_thread_info threadinfo;
4886
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);
4891 return result;
4892 }
4893
4894 static void
4895 threadinfo_test_cmd (char *cmd, int tty)
4896 {
4897 int athread = SAMPLE_THREAD;
4898 threadref thread;
4899 int set;
4900
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");
4905 }
4906
4907 static int
4908 thread_display_step (threadref *ref, void *context)
4909 {
4910 /* output_threadid(" threadstep ",ref); *//* simple test */
4911 return get_and_display_threadinfo (ref);
4912 }
4913
4914 static void
4915 threadlist_update_test_cmd (char *cmd, int tty)
4916 {
4917 printf_filtered ("Remote Threadlist update test\n");
4918 remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
4919 }
4920
4921 static void
4922 init_remote_threadtests (void)
4923 {
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 ");
4934 }
4935
4936 #endif /* 0 */
4937
4938 static void
4939 init_remote_ops (void)
4940 {
4941 remote_ops.to_shortname = "remote";
4942 remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
4943 remote_ops.to_doc =
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;
4976 }
4977
4978 /* Set up the extended remote vector by making a copy of the standard
4979 remote vector and adding to it. */
4980
4981 static void
4982 init_extended_remote_ops (void)
4983 {
4984 extended_remote_ops = remote_ops;
4985
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;
4995 }
4996
4997 /*
4998 * Command: info remote-process
4999 *
5000 * This implements Cisco's version of the "info proc" command.
5001 *
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.
5005 *
5006 * Syntax: qfProcessInfo request first string
5007 * qsProcessInfo request subsequent string
5008 * reply: 'O'<hex-encoded-string>
5009 * 'l' last reply (empty)
5010 */
5011
5012 static void
5013 remote_info_process (char *args, int from_tty)
5014 {
5015 char *buf = alloca (PBUFSIZ);
5016
5017 if (remote_desc == 0)
5018 error ("Command can only be used when connected to the remote target.");
5019
5020 putpkt ("qfProcessInfo");
5021 getpkt (buf, PBUFSIZ, 0);
5022 if (buf[0] == 0)
5023 return; /* Silently: target does not support this feature. */
5024
5025 if (buf[0] == 'E')
5026 error ("info proc: target error.");
5027
5028 while (buf[0] == 'O') /* Capitol-O packet */
5029 {
5030 remote_console_output (&buf[1]);
5031 putpkt ("qsProcessInfo");
5032 getpkt (buf, PBUFSIZ, 0);
5033 }
5034 }
5035
5036 /*
5037 * Target Cisco
5038 */
5039
5040 static void
5041 remote_cisco_open (char *name, int from_tty)
5042 {
5043 if (name == 0)
5044 error (
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).");
5047
5048 /* See FIXME above */
5049 wait_forever_enabled_p = 1;
5050
5051 target_preopen (from_tty);
5052
5053 unpush_target (&remote_cisco_ops);
5054
5055 remote_desc = SERIAL_OPEN (name);
5056 if (!remote_desc)
5057 perror_with_name (name);
5058
5059 /*
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
5062 * default to 9600
5063 */
5064
5065 baud_rate = (baud_rate > 0) ? baud_rate : 9600;
5066 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
5067 {
5068 SERIAL_CLOSE (remote_desc);
5069 perror_with_name (name);
5070 }
5071
5072 SERIAL_RAW (remote_desc);
5073
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);
5077
5078 if (from_tty)
5079 {
5080 puts_filtered ("Remote debugging using ");
5081 puts_filtered (name);
5082 puts_filtered ("\n");
5083 }
5084
5085 remote_cisco_mode = 1;
5086
5087 push_target (&remote_cisco_ops); /* Switch to using cisco target now */
5088
5089 init_all_packet_configs ();
5090
5091 general_thread = -2;
5092 continue_thread = -2;
5093
5094 /* Probe for ability to use "ThreadInfo" query, as required. */
5095 use_threadinfo_query = 1;
5096 use_threadextra_query = 1;
5097
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;
5105
5106 /* Start the remote connection; if error (0), discard this target. */
5107
5108 if (!catch_errors (remote_start_remote_dummy, (char *) 0,
5109 "Couldn't establish connection to remote target\n",
5110 RETURN_MASK_ALL))
5111 {
5112 pop_target ();
5113 return;
5114 }
5115 }
5116
5117 static void
5118 remote_cisco_close (int quitting)
5119 {
5120 remote_cisco_mode = 0;
5121 remote_close (quitting);
5122 }
5123
5124 static void
5125 remote_cisco_mourn (void)
5126 {
5127 remote_mourn_1 (&remote_cisco_ops);
5128 }
5129
5130 enum
5131 {
5132 READ_MORE,
5133 FATAL_ERROR,
5134 ENTER_DEBUG,
5135 DISCONNECT_TELNET
5136 }
5137 minitelnet_return;
5138
5139 /* shared between readsocket() and readtty() */
5140 static char *tty_input;
5141
5142 static int escape_count;
5143 static int echo_check;
5144 extern int quit_flag;
5145
5146 static int
5147 readsocket (void)
5148 {
5149 int data;
5150
5151 /* Loop until the socket doesn't have any more data */
5152
5153 while ((data = readchar (0)) >= 0)
5154 {
5155 /* Check for the escape sequence */
5156 if (data == '|')
5157 {
5158 /* If this is the fourth escape, get out */
5159 if (++escape_count == 4)
5160 {
5161 return ENTER_DEBUG;
5162 }
5163 else
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. */
5167 continue;
5168 }
5169 }
5170 else
5171 /* Not a '|' */
5172 {
5173 /* Ensure any pending '|'s are flushed. */
5174
5175 for (; escape_count > 0; escape_count--)
5176 putchar ('|');
5177 }
5178
5179 if (data == '\r') /* If this is a return character, */
5180 continue; /* - just supress it. */
5181
5182 if (echo_check != -1) /* Check for echo of user input. */
5183 {
5184 if (tty_input[echo_check] == data)
5185 {
5186 echo_check++; /* Character matched user input: */
5187 continue; /* Continue without echoing it. */
5188 }
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. */
5193 }
5194 else
5195 { /* Failed check for echo of user input.
5196 We now have some suppressed output to flush! */
5197 int j;
5198
5199 for (j = 0; j < echo_check; j++)
5200 putchar (tty_input[j]);
5201 echo_check = -1;
5202 }
5203 }
5204 putchar (data); /* Default case: output the char. */
5205 }
5206
5207 if (data == SERIAL_TIMEOUT) /* Timeout returned from readchar. */
5208 return READ_MORE; /* Try to read some more */
5209 else
5210 return FATAL_ERROR; /* Trouble, bail out */
5211 }
5212
5213 static int
5214 readtty (void)
5215 {
5216 int tty_bytecount;
5217
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)
5221 {
5222 perror ("readtty: read failed");
5223 return FATAL_ERROR;
5224 }
5225
5226 /* Remove a quoted newline. */
5227 if (tty_input[tty_bytecount - 1] == '\n' &&
5228 tty_input[tty_bytecount - 2] == '\\') /* line ending in backslash */
5229 {
5230 tty_input[--tty_bytecount] = 0; /* remove newline */
5231 tty_input[--tty_bytecount] = 0; /* remove backslash */
5232 }
5233
5234 /* Turn trailing newlines into returns */
5235 if (tty_input[tty_bytecount - 1] == '\n')
5236 tty_input[tty_bytecount - 1] = '\r';
5237
5238 /* If the line consists of a ~, enter debugging mode. */
5239 if ((tty_input[0] == '~') && (tty_bytecount == 2))
5240 return ENTER_DEBUG;
5241
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))
5245 {
5246 perror_with_name ("readtty: write failed");
5247 return FATAL_ERROR;
5248 }
5249
5250 return READ_MORE;
5251 }
5252
5253 static int
5254 minitelnet (void)
5255 {
5256 fd_set input; /* file descriptors for select */
5257 int tablesize; /* max number of FDs for select */
5258 int status;
5259 int quit_count = 0;
5260
5261 extern int escape_count; /* global shared by readsocket */
5262 extern int echo_check; /* ditto */
5263
5264 escape_count = 0;
5265 echo_check = -1;
5266
5267 tablesize = 8 * sizeof (input);
5268
5269 for (;;)
5270 {
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. */
5274
5275 if ((status = readsocket ()) == FATAL_ERROR)
5276 {
5277 error ("Debugging terminated by communications error");
5278 }
5279 else if (status != READ_MORE)
5280 {
5281 return (status);
5282 }
5283
5284 fflush (stdout); /* Flush output before blocking */
5285
5286 /* Now block on more socket input or TTY input */
5287
5288 FD_ZERO (&input);
5289 FD_SET (fileno (stdin), &input);
5290 FD_SET (DEPRECATED_SERIAL_FD (remote_desc), &input);
5291
5292 status = select (tablesize, &input, 0, 0, 0);
5293 if ((status == -1) && (errno != EINTR))
5294 {
5295 error ("Communications error on select %d", errno);
5296 }
5297
5298 /* Handle Control-C typed */
5299
5300 if (quit_flag)
5301 {
5302 if ((++quit_count) == 2)
5303 {
5304 if (query ("Interrupt GDB? "))
5305 {
5306 printf_filtered ("Interrupted by user.\n");
5307 return_to_top_level (RETURN_QUIT);
5308 }
5309 quit_count = 0;
5310 }
5311 quit_flag = 0;
5312
5313 if (remote_break)
5314 SERIAL_SEND_BREAK (remote_desc);
5315 else
5316 SERIAL_WRITE (remote_desc, "\003", 1);
5317
5318 continue;
5319 }
5320
5321 /* Handle console input */
5322
5323 if (FD_ISSET (fileno (stdin), &input))
5324 {
5325 quit_count = 0;
5326 echo_check = 0;
5327 status = readtty ();
5328 if (status == READ_MORE)
5329 continue;
5330
5331 return status; /* telnet session ended */
5332 }
5333 }
5334 }
5335
5336 static int
5337 remote_cisco_wait (int pid, struct target_waitstatus *status)
5338 {
5339 if (minitelnet () != ENTER_DEBUG)
5340 {
5341 error ("Debugging session terminated by protocol error");
5342 }
5343 putpkt ("?");
5344 return remote_wait (pid, status);
5345 }
5346
5347 static void
5348 init_remote_cisco_ops (void)
5349 {
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;
5380 }
5381
5382 static int
5383 remote_can_async_p (void)
5384 {
5385 /* We're async whenever the serial device is. */
5386 return (current_target.to_async_mask_value) && SERIAL_CAN_ASYNC_P (remote_desc);
5387 }
5388
5389 static int
5390 remote_is_async_p (void)
5391 {
5392 /* We're async whenever the serial device is. */
5393 return (current_target.to_async_mask_value) && SERIAL_IS_ASYNC_P (remote_desc);
5394 }
5395
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. */
5399
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;
5403
5404 static void
5405 remote_async_serial_handler (serial_t scb, void *context)
5406 {
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);
5410 }
5411
5412 static void
5413 remote_async (void (*callback) (enum inferior_event_type event_type, void *context), void *context)
5414 {
5415 if (current_target.to_async_mask_value == 0)
5416 internal_error (__FILE__, __LINE__,
5417 "Calling remote_async when async is masked");
5418
5419 if (callback != NULL)
5420 {
5421 SERIAL_ASYNC (remote_desc, remote_async_serial_handler, NULL);
5422 async_client_callback = callback;
5423 async_client_context = context;
5424 }
5425 else
5426 SERIAL_ASYNC (remote_desc, NULL, NULL);
5427 }
5428
5429 /* Target async and target extended-async.
5430
5431 This are temporary targets, until it is all tested. Eventually
5432 async support will be incorporated int the usual 'remote'
5433 target. */
5434
5435 static void
5436 init_remote_async_ops (void)
5437 {
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;
5478 }
5479
5480 /* Set up the async extended remote vector by making a copy of the standard
5481 remote vector and adding to it. */
5482
5483 static void
5484 init_extended_async_remote_ops (void)
5485 {
5486 extended_async_remote_ops = remote_async_ops;
5487
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;
5497 }
5498
5499 static void
5500 set_remote_cmd (char *args, int from_tty)
5501 {
5502
5503 }
5504
5505 static void
5506 show_remote_cmd (char *args, int from_tty)
5507 {
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);
5511 }
5512
5513 static void
5514 build_remote_gdbarch_data (void)
5515 {
5516 build_remote_packet_sizes ();
5517
5518 /* Cisco stuff */
5519 tty_input = xmalloc (PBUFSIZ);
5520 remote_address_size = TARGET_ADDR_BIT;
5521 }
5522
5523 void
5524 _initialize_remote (void)
5525 {
5526 static struct cmd_list_element *remote_set_cmdlist;
5527 static struct cmd_list_element *remote_show_cmdlist;
5528 struct cmd_list_element *tmpcmd;
5529
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);
5537
5538 init_remote_ops ();
5539 add_target (&remote_ops);
5540
5541 init_extended_remote_ops ();
5542 add_target (&extended_remote_ops);
5543
5544 init_remote_async_ops ();
5545 add_target (&remote_async_ops);
5546
5547 init_extended_async_remote_ops ();
5548 add_target (&extended_async_remote_ops);
5549
5550 init_remote_cisco_ops ();
5551 add_target (&remote_cisco_ops);
5552
5553 #if 0
5554 init_remote_threadtests ();
5555 #endif
5556
5557 /* set/show remote ... */
5558
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);
5571
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).",
5575 &cmdlist);
5576
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.",
5584 &maintenancelist);
5585
5586 add_show_from_set
5587 (add_set_cmd ("remotebreak", no_class,
5588 var_boolean, (char *) &remote_break,
5589 "Set whether to send break if interrupted.\n",
5590 &setlist),
5591 &showlist);
5592
5593 /* Install commands for configuring memory read/write packets. */
5594
5595 add_cmd ("remotewritesize", no_class, set_memory_write_packet_size,
5596 "Set the maximum number of bytes per memory write packet (deprecated).\n",
5597 &setlist);
5598 add_cmd ("remotewritesize", no_class, show_memory_write_packet_size,
5599 "Show the maximum number of bytes per memory write packet (deprecated).\n",
5600 &showlist);
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);
5625
5626 add_show_from_set
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",
5631 &setlist),
5632 &showlist);
5633
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,
5639 1);
5640 #if 0
5641 /* XXXX - should ``set remotebinarydownload'' be retained for
5642 compatibility. */
5643 add_show_from_set
5644 (add_set_cmd ("remotebinarydownload", no_class,
5645 var_boolean, (char *) &remote_binary_download,
5646 "Set binary downloads.\n", &setlist),
5647 &showlist);
5648 #endif
5649
5650 add_info ("remote-process", remote_info_process,
5651 "Query the remote system for process info.");
5652
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,
5658 1);
5659
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,
5665 0);
5666
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,
5672 0);
5673
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,
5679 0);
5680
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,
5686 0);
5687
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,
5693 0);
5694
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,
5698 "\
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);
5704 }
This page took 0.15595 seconds and 4 git commands to generate.