1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 1991, 1992, 1993 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., 675 Mass Ave, Cambridge, MA 02139, 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
30 CSUM1 and CSUM2 are ascii hex representation of an 8-bit
31 checksum of <data>, the most significant nibble is sent first.
32 the hex digits 0-9,a-f are used.
34 Receiver responds with:
36 + - if CSUM is correct and ready for next packet
37 - - if CSUM is incorrect
40 All values are encoded in ascii hex digits.
45 reply XX....X Each byte of register data
46 is described by two hex digits.
47 Registers are in the internal order
48 for GDB, and the bytes in a register
49 are in the same order the machine uses.
52 write regs GXX..XX Each byte of register data
53 is described by two hex digits.
57 read mem mAA..AA,LLLL AA..AA is address, LLLL is length.
58 reply XX..XX XX..XX is mem contents
59 Can be fewer bytes than requested
60 if able to read only part of the data.
63 write mem MAA..AA,LLLL:XX..XX
65 LLLL is number of bytes,
68 ENN for an error (this includes the case
69 where only part of the data was
72 cont cAA..AA AA..AA is address to resume
74 resume at same address.
76 step sAA..AA AA..AA is address to resume
78 resume at same address.
80 last signal ? Reply the current reason for stopping.
81 This is the same reply as is generated
82 for step or cont : SAA where AA is the
85 There is no immediate reply to step or cont.
86 The reply comes when the machine stops.
87 It is SAA AA is the "signal number"
89 or... TAAn...:r...;n:r...;n...:r...;
91 n... = register number
92 r... = register contents
93 or... WAA The process extited, and AA is
94 the exit status. This is only
95 applicable for certains sorts of
97 or... NAATT;DD;BB Relocate the object file.
102 This is used by the NLM stub,
103 which is why it only has three
104 addresses rather than one per
105 section: the NLM stub always
106 sees only three sections, even
107 though gdb may see more.
111 toggle debug d toggle debug flag (see 386 & 68k stubs)
112 reset r reset -- see sparc stub.
113 reserved <other> On other requests, the stub should
114 ignore the request and send an empty
115 response ($#<checksum>). This way
116 we can extend the protocol and GDB
117 can tell whether the stub it is
118 talking to uses the old or the new.
125 #include "inferior.h"
130 #include "terminal.h"
132 #include "objfiles.h"
133 #include "gdb-stabs.h"
137 #if !defined(DONT_USE_REMOTE)
139 #include <sys/types.h>
145 /* Prototypes for local functions */
148 remote_write_bytes
PARAMS ((CORE_ADDR memaddr
, unsigned char *myaddr
, int len
));
151 remote_read_bytes
PARAMS ((CORE_ADDR memaddr
, unsigned char *myaddr
, int len
));
154 remote_files_info
PARAMS ((struct target_ops
*ignore
));
157 remote_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
, int len
,
158 int should_write
, struct target_ops
*target
));
161 remote_prepare_to_store
PARAMS ((void));
164 remote_fetch_registers
PARAMS ((int regno
));
167 remote_resume
PARAMS ((int pid
, int step
, int siggnal
));
170 remote_start_remote
PARAMS ((char *dummy
));
173 remote_open
PARAMS ((char *name
, int from_tty
));
176 remote_close
PARAMS ((int quitting
));
179 remote_store_registers
PARAMS ((int regno
));
182 getpkt
PARAMS ((char *buf
, int forever
));
185 putpkt
PARAMS ((char *buf
));
188 remote_send
PARAMS ((char *buf
));
191 readchar
PARAMS ((void));
194 remote_wait
PARAMS ((int pid
, WAITTYPE
*status
));
197 tohex
PARAMS ((int nib
));
200 fromhex
PARAMS ((int a
));
203 remote_detach
PARAMS ((char *args
, int from_tty
));
206 remote_interrupt
PARAMS ((int signo
));
209 remote_interrupt_twice
PARAMS ((int signo
));
212 interrupt_query
PARAMS ((void));
214 extern struct target_ops remote_ops
; /* Forward decl */
216 extern int baud_rate
;
218 extern int remote_debug
;
220 /* This was 5 seconds, which is a long time to sit and wait.
221 Unless this is going though some terminal server or multiplexer or
222 other form of hairy serial connection, I would think 2 seconds would
224 static int timeout
= 2;
230 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
231 remote_open knows that we don't have a file open when the program
233 serial_t remote_desc
= NULL
;
237 /* Maximum number of bytes to read/write at once. The value here
238 is chosen to fill up a packet (the headers account for the 32). */
239 #define MAXBUFBYTES ((PBUFSIZ-32)/2)
241 /* Round up PBUFSIZ to hold all the registers, at least. */
242 #if REGISTER_BYTES > MAXBUFBYTES
244 #define PBUFSIZ (REGISTER_BYTES * 2 + 32)
247 /* Clean up connection to a remote debugger. */
251 remote_close (quitting
)
255 SERIAL_CLOSE (remote_desc
);
259 /* Stub for catch_errors. */
262 remote_start_remote (dummy
)
265 immediate_quit
= 1; /* Allow user to interrupt it */
267 /* Ack any packet which the remote side has already sent. */
268 /* I'm not sure this \r is needed; we don't use it any other time we
270 SERIAL_WRITE (remote_desc
, "+\r", 2);
271 putpkt ("?"); /* initiate a query from remote machine */
274 start_remote (); /* Initialize gdb process mechanisms */
278 /* Open a connection to a remote debugger.
279 NAME is the filename used for communication. */
281 static DCACHE
*remote_dcache
;
284 remote_open (name
, from_tty
)
290 "To open a remote debug connection, you need to specify what serial\n\
291 device is attached to the remote system (e.g. /dev/ttya).");
293 target_preopen (from_tty
);
295 unpush_target (&remote_ops
);
297 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
299 remote_desc
= SERIAL_OPEN (name
);
301 perror_with_name (name
);
303 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
305 SERIAL_CLOSE (remote_desc
);
306 perror_with_name (name
);
309 SERIAL_RAW (remote_desc
);
311 /* If there is something sitting in the buffer we might take it as a
312 response to a command, which would be bad. */
313 SERIAL_FLUSH_INPUT (remote_desc
);
317 puts_filtered ("Remote debugging using ");
318 puts_filtered (name
);
319 puts_filtered ("\n");
321 push_target (&remote_ops
); /* Switch to using remote target now */
323 /* Start the remote connection; if error (0), discard this target.
324 In particular, if the user quits, be sure to discard it
325 (we'd be in an inconsistent state otherwise). */
326 if (!catch_errors (remote_start_remote
, (char *)0,
327 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
332 takes a program previously attached to and detaches it.
333 We better not have left any breakpoints
334 in the program or it'll die when it hits one.
335 Close the open connection to the remote debugger.
336 Use this when you want to detach and do something else
340 remote_detach (args
, from_tty
)
345 error ("Argument given to \"detach\" when remotely debugging.");
349 puts_filtered ("Ending remote debugging.\n");
352 /* Convert hex digit A to a number. */
358 if (a
>= '0' && a
<= '9')
360 else if (a
>= 'a' && a
<= 'f')
363 error ("Reply contains invalid hex digit");
367 /* Convert number NIB to a hex digit. */
379 /* Tell the remote machine to resume. */
382 remote_resume (pid
, step
, siggnal
)
383 int pid
, step
, siggnal
;
390 target_terminal_ours_for_output ();
391 printf_filtered ("Can't send signals to a remote system. ");
392 name
= strsigno (siggnal
);
394 printf_filtered (name
);
396 printf_filtered ("Signal %d", siggnal
);
397 printf_filtered (" not sent.\n");
398 target_terminal_inferior ();
401 dcache_flush (remote_dcache
);
403 strcpy (buf
, step
? "s": "c");
408 /* Send ^C to target to halt it. Target will respond, and send us a
412 remote_interrupt (signo
)
415 /* If this doesn't work, try more severe steps. */
416 signal (signo
, remote_interrupt_twice
);
419 printf ("remote_interrupt called\n");
421 SERIAL_WRITE (remote_desc
, "\003", 1); /* Send a ^C */
424 static void (*ofunc
)();
426 /* The user typed ^C twice. */
428 remote_interrupt_twice (signo
)
431 signal (signo
, ofunc
);
435 signal (signo
, remote_interrupt
);
438 /* Ask the user what to do when an interrupt is received. */
443 target_terminal_ours ();
445 if (query ("Interrupted while waiting for the program.\n\
446 Give up (and stop debugging it)? "))
448 target_mourn_inferior ();
449 return_to_top_level (RETURN_QUIT
);
452 target_terminal_inferior ();
455 /* Wait until the remote machine stops, then return,
456 storing status in STATUS just as `wait' would.
457 Returns "pid" (though it's not clear what, if anything, that
458 means in the case of this target). */
461 remote_wait (pid
, status
)
465 unsigned char buf
[PBUFSIZ
];
467 WSETEXIT ((*status
), 0);
473 ofunc
= (void (*)()) signal (SIGINT
, remote_interrupt
);
474 getpkt ((char *) buf
, 1);
475 signal (SIGINT
, ofunc
);
478 warning ("Remote failure reply: %s", buf
);
479 else if (buf
[0] == 'T')
483 char regs
[MAX_REGISTER_RAW_SIZE
];
485 /* Expedited reply, containing Signal, {regno, reg} repeat */
486 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
488 n... = register number
489 r... = register contents
492 p
= &buf
[3]; /* after Txx */
498 regno
= strtol (p
, &p1
, 16); /* Read the register number */
501 warning ("Remote sent badly formed register number: %s\nPacket: '%s'\n",
507 warning ("Malformed packet (missing colon): %s\nPacket: '%s'\n",
510 if (regno
>= NUM_REGS
)
511 warning ("Remote sent bad register number %d: %s\nPacket: '%s'\n",
514 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
516 if (p
[0] == 0 || p
[1] == 0)
517 warning ("Remote reply is too short: %s", buf
);
518 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
523 warning ("Remote register badly formatted: %s", buf
);
525 supply_register (regno
, regs
);
529 else if (buf
[0] == 'N')
532 bfd_vma text_addr
, data_addr
, bss_addr
;
534 /* Relocate object file. Format is NAATT;DD;BB where AA is
535 the signal number, TT is the new text address, DD is the
536 new data address, and BB is the new bss address. This is
537 used by the NLM stub; gdb may see more sections. */
539 text_addr
= strtoul (p
, &p1
, 16);
540 if (p1
== p
|| *p1
!= ';')
541 warning ("Malformed relocation packet: Packet '%s'", buf
);
543 data_addr
= strtoul (p
, &p1
, 16);
544 if (p1
== p
|| *p1
!= ';')
545 warning ("Malformed relocation packet: Packet '%s'", buf
);
547 bss_addr
= strtoul (p
, &p1
, 16);
549 warning ("Malformed relocation packet: Packet '%s'", buf
);
551 if (symfile_objfile
!= NULL
552 && (ANOFFSET (symfile_objfile
->section_offsets
,
553 SECT_OFF_TEXT
) != text_addr
554 || ANOFFSET (symfile_objfile
->section_offsets
,
555 SECT_OFF_DATA
) != data_addr
556 || ANOFFSET (symfile_objfile
->section_offsets
,
557 SECT_OFF_BSS
) != bss_addr
))
559 struct section_offsets
*offs
;
561 /* FIXME: This code assumes gdb-stabs.h is being used;
562 it's broken for xcoff, dwarf, sdb-coff, etc. But
563 there is no simple canonical representation for this
564 stuff. (Just what does "text" as seen by the stub
567 /* FIXME: Why don't the various symfile_offsets routines
568 in the sym_fns vectors set this?
569 (no good reason -kingdon). */
570 if (symfile_objfile
->num_sections
== 0)
571 symfile_objfile
->num_sections
= SECT_OFF_MAX
;
573 offs
= ((struct section_offsets
*)
574 alloca (sizeof (struct section_offsets
)
575 + (symfile_objfile
->num_sections
576 * sizeof (offs
->offsets
))));
577 memcpy (offs
, symfile_objfile
->section_offsets
,
578 (sizeof (struct section_offsets
)
579 + (symfile_objfile
->num_sections
580 * sizeof (offs
->offsets
))));
581 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
582 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
583 ANOFFSET (offs
, SECT_OFF_BSS
) = bss_addr
;
585 objfile_relocate (symfile_objfile
, offs
);
587 struct obj_section
*s
;
590 abfd
= symfile_objfile
->obfd
;
592 for (s
= symfile_objfile
->sections
;
593 s
< symfile_objfile
->sections_end
; ++s
)
597 flags
= bfd_get_section_flags (abfd
, s
->sec_ptr
);
599 if (flags
& SEC_CODE
)
601 s
->addr
+= text_addr
;
602 s
->endaddr
+= text_addr
;
604 else if (flags
& (SEC_DATA
| SEC_LOAD
))
606 s
->addr
+= data_addr
;
607 s
->endaddr
+= data_addr
;
609 else if (flags
& SEC_ALLOC
)
612 s
->endaddr
+= bss_addr
;
619 else if (buf
[0] == 'W')
621 /* The remote process exited. */
622 WSETEXIT (*status
, (fromhex (buf
[1]) << 4) + fromhex (buf
[2]));
625 else if (buf
[0] == 'S')
628 warning ("Invalid remote reply: %s", buf
);
631 WSETSTOP ((*status
), (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2]))));
636 /* Number of bytes of registers this stub implements. */
637 static int register_bytes_found
;
639 /* Read the remote registers into the block REGS. */
640 /* Currently we just read all the registers, so we don't use regno. */
643 remote_fetch_registers (regno
)
649 char regs
[REGISTER_BYTES
];
654 /* Unimplemented registers read as all bits zero. */
655 memset (regs
, 0, REGISTER_BYTES
);
657 /* We can get out of synch in various cases. If the first character
658 in the buffer is not a hex character, assume that has happened
659 and try to fetch another packet to read. */
660 while ((buf
[0] < '0' || buf
[0] > '9')
661 && (buf
[0] < 'a' || buf
[0] > 'f'))
664 printf ("Bad register packet; fetching a new packet\n");
668 /* Reply describes registers byte by byte, each byte encoded as two
669 hex characters. Suck them all up, then supply them to the
670 register cacheing/storage mechanism. */
673 for (i
= 0; i
< REGISTER_BYTES
; i
++)
679 warning ("Remote reply is of odd length: %s", buf
);
680 /* Don't change register_bytes_found in this case, and don't
681 print a second warning. */
684 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
688 if (i
!= register_bytes_found
)
690 register_bytes_found
= i
;
691 #ifdef REGISTER_BYTES_OK
692 if (!REGISTER_BYTES_OK (i
))
693 warning ("Remote reply is too short: %s", buf
);
698 for (i
= 0; i
< NUM_REGS
; i
++)
699 supply_register (i
, ®s
[REGISTER_BYTE(i
)]);
702 /* Prepare to store registers. Since we send them all, we have to
703 read out the ones we don't want to change first. */
706 remote_prepare_to_store ()
708 /* Make sure the entire registers array is valid. */
709 read_register_bytes (0, (char *)NULL
, REGISTER_BYTES
);
712 /* Store the remote registers from the contents of the block REGISTERS.
713 FIXME, eventually just store one register if that's all that is needed. */
717 remote_store_registers (regno
)
726 /* Command describes registers byte by byte,
727 each byte encoded as two hex characters. */
730 /* remote_prepare_to_store insures that register_bytes_found gets set. */
731 for (i
= 0; i
< register_bytes_found
; i
++)
733 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
734 *p
++ = tohex (registers
[i
] & 0xf);
743 /* Use of the data cache is disabled because it loses for looking at
744 and changing hardware I/O ports and the like. Accepting `volatile'
745 would perhaps be one way to fix it, but a better way which would
746 win for more cases would be to use the executable file for the text
747 segment, like the `icache' code below but done cleanly (in some
748 target-independent place, perhaps in target_xfer_memory, perhaps
749 based on assigning each target a speed or perhaps by some simpler
752 /* Read a word from remote address ADDR and return it.
753 This goes through the data cache. */
756 remote_fetch_word (addr
)
762 extern CORE_ADDR text_start
, text_end
;
764 if (addr
>= text_start
&& addr
< text_end
)
767 xfer_core_file (addr
, &buffer
, sizeof (int));
772 return dcache_fetch (remote_dcache
, addr
);
775 /* Write a word WORD into remote address ADDR.
776 This goes through the data cache. */
779 remote_store_word (addr
, word
)
783 dcache_poke (remote_dcache
, addr
, word
);
787 /* Write memory data directly to the remote machine.
788 This does not inform the data cache; the data cache uses this.
789 MEMADDR is the address in the remote memory space.
790 MYADDR is the address of the buffer in our space.
791 LEN is the number of bytes.
793 Returns number of bytes transferred, or 0 for error. */
796 remote_write_bytes (memaddr
, myaddr
, len
)
798 unsigned char *myaddr
;
805 if (len
> PBUFSIZ
/ 2 - 20)
808 sprintf (buf
, "M%x,%x:", memaddr
, len
);
810 /* We send target system values byte by byte, in increasing byte addresses,
811 each byte encoded as two hex characters. */
813 p
= buf
+ strlen (buf
);
814 for (i
= 0; i
< len
; i
++)
816 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
817 *p
++ = tohex (myaddr
[i
] & 0xf);
826 /* There is no correspondance between what the remote protocol uses
827 for errors and errno codes. We would like a cleaner way of
828 representing errors (big enough to include errno codes, bfd_error
829 codes, and others). But for now just return EIO. */
836 /* Read memory data directly from the remote machine.
837 This does not use the data cache; the data cache uses this.
838 MEMADDR is the address in the remote memory space.
839 MYADDR is the address of the buffer in our space.
840 LEN is the number of bytes.
842 Returns number of bytes transferred, or 0 for error. */
845 remote_read_bytes (memaddr
, myaddr
, len
)
847 unsigned char *myaddr
;
854 if (len
> PBUFSIZ
/ 2 - 1)
857 sprintf (buf
, "m%x,%x", memaddr
, len
);
863 /* There is no correspondance between what the remote protocol uses
864 for errors and errno codes. We would like a cleaner way of
865 representing errors (big enough to include errno codes, bfd_error
866 codes, and others). But for now just return EIO. */
871 /* Reply describes memory byte by byte,
872 each byte encoded as two hex characters. */
875 for (i
= 0; i
< len
; i
++)
877 if (p
[0] == 0 || p
[1] == 0)
878 /* Reply is short. This means that we were able to read only part
879 of what we wanted to. */
881 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
887 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
888 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
889 nonzero. Returns length of data written or read; 0 for error. */
893 remote_xfer_memory(memaddr
, myaddr
, len
, should_write
, target
)
898 struct target_ops
*target
; /* ignored */
902 int total_xferred
= 0;
906 if (len
> MAXBUFBYTES
)
907 xfersize
= MAXBUFBYTES
;
912 bytes_xferred
= remote_write_bytes (memaddr
, myaddr
, xfersize
);
914 bytes_xferred
= remote_read_bytes (memaddr
, myaddr
, xfersize
);
916 /* If we get an error, we are done xferring. */
917 if (bytes_xferred
== 0)
920 memaddr
+= bytes_xferred
;
921 myaddr
+= bytes_xferred
;
922 len
-= bytes_xferred
;
923 total_xferred
+= bytes_xferred
;
925 return total_xferred
;
929 remote_files_info (ignore
)
930 struct target_ops
*ignore
;
932 puts_filtered ("Debugging a target over a serial line.\n");
935 /* Stuff for dealing with the packets which are part of this protocol.
936 See comment at top of file for details. */
938 /* Read a single character from the remote end, masking it down to 7 bits. */
945 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
953 /* Send the command in BUF to the remote machine,
954 and read the reply into BUF.
955 Report an error if we get an error reply. */
966 error ("Remote failure reply: %s", buf
);
969 /* Send a packet to the remote machine, with error checking.
970 The data of the packet is in BUF. */
977 unsigned char csum
= 0;
979 int cnt
= strlen (buf
);
983 /* Copy the packet into buffer BUF2, encapsulating it
984 and giving it a checksum. */
986 if (cnt
> sizeof(buf2
) - 5) /* Prosanity check */
992 for (i
= 0; i
< cnt
; i
++)
998 *p
++ = tohex ((csum
>> 4) & 0xf);
999 *p
++ = tohex (csum
& 0xf);
1001 /* Send it over and over until we get a positive ack. */
1008 printf ("Sending packet: %s...", buf2
); fflush(stdout
);
1010 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
1011 perror_with_name ("putpkt: write failed");
1013 /* read until either a timeout occurs (-2) or '+' is read */
1024 case SERIAL_TIMEOUT
:
1025 break; /* Retransmit buffer */
1027 perror_with_name ("putpkt: couldn't read ACK");
1029 error ("putpkt: EOF while trying to read ACK");
1032 printf ("%02X %c ", ch
&0xFF, ch
);
1035 break; /* Here to retransmit */
1046 /* Read a packet from the remote machine, with error checking,
1047 and store it in BUF. BUF is expected to be of size PBUFSIZ.
1048 If FOREVER, wait forever rather than timing out; this is used
1049 while the target is executing user code. */
1052 getpkt (buf
, forever
)
1059 unsigned char c1
, c2
;
1061 #define MAX_RETRIES 10
1071 /* This can loop forever if the remote side sends us characters
1072 continuously, but if it pauses, we'll get a zero from readchar
1073 because of timeout. Then we'll count that as a retry. */
1076 if (c
> 0 && c
!= '$')
1079 if (c
== SERIAL_TIMEOUT
)
1083 if (++retries
>= MAX_RETRIES
)
1084 if (remote_debug
) puts_filtered ("Timed out.\n");
1088 if (c
== SERIAL_EOF
)
1089 error ("Remote connection closed");
1090 if (c
== SERIAL_ERROR
)
1091 perror_with_name ("Remote communication error");
1093 /* Force csum to be zero here because of possible error retry. */
1100 if (c
== SERIAL_TIMEOUT
)
1103 puts_filtered ("Timeout in mid-packet, retrying\n");
1104 goto whole
; /* Start a new packet, count retries */
1109 puts_filtered ("Saw new packet start in middle of old one\n");
1110 goto whole
; /* Start a new packet, count retries */
1114 if (bp
>= buf
+PBUFSIZ
-1)
1117 puts_filtered ("Remote packet too long: ");
1118 puts_filtered (buf
);
1119 puts_filtered ("\n");
1127 c1
= fromhex (readchar ());
1128 c2
= fromhex (readchar ());
1129 if ((csum
& 0xff) == (c1
<< 4) + c2
)
1131 printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
1132 (c1
<< 4) + c2
, csum
& 0xff);
1133 puts_filtered (buf
);
1134 puts_filtered ("\n");
1136 /* Try the whole thing again. */
1138 if (++retries
< MAX_RETRIES
)
1140 SERIAL_WRITE (remote_desc
, "-", 1);
1144 printf ("Ignoring packet error, continuing...\n");
1151 SERIAL_WRITE (remote_desc
, "+", 1);
1154 fprintf (stderr
,"Packet received: %s\n", buf
);
1161 /* Don't wait for it to die. I'm not really sure it matters whether
1162 we do or not. For the existing stubs, kill is a noop. */
1163 target_mourn_inferior ();
1169 unpush_target (&remote_ops
);
1170 generic_mourn_inferior ();
1173 #ifdef REMOTE_BREAKPOINT
1175 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
1176 than other targets. */
1177 static unsigned char break_insn
[] = REMOTE_BREAKPOINT
;
1179 /* Check that it fits in BREAKPOINT_MAX bytes. */
1180 static unsigned char check_break_insn_size
[BREAKPOINT_MAX
] = REMOTE_BREAKPOINT
;
1182 #else /* No REMOTE_BREAKPOINT. */
1184 /* Same old breakpoint instruction. This code does nothing different
1185 than mem-break.c. */
1186 static unsigned char break_insn
[] = BREAKPOINT
;
1188 #endif /* No REMOTE_BREAKPOINT. */
1190 /* Insert a breakpoint on targets that don't have any better breakpoint
1191 support. We read the contents of the target location and stash it,
1192 then overwrite it with a breakpoint instruction. ADDR is the target
1193 location in the target machine. CONTENTS_CACHE is a pointer to
1194 memory allocated for saving the target contents. It is guaranteed
1195 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
1196 is accomplished via BREAKPOINT_MAX). */
1199 remote_insert_breakpoint (addr
, contents_cache
)
1201 char *contents_cache
;
1205 val
= target_read_memory (addr
, contents_cache
, sizeof break_insn
);
1208 val
= target_write_memory (addr
, (char *)break_insn
, sizeof break_insn
);
1214 remote_remove_breakpoint (addr
, contents_cache
)
1216 char *contents_cache
;
1218 return target_write_memory (addr
, contents_cache
, sizeof break_insn
);
1221 /* Define the target subroutine names */
1223 struct target_ops remote_ops
= {
1224 "remote", /* to_shortname */
1225 "Remote serial target in gdb-specific protocol", /* to_longname */
1226 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
1227 Specify the serial device it is connected to (e.g. /dev/ttya).", /* to_doc */
1228 remote_open
, /* to_open */
1229 remote_close
, /* to_close */
1230 NULL
, /* to_attach */
1231 remote_detach
, /* to_detach */
1232 remote_resume
, /* to_resume */
1233 remote_wait
, /* to_wait */
1234 remote_fetch_registers
, /* to_fetch_registers */
1235 remote_store_registers
, /* to_store_registers */
1236 remote_prepare_to_store
, /* to_prepare_to_store */
1237 remote_xfer_memory
, /* to_xfer_memory */
1238 remote_files_info
, /* to_files_info */
1240 remote_insert_breakpoint
, /* to_insert_breakpoint */
1241 remote_remove_breakpoint
, /* to_remove_breakpoint */
1243 NULL
, /* to_terminal_init */
1244 NULL
, /* to_terminal_inferior */
1245 NULL
, /* to_terminal_ours_for_output */
1246 NULL
, /* to_terminal_ours */
1247 NULL
, /* to_terminal_info */
1248 remote_kill
, /* to_kill */
1249 generic_load
, /* to_load */
1250 NULL
, /* to_lookup_symbol */
1251 NULL
, /* to_create_inferior */
1252 remote_mourn
, /* to_mourn_inferior */
1254 0, /* to_notice_signals */
1255 process_stratum
, /* to_stratum */
1257 1, /* to_has_all_memory */
1258 1, /* to_has_memory */
1259 1, /* to_has_stack */
1260 1, /* to_has_registers */
1261 1, /* to_has_execution */
1262 NULL
, /* sections */
1263 NULL
, /* sections_end */
1264 OPS_MAGIC
/* to_magic */
1268 _initialize_remote ()
1270 add_target (&remote_ops
);
This page took 0.054728 seconds and 4 git commands to generate.