1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 /* Remote communication protocol.
22 A debug packet whose contents are <data>
23 is encapsulated for transmission in the form:
25 $ <data> # CSUM1 CSUM2
27 <data> must be ASCII alphanumeric and cannot include characters
28 '$' or '#'. If <data> starts with two characters followed by
29 ':', then the existing stubs interpret this as a sequence number.
31 CSUM1 and CSUM2 are ascii hex representation of an 8-bit
32 checksum of <data>, the most significant nibble is sent first.
33 the hex digits 0-9,a-f are used.
35 Receiver responds with:
37 + - if CSUM is correct and ready for next packet
38 - - if CSUM is incorrect
41 All values are encoded in ascii hex digits.
46 reply XX....X Each byte of register data
47 is described by two hex digits.
48 Registers are in the internal order
49 for GDB, and the bytes in a register
50 are in the same order the machine uses.
53 write regs GXX..XX Each byte of register data
54 is described by two hex digits.
58 write reg Pn...=r... Write register n... with value r...,
59 which contains two hex digits for each
60 byte in the register (target byte
64 (not supported by all stubs).
66 read mem mAA..AA,LLLL AA..AA is address, LLLL is length.
67 reply XX..XX XX..XX is mem contents
68 Can be fewer bytes than requested
69 if able to read only part of the data.
72 write mem MAA..AA,LLLL:XX..XX
74 LLLL is number of bytes,
77 ENN for an error (this includes the case
78 where only part of the data was
81 cont cAA..AA AA..AA is address to resume
83 resume at same address.
85 step sAA..AA AA..AA is address to resume
87 resume at same address.
89 last signal ? Reply the current reason for stopping.
90 This is the same reply as is generated
91 for step or cont : SAA where AA is the
94 There is no immediate reply to step or cont.
95 The reply comes when the machine stops.
96 It is SAA AA is the "signal number"
98 or... TAAn...:r...;n:r...;n...:r...;
100 n... = register number
101 r... = register contents
102 or... WAA The process exited, and AA is
103 the exit status. This is only
104 applicable for certains sorts of
108 toggle debug d toggle debug flag (see 386 & 68k stubs)
109 reset r reset -- see sparc stub.
110 reserved <other> On other requests, the stub should
111 ignore the request and send an empty
112 response ($#<checksum>). This way
113 we can extend the protocol and GDB
114 can tell whether the stub it is
115 talking to uses the old or the new.
116 search tAA:PP,MM Search backwards starting at address
117 AA for a match with pattern PP and
118 mask MM. PP and MM are 4 bytes.
119 Not supported by all stubs.
121 general query qXXXX Request info about XXXX.
122 general set QXXXX=yyyy Set value of XXXX to yyyy.
123 query sect offs qOffsets Get section offsets. Reply is
124 Text=xxx;Data=yyy;Bss=zzz
125 console output Otext Send text to stdout. Only comes from
128 Responses can be run-length encoded to save space. A '*' means that
129 the next character is an ASCII encoding giving a repeat count which
130 stands for that many repititions of the character preceding the '*'.
131 The encoding is n+29, yielding a printable character where n >=3
132 (which is where rle starts to win). Don't use an n > 126.
135 "0* " means the same as "0000". */
138 #include "gdb_string.h"
141 #include "inferior.h"
146 #include "terminal.h"
148 #include "objfiles.h"
149 #include "gdb-stabs.h"
150 #include "remote-utils.h"
154 #include <sys/types.h>
160 /* Prototypes for local functions */
163 remote_write_bytes PARAMS ((CORE_ADDR memaddr, unsigned char *myaddr, int len));
166 remote_read_bytes PARAMS ((CORE_ADDR memaddr, unsigned char *myaddr, int len));
169 remote_files_info PARAMS ((struct target_ops *ignore));
172 remote_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, int len,
173 int should_write, struct target_ops *target));
176 remote_prepare_to_store PARAMS ((void));
179 remote_fetch_registers PARAMS ((int regno));
182 remote_resume PARAMS ((int pid, int step, enum target_signal siggnal));
185 remote_start_remote PARAMS ((char *dummy));
188 remote_open PARAMS ((char *name, int from_tty));
191 remote_close PARAMS ((int quitting));
194 remote_store_registers PARAMS ((int regno));
197 getpkt PARAMS ((char *buf, int forever));
200 putpkt PARAMS ((char *buf));
203 remote_send PARAMS ((char *buf));
206 readchar PARAMS ((int timeout));
209 remote_wait PARAMS ((int pid, struct target_waitstatus *status));
212 tohex PARAMS ((int nib));
215 fromhex PARAMS ((int a));
218 remote_detach PARAMS ((char *args, int from_tty));
221 remote_interrupt PARAMS ((int signo));
224 remote_interrupt_twice PARAMS ((int signo));
227 interrupt_query PARAMS ((void));
230 hppro_load PARAMS ((char *name, int from_tty));
232 extern struct target_ops remote_ops; /* Forward decl */
234 /* This was 5 seconds, which is a long time to sit and wait.
235 Unless this is going though some terminal server or multiplexer or
236 other form of hairy serial connection, I would think 2 seconds would
238 static int remote_timeout = 2;
240 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
241 remote_open knows that we don't have a file open when the program
243 extern serial_t remote_desc;
245 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
246 and i386-stub.c. Normally, no one would notice because it only matters
247 for writing large chunks of memory (e.g. in downloads). Also, this needs
248 to be more than 400 if required to hold the registers (see below, where
249 we round it up based on REGISTER_BYTES). */
252 /* Maximum number of bytes to read/write at once. The value here
253 is chosen to fill up a packet (the headers account for the 32). */
254 #define MAXBUFBYTES ((PBUFSIZ-32)/2)
256 /* Round up PBUFSIZ to hold all the registers, at least. */
257 /* The blank line after the #if seems to be required to work around a
258 bug in HP's PA compiler. */
259 #if REGISTER_BYTES > MAXBUFBYTES
262 #define PBUFSIZ (REGISTER_BYTES * 2 + 32)
265 /* Should we try the 'P' request? If this is set to one when the stub
266 doesn't support 'P', the only consequence is some unnecessary traffic. */
267 static int stub_supports_P = 1;
269 /* sets the download protocol, choices are srec, generic, boot */
271 static char *loadtype_str;
272 static void set_loadtype_command
273 PARAMS ((char *, int, struct cmd_list_element *));
276 hppro_load (file, from_tty)
280 puts ("Loading... HA!");
284 /* Clean up connection to a remote debugger. */
288 remote_close (quitting)
292 SERIAL_CLOSE (remote_desc);
296 /* Query the remote side for the text, data and bss offsets. */
301 unsigned char buf[PBUFSIZ];
303 CORE_ADDR text_addr, data_addr, bss_addr;
304 struct section_offsets *offs;
310 if (buf[0] == '\000')
311 return; /* Return silently. Stub doesn't support this
315 warning ("Remote failure reply: %s", buf);
319 nvals = sscanf (buf, "Text=%lx;Data=%lx;Bss=%lx", &text_addr, &data_addr,
322 error ("Malformed response to offset query, %s", buf);
324 if (symfile_objfile == NULL)
327 offs = (struct section_offsets *) alloca (sizeof (struct section_offsets)
328 + symfile_objfile->num_sections
329 * sizeof (offs->offsets));
330 memcpy (offs, symfile_objfile->section_offsets,
331 sizeof (struct section_offsets)
332 + symfile_objfile->num_sections
333 * sizeof (offs->offsets));
335 /* FIXME: This code assumes gdb-stabs.h is being used; it's broken
336 for xcoff, dwarf, sdb-coff, etc. But there is no simple
337 canonical representation for this stuff. (Just what does "text"
338 as seen by the stub mean, anyway? I think it means all sections
339 with SEC_CODE set, but we currently have no way to deal with that). */
341 ANOFFSET (offs, SECT_OFF_TEXT) = text_addr;
343 /* This is a temporary kludge to force data and bss to use the same offsets
344 because that's what nlmconv does now. The real solution requires changes
345 to the stub and remote.c that I don't have time to do right now. */
347 ANOFFSET (offs, SECT_OFF_DATA) = data_addr;
348 ANOFFSET (offs, SECT_OFF_BSS) = data_addr;
350 objfile_relocate (symfile_objfile, offs);
362 /* See if we can connect to the boot ROM command line */
365 SERIAL_WRITE (remote_desc, "\r\n", 2);
367 if ((sr_get_debug() > 2) && (isascii(c)))
369 if (c == SERIAL_TIMEOUT) {
371 puts_filtered ("Timed out.\n");
375 if (sr_get_debug() > 2)
376 puts ("Got ACK from stub");
380 if (sr_get_debug() > 2)
381 puts ("Got prompt from ROM monitor");
388 /* Stub for catch_errors. */
390 remote_start_remote (dummy)
395 immediate_quit = 1; /* Allow user to interrupt it */
397 /* Ack any packet which the remote side has already sent. */
400 puts ("Trying a '+' to ACK the target.");
402 SERIAL_WRITE (remote_desc, "+", 1);
407 get_offsets (); /* Get text, data & bss offsets */
410 putpkt ("?"); /* initiate a query from remote machine */
413 start_remote (); /* Initialize gdb process mechanisms */
418 /* Open a connection to a remote debugger.
419 NAME is the filename used for communication. */
421 static DCACHE *remote_dcache;
424 remote_open (name, from_tty)
430 "To open a remote debug connection, you need to specify what serial\n\
431 device is attached to the remote system (e.g. /dev/ttya).");
433 target_preopen (from_tty);
435 unpush_target (&remote_ops);
437 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
439 remote_desc = SERIAL_OPEN (name);
441 perror_with_name (name);
445 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
447 SERIAL_CLOSE (remote_desc);
448 perror_with_name (name);
452 SERIAL_RAW (remote_desc);
454 /* If there is something sitting in the buffer we might take it as a
455 response to a command, which would be bad. */
456 SERIAL_FLUSH_INPUT (remote_desc);
460 puts_filtered ("Remote debugging using ");
461 puts_filtered (name);
462 puts_filtered ("\n");
464 push_target (&remote_ops); /* Switch to using remote target now */
466 /* Start out by trying the 'P' request to set registers. We set this each
467 time that we open a new target so that if the user switches from one
468 stub to another, we can (if the target is closed and reopened) cope. */
471 /* Without this, some commands which require an active target (such as kill)
472 won't work. This variable serves (at least) double duty as both the pid
473 of the target process (if it has such), and as a flag indicating that a
474 target is active. These functions should be split out into seperate
475 variables, especially since GDB will someday have a notion of debugging
476 several processes. */
478 inferior_pid = 42000;
480 /* Start the remote connection; if error (0), discard this target.
481 In particular, if the user quits, be sure to discard it
482 (we'd be in an inconsistent state otherwise). */
483 if (!catch_errors (remote_start_remote, (char *)0,
484 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL))
489 takes a program previously attached to and detaches it.
490 We better not have left any breakpoints
491 in the program or it'll die when it hits one.
492 Close the open connection to the remote debugger.
493 Use this when you want to detach and do something else
497 remote_detach (args, from_tty)
502 error ("Argument given to \"detach\" when remotely debugging.");
506 puts_filtered ("Ending remote debugging.\n");
509 /* Convert hex digit A to a number. */
515 if (a >= '0' && a <= '9')
517 else if (a >= 'a' && a <= 'f')
520 error ("Reply contains invalid hex digit");
523 /* Convert number NIB to a hex digit. */
535 /* Tell the remote machine to resume. */
538 remote_resume (pid, step, siggnal)
540 enum target_signal siggnal;
546 target_terminal_ours_for_output ();
548 ("Can't send signals to a remote system. %s not sent.\n",
549 target_signal_to_name (siggnal)); target_terminal_inferior ();
552 dcache_flush (remote_dcache);
554 strcpy (buf, step ? "s": "c");
559 /* Send ^C to target to halt it. Target will respond, and send us a
563 remote_interrupt (signo)
566 /* If this doesn't work, try more severe steps. */
567 signal (signo, remote_interrupt_twice);
570 printf_unfiltered ("remote_interrupt called\n");
572 SERIAL_WRITE (remote_desc, "\003", 1); /* Send a ^C */
575 static void (*ofunc)();
577 /* The user typed ^C twice. */
579 remote_interrupt_twice (signo)
582 signal (signo, ofunc);
586 signal (signo, remote_interrupt);
589 /* Ask the user what to do when an interrupt is received. */
594 target_terminal_ours ();
596 if (query ("Interrupted while waiting for the program.\n\
597 Give up (and stop debugging it)? "))
599 target_mourn_inferior ();
600 return_to_top_level (RETURN_QUIT);
603 target_terminal_inferior ();
606 /* Wait until the remote machine stops, then return,
607 storing status in STATUS just as `wait' would.
608 Returns "pid" (though it's not clear what, if anything, that
609 means in the case of this target). */
612 remote_wait (pid, status)
614 struct target_waitstatus *status;
616 unsigned char buf[PBUFSIZ];
618 status->kind = TARGET_WAITKIND_EXITED;
619 status->value.integer = 0;
625 ofunc = (void (*)()) signal (SIGINT, remote_interrupt);
626 getpkt ((char *) buf, 1);
627 signal (SIGINT, ofunc);
631 case 'E': /* Error of some sort */
632 warning ("Remote failure reply: %s", buf);
634 case 'T': /* Status with PC, SP, FP, ... */
638 char regs[MAX_REGISTER_RAW_SIZE];
640 /* Expedited reply, containing Signal, {regno, reg} repeat */
641 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
643 n... = register number
644 r... = register contents
647 p = &buf[3]; /* after Txx */
653 regno = strtol (p, &p1, 16); /* Read the register number */
656 warning ("Remote sent badly formed register number: %s\nPacket: '%s'\n",
662 warning ("Malformed packet (missing colon): %s\nPacket: '%s'\n",
665 if (regno >= NUM_REGS)
666 warning ("Remote sent bad register number %d: %s\nPacket: '%s'\n",
669 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
671 if (p[0] == 0 || p[1] == 0)
672 warning ("Remote reply is too short: %s", buf);
673 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
678 warning ("Remote register badly formatted: %s", buf);
680 supply_register (regno, regs);
684 case 'S': /* Old style status, just signal only */
685 status->kind = TARGET_WAITKIND_STOPPED;
686 status->value.sig = (enum target_signal)
687 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
690 case 'W': /* Target exited */
692 /* The remote process exited. */
693 status->kind = TARGET_WAITKIND_EXITED;
694 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
697 case 'O': /* Console output */
698 fputs_filtered (buf + 1, gdb_stdout);
701 warning ("Invalid remote reply: %s", buf);
708 /* Number of bytes of registers this stub implements. */
709 static int register_bytes_found;
711 /* Read the remote registers into the block REGS. */
712 /* Currently we just read all the registers, so we don't use regno. */
715 remote_fetch_registers (regno)
721 char regs[REGISTER_BYTES];
726 /* Unimplemented registers read as all bits zero. */
727 memset (regs, 0, REGISTER_BYTES);
729 /* We can get out of synch in various cases. If the first character
730 in the buffer is not a hex character, assume that has happened
731 and try to fetch another packet to read. */
732 while ((buf[0] < '0' || buf[0] > '9')
733 && (buf[0] < 'a' || buf[0] > 'f'))
736 printf_unfiltered ("Bad register packet; fetching a new packet\n");
740 /* Reply describes registers byte by byte, each byte encoded as two
741 hex characters. Suck them all up, then supply them to the
742 register cacheing/storage mechanism. */
745 for (i = 0; i < REGISTER_BYTES; i++)
751 warning ("Remote reply is of odd length: %s", buf);
752 /* Don't change register_bytes_found in this case, and don't
753 print a second warning. */
756 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
760 if (i != register_bytes_found)
762 register_bytes_found = i;
763 #ifdef REGISTER_BYTES_OK
764 if (!REGISTER_BYTES_OK (i))
765 warning ("Remote reply is too short: %s", buf);
770 for (i = 0; i < NUM_REGS; i++)
771 supply_register (i, ®s[REGISTER_BYTE(i)]);
774 /* Prepare to store registers. Since we may send them all (using a
775 'G' request), we have to read out the ones we don't want to change
779 remote_prepare_to_store ()
781 /* Make sure the entire registers array is valid. */
782 read_register_bytes (0, (char *)NULL, REGISTER_BYTES);
785 /* Store register REGNO, or all registers if REGNO == -1, from the contents
786 of REGISTERS. FIXME: ignores errors. */
789 remote_store_registers (regno)
796 if (regno >= 0 && stub_supports_P)
798 /* Try storing a single register. */
801 sprintf (buf, "P%x=", regno);
802 p = buf + strlen (buf);
803 regp = ®isters[REGISTER_BYTE (regno)];
804 for (i = 0; i < REGISTER_RAW_SIZE (regno); ++i)
806 *p++ = tohex ((regp[i] >> 4) & 0xf);
807 *p++ = tohex (regp[i] & 0xf);
813 /* The stub understands the 'P' request. We are done. */
817 /* The stub does not support the 'P' request. Use 'G' instead,
818 and don't try using 'P' in the future (it will just waste our
825 /* Command describes registers byte by byte,
826 each byte encoded as two hex characters. */
829 /* remote_prepare_to_store insures that register_bytes_found gets set. */
830 for (i = 0; i < register_bytes_found; i++)
832 *p++ = tohex ((registers[i] >> 4) & 0xf);
833 *p++ = tohex (registers[i] & 0xf);
842 /* Use of the data cache is disabled because it loses for looking at
843 and changing hardware I/O ports and the like. Accepting `volatile'
844 would perhaps be one way to fix it. Another idea would be to use the
845 executable file for the text segment (for all SEC_CODE sections?
846 For all SEC_READONLY sections?). This has problems if you want to
847 actually see what the memory contains (e.g. self-modifying code,
848 clobbered memory, user downloaded the wrong thing). */
850 /* Read a word from remote address ADDR and return it.
851 This goes through the data cache. */
854 remote_fetch_word (addr)
857 return dcache_fetch (remote_dcache, addr);
860 /* Write a word WORD into remote address ADDR.
861 This goes through the data cache. */
864 remote_store_word (addr, word)
868 dcache_poke (remote_dcache, addr, word);
872 /* Write memory data directly to the remote machine.
873 This does not inform the data cache; the data cache uses this.
874 MEMADDR is the address in the remote memory space.
875 MYADDR is the address of the buffer in our space.
876 LEN is the number of bytes.
878 Returns number of bytes transferred, or 0 for error. */
881 remote_write_bytes (memaddr, myaddr, len)
883 unsigned char *myaddr;
890 /* FIXME-32x64: Need a version of print_address_numeric which puts the
891 result in a buffer like sprintf. */
892 sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, len);
894 /* We send target system values byte by byte, in increasing byte addresses,
895 each byte encoded as two hex characters. */
897 p = buf + strlen (buf);
898 for (i = 0; i < len; i++)
900 *p++ = tohex ((myaddr[i] >> 4) & 0xf);
901 *p++ = tohex (myaddr[i] & 0xf);
910 /* There is no correspondance between what the remote protocol uses
911 for errors and errno codes. We would like a cleaner way of
912 representing errors (big enough to include errno codes, bfd_error
913 codes, and others). But for now just return EIO. */
920 /* Read memory data directly from the remote machine.
921 This does not use the data cache; the data cache uses this.
922 MEMADDR is the address in the remote memory space.
923 MYADDR is the address of the buffer in our space.
924 LEN is the number of bytes.
926 Returns number of bytes transferred, or 0 for error. */
929 remote_read_bytes (memaddr, myaddr, len)
931 unsigned char *myaddr;
938 if (len > PBUFSIZ / 2 - 1)
941 /* FIXME-32x64: Need a version of print_address_numeric which puts the
942 result in a buffer like sprintf. */
943 sprintf (buf, "m%lx,%x", (unsigned long) memaddr, len);
949 /* There is no correspondance between what the remote protocol uses
950 for errors and errno codes. We would like a cleaner way of
951 representing errors (big enough to include errno codes, bfd_error
952 codes, and others). But for now just return EIO. */
957 /* Reply describes memory byte by byte,
958 each byte encoded as two hex characters. */
961 for (i = 0; i < len; i++)
963 if (p[0] == 0 || p[1] == 0)
964 /* Reply is short. This means that we were able to read only part
965 of what we wanted to. */
967 myaddr[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
973 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
974 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
975 nonzero. Returns length of data written or read; 0 for error. */
979 remote_xfer_memory(memaddr, myaddr, len, should_write, target)
984 struct target_ops *target; /* ignored */
988 int total_xferred = 0;
992 if (len > MAXBUFBYTES)
993 xfersize = MAXBUFBYTES;
998 bytes_xferred = remote_write_bytes (memaddr,
999 (unsigned char *)myaddr, xfersize);
1001 bytes_xferred = remote_read_bytes (memaddr,
1002 (unsigned char *)myaddr, xfersize);
1004 /* If we get an error, we are done xferring. */
1005 if (bytes_xferred == 0)
1008 memaddr += bytes_xferred;
1009 myaddr += bytes_xferred;
1010 len -= bytes_xferred;
1011 total_xferred += bytes_xferred;
1013 return total_xferred;
1017 /* Enable after 4.12. */
1020 remote_search (len, data, mask, startaddr, increment, lorange, hirange
1021 addr_found, data_found)
1025 CORE_ADDR startaddr;
1029 CORE_ADDR *addr_found;
1032 if (increment == -4 && len == 4)
1034 long mask_long, data_long;
1035 long data_found_long;
1036 CORE_ADDR addr_we_found;
1038 long returned_long[2];
1041 mask_long = extract_unsigned_integer (mask, len);
1042 data_long = extract_unsigned_integer (data, len);
1043 sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
1048 /* The stub doesn't support the 't' request. We might want to
1049 remember this fact, but on the other hand the stub could be
1050 switched on us. Maybe we should remember it only until
1051 the next "target remote". */
1052 generic_search (len, data, mask, startaddr, increment, lorange,
1053 hirange, addr_found, data_found);
1058 /* There is no correspondance between what the remote protocol uses
1059 for errors and errno codes. We would like a cleaner way of
1060 representing errors (big enough to include errno codes, bfd_error
1061 codes, and others). But for now just use EIO. */
1062 memory_error (EIO, startaddr);
1065 while (*p != '\0' && *p != ',')
1066 addr_we_found = (addr_we_found << 4) + fromhex (*p++);
1068 error ("Protocol error: short return for search");
1070 data_found_long = 0;
1071 while (*p != '\0' && *p != ',')
1072 data_found_long = (data_found_long << 4) + fromhex (*p++);
1073 /* Ignore anything after this comma, for future extensions. */
1075 if (addr_we_found < lorange || addr_we_found >= hirange)
1081 *addr_found = addr_we_found;
1082 *data_found = store_unsigned_integer (data_we_found, len);
1085 generic_search (len, data, mask, startaddr, increment, lorange,
1086 hirange, addr_found, data_found);
1091 remote_files_info (ignore)
1092 struct target_ops *ignore;
1094 puts_filtered ("Debugging a target over a serial line.\n");
1097 /* Stuff for dealing with the packets which are part of this protocol.
1098 See comment at top of file for details. */
1100 /* Read a single character from the remote end, masking it down to 7 bits. */
1108 ch = SERIAL_READCHAR (remote_desc, timeout);
1113 error ("Remote connection closed");
1115 perror_with_name ("Remote communication error");
1116 case SERIAL_TIMEOUT:
1123 /* Send the command in BUF to the remote machine,
1124 and read the reply into BUF.
1125 Report an error if we get an error reply. */
1136 error ("Remote failure reply: %s", buf);
1139 /* Send a packet to the remote machine, with error checking.
1140 The data of the packet is in BUF. */
1146 unsigned char csum = 0;
1148 int cnt = strlen (buf);
1152 /* Copy the packet into buffer BUF2, encapsulating it
1153 and giving it a checksum. */
1155 if (cnt > sizeof(buf2) - 5) /* Prosanity check */
1161 for (i = 0; i < cnt; i++)
1167 *p++ = tohex ((csum >> 4) & 0xf);
1168 *p++ = tohex (csum & 0xf);
1170 /* Send it over and over until we get a positive ack. */
1174 int started_error_output = 0;
1179 printf_unfiltered ("Sending packet: %s...", buf2);
1180 gdb_flush(gdb_stdout);
1182 if (SERIAL_WRITE (remote_desc, buf2, p - buf2))
1183 perror_with_name ("putpkt: write failed");
1185 /* read until either a timeout occurs (-2) or '+' is read */
1188 ch = readchar (remote_timeout);
1195 case SERIAL_TIMEOUT:
1197 if (started_error_output)
1199 putchar_unfiltered ('\n');
1200 started_error_output = 0;
1209 printf_unfiltered("Got Ack\n");
1211 case SERIAL_TIMEOUT:
1212 break; /* Retransmit buffer */
1215 unsigned char junkbuf[PBUFSIZ];
1217 /* It's probably an old response, and we're out of sync. Just
1218 gobble up the packet and ignore it. */
1219 getpkt (junkbuf, 0);
1220 continue; /* Now, go look for + */
1225 if (!started_error_output)
1227 started_error_output = 1;
1228 printf_unfiltered ("putpkt: Junk: ");
1230 putchar_unfiltered (ch & 0177);
1234 break; /* Here to retransmit */
1238 /* This is wrong. If doing a long backtrace, the user should be
1239 able to get out next time we call QUIT, without anything as violent
1240 as interrupt_query. If we want to provide a way out of here
1241 without getting to the next QUIT, it should be based on hitting
1242 ^C twice as in remote_wait. */
1252 /* Come here after finding the start of the frame. Collect the rest into BUF,
1253 verifying the checksum, length, and handling run-length compression.
1254 Returns 0 on any error, 1 on success. */
1269 c = readchar (remote_timeout);
1273 case SERIAL_TIMEOUT:
1275 puts_filtered ("Timeout in mid-packet, retrying\n");
1279 puts_filtered ("Saw new packet start in middle of old one\n");
1280 return 0; /* Start a new packet, count retries */
1283 unsigned char pktcsum;
1287 pktcsum = fromhex (readchar (remote_timeout)) << 4;
1288 pktcsum |= fromhex (readchar (remote_timeout));
1290 if (csum == pktcsum)
1293 printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
1295 puts_filtered (buf);
1296 puts_filtered ("\n");
1300 case '*': /* Run length encoding */
1302 c = readchar (remote_timeout);
1304 c = c - ' ' + 3; /* Compute repeat count */
1306 if (bp + c - 1 < buf + PBUFSIZ - 1)
1308 memset (bp, *(bp - 1), c);
1314 printf_filtered ("Repeat count %d too large for buffer: ", c);
1315 puts_filtered (buf);
1316 puts_filtered ("\n");
1320 if (bp < buf + PBUFSIZ - 1)
1328 puts_filtered ("Remote packet too long: ");
1329 puts_filtered (buf);
1330 puts_filtered ("\n");
1337 /* Read a packet from the remote machine, with error checking,
1338 and store it in BUF. BUF is expected to be of size PBUFSIZ.
1339 If FOREVER, wait forever rather than timing out; this is used
1340 while the target is executing user code. */
1343 getpkt (buf, forever)
1356 timeout = remote_timeout;
1358 #define MAX_TRIES 10
1360 for (tries = 1; tries <= MAX_TRIES; tries++)
1362 /* This can loop forever if the remote side sends us characters
1363 continuously, but if it pauses, we'll get a zero from readchar
1364 because of timeout. Then we'll count that as a retry. */
1366 /* Note that we will only wait forever prior to the start of a packet.
1367 After that, we expect characters to arrive at a brisk pace. They
1368 should show up within remote_timeout intervals. */
1372 c = readchar (timeout);
1374 if (c == SERIAL_TIMEOUT)
1377 puts_filtered ("Timed out.\n");
1383 /* We've found the start of a packet, now collect the data. */
1385 val = read_frame (buf);
1390 fprintf_unfiltered (gdb_stderr, "Packet received: %s\n", buf);
1391 SERIAL_WRITE (remote_desc, "+", 1);
1395 /* Try the whole thing again. */
1397 SERIAL_WRITE (remote_desc, "-", 1);
1400 /* We have tried hard enough, and just can't receive the packet. Give up. */
1402 printf_unfiltered ("Ignoring packet error, continuing...\n");
1403 SERIAL_WRITE (remote_desc, "+", 1);
1410 /* Don't wait for it to die. I'm not really sure it matters whether
1411 we do or not. For the existing stubs, kill is a noop. */
1412 target_mourn_inferior ();
1418 unpush_target (&remote_ops);
1419 generic_mourn_inferior ();
1422 #ifdef REMOTE_BREAKPOINT
1424 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
1425 than other targets. */
1426 static unsigned char break_insn[] = REMOTE_BREAKPOINT;
1428 #else /* No REMOTE_BREAKPOINT. */
1430 /* Same old breakpoint instruction. This code does nothing different
1431 than mem-break.c. */
1432 static unsigned char break_insn[] = BREAKPOINT;
1434 #endif /* No REMOTE_BREAKPOINT. */
1436 /* Insert a breakpoint on targets that don't have any better breakpoint
1437 support. We read the contents of the target location and stash it,
1438 then overwrite it with a breakpoint instruction. ADDR is the target
1439 location in the target machine. CONTENTS_CACHE is a pointer to
1440 memory allocated for saving the target contents. It is guaranteed
1441 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
1442 is accomplished via BREAKPOINT_MAX). */
1445 remote_insert_breakpoint (addr, contents_cache)
1447 char *contents_cache;
1451 val = target_read_memory (addr, contents_cache, sizeof break_insn);
1454 val = target_write_memory (addr, (char *)break_insn, sizeof break_insn);
1460 remote_remove_breakpoint (addr, contents_cache)
1462 char *contents_cache;
1464 return target_write_memory (addr, contents_cache, sizeof break_insn);
1467 /* Define the target subroutine names */
1469 struct target_ops remote_hppro_ops = {
1470 "hppro", /* to_shortname */
1471 "Remote serial target for HP-PRO targets", /* to_longname */
1472 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
1473 This is for targets that supports the HP-PRO standard.\n\
1474 Specify the serial device it is connected to (e.g. /dev/ttya) or telnet port.", /* to_doc */
1475 remote_open, /* to_open */
1476 remote_close, /* to_close */
1477 NULL, /* to_attach */
1478 remote_detach, /* to_detach */
1479 remote_resume, /* to_resume */
1480 remote_wait, /* to_wait */
1481 remote_fetch_registers, /* to_fetch_registers */
1482 remote_store_registers, /* to_store_registers */
1483 remote_prepare_to_store, /* to_prepare_to_store */
1484 remote_xfer_memory, /* to_xfer_memory */
1485 remote_files_info, /* to_files_info */
1487 remote_insert_breakpoint, /* to_insert_breakpoint */
1488 remote_remove_breakpoint, /* to_remove_breakpoint */
1490 NULL, /* to_terminal_init */
1491 NULL, /* to_terminal_inferior */
1492 NULL, /* to_terminal_ours_for_output */
1493 NULL, /* to_terminal_ours */
1494 NULL, /* to_terminal_info */
1495 remote_kill, /* to_kill */
1496 hppro_load, /* to_load */
1497 NULL, /* to_lookup_symbol */
1498 NULL, /* to_create_inferior */
1499 remote_mourn, /* to_mourn_inferior */
1501 0, /* to_notice_signals */
1502 0, /* to_thread_alive */
1504 process_stratum, /* to_stratum */
1506 1, /* to_has_all_memory */
1507 1, /* to_has_memory */
1508 1, /* to_has_stack */
1509 1, /* to_has_registers */
1510 1, /* to_has_execution */
1511 NULL, /* sections */
1512 NULL, /* sections_end */
1513 OPS_MAGIC /* to_magic */
1517 _initialize_remote_hppro ()
1519 struct cmd_list_element *c;
1520 add_target (&remote_hppro_ops);
1522 /* this sets the type of download protocol */
1523 c = add_set_cmd ("loadtype", no_class, var_string, (char *)&loadtype_str,
1524 "Set the type of the remote load protocol.\n", &setlist);
1525 c->function.sfunc = set_loadtype_command;
1526 add_show_from_set (c, &showlist);
1527 loadtype_str = savestring ("generic", 8);
1529 /* this adds a command to boot the board */
1530 add_com ("boot", class_support, boot_board,
1531 "Boot the damn target board.\n");
1535 set_loadtype_command (ignore, from_tty, c)
1538 struct cmd_list_element *c;
1540 loadtype_str = savestring (*(char **) c->var, strlen (*(char **) c->var));