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 /* This was 5 seconds, which is a long time to sit and wait.
217 Unless this is going though some terminal server or multiplexer or
218 other form of hairy serial connection, I would think 2 seconds would
220 static int timeout
= 2;
226 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
227 remote_open knows that we don't have a file open when the program
229 serial_t remote_desc
= NULL
;
231 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
232 and i386-stub.c. Normally, no one would notice because it only matters
233 for writing large chunks of memory (e.g. in downloads). Also, this needs
234 to be more than 400 if required to hold the registers (see below, where
235 we round it up based on REGISTER_BYTES). */
238 /* Maximum number of bytes to read/write at once. The value here
239 is chosen to fill up a packet (the headers account for the 32). */
240 #define MAXBUFBYTES ((PBUFSIZ-32)/2)
242 /* Round up PBUFSIZ to hold all the registers, at least. */
243 #if REGISTER_BYTES > MAXBUFBYTES
245 #define PBUFSIZ (REGISTER_BYTES * 2 + 32)
248 /* Clean up connection to a remote debugger. */
252 remote_close (quitting
)
256 SERIAL_CLOSE (remote_desc
);
260 /* Stub for catch_errors. */
263 remote_start_remote (dummy
)
266 immediate_quit
= 1; /* Allow user to interrupt it */
268 /* Ack any packet which the remote side has already sent. */
269 /* I'm not sure this \r is needed; we don't use it any other time we
271 SERIAL_WRITE (remote_desc
, "+\r", 2);
272 putpkt ("?"); /* initiate a query from remote machine */
275 start_remote (); /* Initialize gdb process mechanisms */
279 /* Open a connection to a remote debugger.
280 NAME is the filename used for communication. */
282 static DCACHE
*remote_dcache
;
285 remote_open (name
, from_tty
)
291 "To open a remote debug connection, you need to specify what serial\n\
292 device is attached to the remote system (e.g. /dev/ttya).");
294 target_preopen (from_tty
);
296 unpush_target (&remote_ops
);
298 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
300 remote_desc
= SERIAL_OPEN (name
);
302 perror_with_name (name
);
304 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
306 SERIAL_CLOSE (remote_desc
);
307 perror_with_name (name
);
310 SERIAL_RAW (remote_desc
);
312 /* If there is something sitting in the buffer we might take it as a
313 response to a command, which would be bad. */
314 SERIAL_FLUSH_INPUT (remote_desc
);
318 puts_filtered ("Remote debugging using ");
319 puts_filtered (name
);
320 puts_filtered ("\n");
322 push_target (&remote_ops
); /* Switch to using remote target now */
324 /* Start the remote connection; if error (0), discard this target.
325 In particular, if the user quits, be sure to discard it
326 (we'd be in an inconsistent state otherwise). */
327 if (!catch_errors (remote_start_remote
, (char *)0,
328 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
333 takes a program previously attached to and detaches it.
334 We better not have left any breakpoints
335 in the program or it'll die when it hits one.
336 Close the open connection to the remote debugger.
337 Use this when you want to detach and do something else
341 remote_detach (args
, from_tty
)
346 error ("Argument given to \"detach\" when remotely debugging.");
350 puts_filtered ("Ending remote debugging.\n");
353 /* Convert hex digit A to a number. */
359 if (a
>= '0' && a
<= '9')
361 else if (a
>= 'a' && a
<= 'f')
364 error ("Reply contains invalid hex digit");
368 /* Convert number NIB to a hex digit. */
380 /* Tell the remote machine to resume. */
383 remote_resume (pid
, step
, siggnal
)
384 int pid
, step
, siggnal
;
391 target_terminal_ours_for_output ();
392 printf_filtered ("Can't send signals to a remote system. ");
393 name
= strsigno (siggnal
);
395 printf_filtered (name
);
397 printf_filtered ("Signal %d", siggnal
);
398 printf_filtered (" not sent.\n");
399 target_terminal_inferior ();
402 dcache_flush (remote_dcache
);
404 strcpy (buf
, step
? "s": "c");
409 /* Send ^C to target to halt it. Target will respond, and send us a
413 remote_interrupt (signo
)
416 /* If this doesn't work, try more severe steps. */
417 signal (signo
, remote_interrupt_twice
);
420 printf_unfiltered ("remote_interrupt called\n");
422 SERIAL_WRITE (remote_desc
, "\003", 1); /* Send a ^C */
425 static void (*ofunc
)();
427 /* The user typed ^C twice. */
429 remote_interrupt_twice (signo
)
432 signal (signo
, ofunc
);
436 signal (signo
, remote_interrupt
);
439 /* Ask the user what to do when an interrupt is received. */
444 target_terminal_ours ();
446 if (query ("Interrupted while waiting for the program.\n\
447 Give up (and stop debugging it)? "))
449 target_mourn_inferior ();
450 return_to_top_level (RETURN_QUIT
);
453 target_terminal_inferior ();
456 /* Wait until the remote machine stops, then return,
457 storing status in STATUS just as `wait' would.
458 Returns "pid" (though it's not clear what, if anything, that
459 means in the case of this target). */
462 remote_wait (pid
, status
)
466 unsigned char buf
[PBUFSIZ
];
468 WSETEXIT ((*status
), 0);
474 ofunc
= (void (*)()) signal (SIGINT
, remote_interrupt
);
475 getpkt ((char *) buf
, 1);
476 signal (SIGINT
, ofunc
);
479 warning ("Remote failure reply: %s", buf
);
480 else if (buf
[0] == 'T')
484 char regs
[MAX_REGISTER_RAW_SIZE
];
486 /* Expedited reply, containing Signal, {regno, reg} repeat */
487 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
489 n... = register number
490 r... = register contents
493 p
= &buf
[3]; /* after Txx */
499 regno
= strtol (p
, &p1
, 16); /* Read the register number */
502 warning ("Remote sent badly formed register number: %s\nPacket: '%s'\n",
508 warning ("Malformed packet (missing colon): %s\nPacket: '%s'\n",
511 if (regno
>= NUM_REGS
)
512 warning ("Remote sent bad register number %d: %s\nPacket: '%s'\n",
515 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
517 if (p
[0] == 0 || p
[1] == 0)
518 warning ("Remote reply is too short: %s", buf
);
519 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
524 warning ("Remote register badly formatted: %s", buf
);
526 supply_register (regno
, regs
);
530 else if (buf
[0] == 'N')
533 bfd_vma text_addr
, data_addr
, bss_addr
;
535 /* Relocate object file. Format is NAATT;DD;BB where AA is
536 the signal number, TT is the new text address, DD is the
537 new data address, and BB is the new bss address. This is
538 used by the NLM stub; gdb may see more sections. */
540 text_addr
= strtoul (p
, &p1
, 16);
541 if (p1
== p
|| *p1
!= ';')
542 warning ("Malformed relocation packet: Packet '%s'", buf
);
544 data_addr
= strtoul (p
, &p1
, 16);
545 if (p1
== p
|| *p1
!= ';')
546 warning ("Malformed relocation packet: Packet '%s'", buf
);
548 bss_addr
= strtoul (p
, &p1
, 16);
550 warning ("Malformed relocation packet: Packet '%s'", buf
);
552 if (symfile_objfile
!= NULL
553 && (ANOFFSET (symfile_objfile
->section_offsets
,
554 SECT_OFF_TEXT
) != text_addr
555 || ANOFFSET (symfile_objfile
->section_offsets
,
556 SECT_OFF_DATA
) != data_addr
557 || ANOFFSET (symfile_objfile
->section_offsets
,
558 SECT_OFF_BSS
) != bss_addr
))
560 struct section_offsets
*offs
;
562 /* FIXME: This code assumes gdb-stabs.h is being used;
563 it's broken for xcoff, dwarf, sdb-coff, etc. But
564 there is no simple canonical representation for this
565 stuff. (Just what does "text" as seen by the stub
568 offs
= ((struct section_offsets
*)
569 alloca (sizeof (struct section_offsets
)
570 + (symfile_objfile
->num_sections
571 * sizeof (offs
->offsets
))));
572 memcpy (offs
, symfile_objfile
->section_offsets
,
573 (sizeof (struct section_offsets
)
574 + (symfile_objfile
->num_sections
575 * sizeof (offs
->offsets
))));
576 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
577 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
578 ANOFFSET (offs
, SECT_OFF_BSS
) = bss_addr
;
580 objfile_relocate (symfile_objfile
, offs
);
582 struct obj_section
*s
;
585 abfd
= symfile_objfile
->obfd
;
587 for (s
= symfile_objfile
->sections
;
588 s
< symfile_objfile
->sections_end
; ++s
)
592 flags
= bfd_get_section_flags (abfd
, s
->sec_ptr
);
594 if (flags
& SEC_CODE
)
596 s
->addr
+= text_addr
;
597 s
->endaddr
+= text_addr
;
599 else if (flags
& (SEC_DATA
| SEC_LOAD
))
601 s
->addr
+= data_addr
;
602 s
->endaddr
+= data_addr
;
604 else if (flags
& SEC_ALLOC
)
607 s
->endaddr
+= bss_addr
;
614 else if (buf
[0] == 'W')
616 /* The remote process exited. */
617 WSETEXIT (*status
, (fromhex (buf
[1]) << 4) + fromhex (buf
[2]));
620 else if (buf
[0] == 'S')
623 warning ("Invalid remote reply: %s", buf
);
626 WSETSTOP ((*status
), (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2]))));
631 /* Number of bytes of registers this stub implements. */
632 static int register_bytes_found
;
634 /* Read the remote registers into the block REGS. */
635 /* Currently we just read all the registers, so we don't use regno. */
638 remote_fetch_registers (regno
)
644 char regs
[REGISTER_BYTES
];
649 /* Unimplemented registers read as all bits zero. */
650 memset (regs
, 0, REGISTER_BYTES
);
652 /* We can get out of synch in various cases. If the first character
653 in the buffer is not a hex character, assume that has happened
654 and try to fetch another packet to read. */
655 while ((buf
[0] < '0' || buf
[0] > '9')
656 && (buf
[0] < 'a' || buf
[0] > 'f'))
659 printf_unfiltered ("Bad register packet; fetching a new packet\n");
663 /* Reply describes registers byte by byte, each byte encoded as two
664 hex characters. Suck them all up, then supply them to the
665 register cacheing/storage mechanism. */
668 for (i
= 0; i
< REGISTER_BYTES
; i
++)
674 warning ("Remote reply is of odd length: %s", buf
);
675 /* Don't change register_bytes_found in this case, and don't
676 print a second warning. */
679 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
683 if (i
!= register_bytes_found
)
685 register_bytes_found
= i
;
686 #ifdef REGISTER_BYTES_OK
687 if (!REGISTER_BYTES_OK (i
))
688 warning ("Remote reply is too short: %s", buf
);
693 for (i
= 0; i
< NUM_REGS
; i
++)
694 supply_register (i
, ®s
[REGISTER_BYTE(i
)]);
697 /* Prepare to store registers. Since we send them all, we have to
698 read out the ones we don't want to change first. */
701 remote_prepare_to_store ()
703 /* Make sure the entire registers array is valid. */
704 read_register_bytes (0, (char *)NULL
, REGISTER_BYTES
);
707 /* Store the remote registers from the contents of the block REGISTERS.
708 FIXME, eventually just store one register if that's all that is needed. */
712 remote_store_registers (regno
)
721 /* Command describes registers byte by byte,
722 each byte encoded as two hex characters. */
725 /* remote_prepare_to_store insures that register_bytes_found gets set. */
726 for (i
= 0; i
< register_bytes_found
; i
++)
728 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
729 *p
++ = tohex (registers
[i
] & 0xf);
738 /* Use of the data cache is disabled because it loses for looking at
739 and changing hardware I/O ports and the like. Accepting `volatile'
740 would perhaps be one way to fix it, but a better way which would
741 win for more cases would be to use the executable file for the text
742 segment, like the `icache' code below but done cleanly (in some
743 target-independent place, perhaps in target_xfer_memory, perhaps
744 based on assigning each target a speed or perhaps by some simpler
747 /* Read a word from remote address ADDR and return it.
748 This goes through the data cache. */
751 remote_fetch_word (addr
)
757 extern CORE_ADDR text_start
, text_end
;
759 if (addr
>= text_start
&& addr
< text_end
)
762 xfer_core_file (addr
, &buffer
, sizeof (int));
767 return dcache_fetch (remote_dcache
, addr
);
770 /* Write a word WORD into remote address ADDR.
771 This goes through the data cache. */
774 remote_store_word (addr
, word
)
778 dcache_poke (remote_dcache
, addr
, word
);
782 /* Write memory data directly to the remote machine.
783 This does not inform the data cache; the data cache uses this.
784 MEMADDR is the address in the remote memory space.
785 MYADDR is the address of the buffer in our space.
786 LEN is the number of bytes.
788 Returns number of bytes transferred, or 0 for error. */
791 remote_write_bytes (memaddr
, myaddr
, len
)
793 unsigned char *myaddr
;
800 sprintf (buf
, "M%x,%x:", memaddr
, len
);
802 /* We send target system values byte by byte, in increasing byte addresses,
803 each byte encoded as two hex characters. */
805 p
= buf
+ strlen (buf
);
806 for (i
= 0; i
< len
; i
++)
808 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
809 *p
++ = tohex (myaddr
[i
] & 0xf);
818 /* There is no correspondance between what the remote protocol uses
819 for errors and errno codes. We would like a cleaner way of
820 representing errors (big enough to include errno codes, bfd_error
821 codes, and others). But for now just return EIO. */
828 /* Read memory data directly from the remote machine.
829 This does not use the data cache; the data cache uses this.
830 MEMADDR is the address in the remote memory space.
831 MYADDR is the address of the buffer in our space.
832 LEN is the number of bytes.
834 Returns number of bytes transferred, or 0 for error. */
837 remote_read_bytes (memaddr
, myaddr
, len
)
839 unsigned char *myaddr
;
846 if (len
> PBUFSIZ
/ 2 - 1)
849 sprintf (buf
, "m%x,%x", memaddr
, len
);
855 /* There is no correspondance between what the remote protocol uses
856 for errors and errno codes. We would like a cleaner way of
857 representing errors (big enough to include errno codes, bfd_error
858 codes, and others). But for now just return EIO. */
863 /* Reply describes memory byte by byte,
864 each byte encoded as two hex characters. */
867 for (i
= 0; i
< len
; i
++)
869 if (p
[0] == 0 || p
[1] == 0)
870 /* Reply is short. This means that we were able to read only part
871 of what we wanted to. */
873 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
879 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
880 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
881 nonzero. Returns length of data written or read; 0 for error. */
885 remote_xfer_memory(memaddr
, myaddr
, len
, should_write
, target
)
890 struct target_ops
*target
; /* ignored */
894 int total_xferred
= 0;
898 if (len
> MAXBUFBYTES
)
899 xfersize
= MAXBUFBYTES
;
904 bytes_xferred
= remote_write_bytes (memaddr
, myaddr
, xfersize
);
906 bytes_xferred
= remote_read_bytes (memaddr
, myaddr
, xfersize
);
908 /* If we get an error, we are done xferring. */
909 if (bytes_xferred
== 0)
912 memaddr
+= bytes_xferred
;
913 myaddr
+= bytes_xferred
;
914 len
-= bytes_xferred
;
915 total_xferred
+= bytes_xferred
;
917 return total_xferred
;
921 remote_files_info (ignore
)
922 struct target_ops
*ignore
;
924 puts_filtered ("Debugging a target over a serial line.\n");
927 /* Stuff for dealing with the packets which are part of this protocol.
928 See comment at top of file for details. */
930 /* Read a single character from the remote end, masking it down to 7 bits. */
937 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
945 /* Send the command in BUF to the remote machine,
946 and read the reply into BUF.
947 Report an error if we get an error reply. */
958 error ("Remote failure reply: %s", buf
);
961 /* Send a packet to the remote machine, with error checking.
962 The data of the packet is in BUF. */
969 unsigned char csum
= 0;
971 int cnt
= strlen (buf
);
975 /* Copy the packet into buffer BUF2, encapsulating it
976 and giving it a checksum. */
978 if (cnt
> sizeof(buf2
) - 5) /* Prosanity check */
984 for (i
= 0; i
< cnt
; i
++)
990 *p
++ = tohex ((csum
>> 4) & 0xf);
991 *p
++ = tohex (csum
& 0xf);
993 /* Send it over and over until we get a positive ack. */
1000 printf_unfiltered ("Sending packet: %s...", buf2
); gdb_flush(gdb_stdout
);
1002 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
1003 perror_with_name ("putpkt: write failed");
1005 /* read until either a timeout occurs (-2) or '+' is read */
1014 printf_unfiltered("Ack\n");
1016 case SERIAL_TIMEOUT
:
1017 break; /* Retransmit buffer */
1019 perror_with_name ("putpkt: couldn't read ACK");
1021 error ("putpkt: EOF while trying to read ACK");
1024 printf_unfiltered ("%02X %c ", ch
&0xFF, ch
);
1027 break; /* Here to retransmit */
1038 /* Read a packet from the remote machine, with error checking,
1039 and store it in BUF. BUF is expected to be of size PBUFSIZ.
1040 If FOREVER, wait forever rather than timing out; this is used
1041 while the target is executing user code. */
1044 getpkt (buf
, forever
)
1051 unsigned char c1
, c2
;
1053 #define MAX_RETRIES 10
1063 /* This can loop forever if the remote side sends us characters
1064 continuously, but if it pauses, we'll get a zero from readchar
1065 because of timeout. Then we'll count that as a retry. */
1068 if (c
> 0 && c
!= '$')
1071 if (c
== SERIAL_TIMEOUT
)
1075 if (++retries
>= MAX_RETRIES
)
1076 if (remote_debug
) puts_filtered ("Timed out.\n");
1080 if (c
== SERIAL_EOF
)
1081 error ("Remote connection closed");
1082 if (c
== SERIAL_ERROR
)
1083 perror_with_name ("Remote communication error");
1085 /* Force csum to be zero here because of possible error retry. */
1092 if (c
== SERIAL_TIMEOUT
)
1095 puts_filtered ("Timeout in mid-packet, retrying\n");
1096 goto whole
; /* Start a new packet, count retries */
1101 puts_filtered ("Saw new packet start in middle of old one\n");
1102 goto whole
; /* Start a new packet, count retries */
1106 if (bp
>= buf
+PBUFSIZ
-1)
1109 puts_filtered ("Remote packet too long: ");
1110 puts_filtered (buf
);
1111 puts_filtered ("\n");
1119 c1
= fromhex (readchar ());
1120 c2
= fromhex (readchar ());
1121 if ((csum
& 0xff) == (c1
<< 4) + c2
)
1123 printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
1124 (c1
<< 4) + c2
, csum
& 0xff);
1125 puts_filtered (buf
);
1126 puts_filtered ("\n");
1128 /* Try the whole thing again. */
1130 if (++retries
< MAX_RETRIES
)
1132 SERIAL_WRITE (remote_desc
, "-", 1);
1136 printf_unfiltered ("Ignoring packet error, continuing...\n");
1143 SERIAL_WRITE (remote_desc
, "+", 1);
1146 fprintf_unfiltered (gdb_stderr
,"Packet received: %s\n", buf
);
1153 /* Don't wait for it to die. I'm not really sure it matters whether
1154 we do or not. For the existing stubs, kill is a noop. */
1155 target_mourn_inferior ();
1161 unpush_target (&remote_ops
);
1162 generic_mourn_inferior ();
1165 #ifdef REMOTE_BREAKPOINT
1167 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
1168 than other targets. */
1169 static unsigned char break_insn
[] = REMOTE_BREAKPOINT
;
1171 /* Check that it fits in BREAKPOINT_MAX bytes. */
1172 static unsigned char check_break_insn_size
[BREAKPOINT_MAX
] = REMOTE_BREAKPOINT
;
1174 #else /* No REMOTE_BREAKPOINT. */
1176 /* Same old breakpoint instruction. This code does nothing different
1177 than mem-break.c. */
1178 static unsigned char break_insn
[] = BREAKPOINT
;
1180 #endif /* No REMOTE_BREAKPOINT. */
1182 /* Insert a breakpoint on targets that don't have any better breakpoint
1183 support. We read the contents of the target location and stash it,
1184 then overwrite it with a breakpoint instruction. ADDR is the target
1185 location in the target machine. CONTENTS_CACHE is a pointer to
1186 memory allocated for saving the target contents. It is guaranteed
1187 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
1188 is accomplished via BREAKPOINT_MAX). */
1191 remote_insert_breakpoint (addr
, contents_cache
)
1193 char *contents_cache
;
1197 val
= target_read_memory (addr
, contents_cache
, sizeof break_insn
);
1200 val
= target_write_memory (addr
, (char *)break_insn
, sizeof break_insn
);
1206 remote_remove_breakpoint (addr
, contents_cache
)
1208 char *contents_cache
;
1210 return target_write_memory (addr
, contents_cache
, sizeof break_insn
);
1213 /* Define the target subroutine names */
1215 struct target_ops remote_ops
= {
1216 "remote", /* to_shortname */
1217 "Remote serial target in gdb-specific protocol", /* to_longname */
1218 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
1219 Specify the serial device it is connected to (e.g. /dev/ttya).", /* to_doc */
1220 remote_open
, /* to_open */
1221 remote_close
, /* to_close */
1222 NULL
, /* to_attach */
1223 remote_detach
, /* to_detach */
1224 remote_resume
, /* to_resume */
1225 remote_wait
, /* to_wait */
1226 remote_fetch_registers
, /* to_fetch_registers */
1227 remote_store_registers
, /* to_store_registers */
1228 remote_prepare_to_store
, /* to_prepare_to_store */
1229 remote_xfer_memory
, /* to_xfer_memory */
1230 remote_files_info
, /* to_files_info */
1232 remote_insert_breakpoint
, /* to_insert_breakpoint */
1233 remote_remove_breakpoint
, /* to_remove_breakpoint */
1235 NULL
, /* to_terminal_init */
1236 NULL
, /* to_terminal_inferior */
1237 NULL
, /* to_terminal_ours_for_output */
1238 NULL
, /* to_terminal_ours */
1239 NULL
, /* to_terminal_info */
1240 remote_kill
, /* to_kill */
1241 generic_load
, /* to_load */
1242 NULL
, /* to_lookup_symbol */
1243 NULL
, /* to_create_inferior */
1244 remote_mourn
, /* to_mourn_inferior */
1246 0, /* to_notice_signals */
1247 process_stratum
, /* to_stratum */
1249 1, /* to_has_all_memory */
1250 1, /* to_has_memory */
1251 1, /* to_has_stack */
1252 1, /* to_has_registers */
1253 1, /* to_has_execution */
1254 NULL
, /* sections */
1255 NULL
, /* sections_end */
1256 OPS_MAGIC
/* to_magic */
1258 #endif /* Use remote. */
1261 _initialize_remote ()
1263 #if !defined(DONT_USE_REMOTE)
1264 add_target (&remote_ops
);
This page took 0.055661 seconds and 4 git commands to generate.