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., 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.
119 search tAA:PP,MM Search backward starting at address
120 AA for a match with pattern PP and
121 mask MM. PP and MM are 4 bytes.
122 Not supported by all stubs.
124 Responses can be run-length encoded to save space. A '*' means that
125 the next two characters are hex digits giving a repeat count which
126 stands for that many repititions of the character preceding the '*'.
127 Note that this means that responses cannot contain '*'. Example:
128 "0*03" means the same as "0000". */
134 #include "inferior.h"
139 #include "terminal.h"
141 #include "objfiles.h"
142 #include "gdb-stabs.h"
146 #if !defined(DONT_USE_REMOTE)
148 #include <sys/types.h>
154 /* Prototypes for local functions */
157 remote_write_bytes
PARAMS ((CORE_ADDR memaddr
, unsigned char *myaddr
, int len
));
160 remote_read_bytes
PARAMS ((CORE_ADDR memaddr
, unsigned char *myaddr
, int len
));
163 remote_files_info
PARAMS ((struct target_ops
*ignore
));
166 remote_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
, int len
,
167 int should_write
, struct target_ops
*target
));
170 remote_prepare_to_store
PARAMS ((void));
173 remote_fetch_registers
PARAMS ((int regno
));
176 remote_resume
PARAMS ((int pid
, int step
, enum target_signal siggnal
));
179 remote_start_remote
PARAMS ((char *dummy
));
182 remote_open
PARAMS ((char *name
, int from_tty
));
185 remote_close
PARAMS ((int quitting
));
188 remote_store_registers
PARAMS ((int regno
));
191 getpkt
PARAMS ((char *buf
, int forever
));
194 putpkt
PARAMS ((char *buf
));
197 remote_send
PARAMS ((char *buf
));
200 readchar
PARAMS ((void));
202 static int remote_wait
PARAMS ((int pid
, struct target_waitstatus
*status
));
205 tohex
PARAMS ((int nib
));
208 fromhex
PARAMS ((int a
));
211 remote_detach
PARAMS ((char *args
, int from_tty
));
214 remote_interrupt
PARAMS ((int signo
));
217 remote_interrupt_twice
PARAMS ((int signo
));
220 interrupt_query
PARAMS ((void));
222 extern struct target_ops remote_ops
; /* Forward decl */
224 /* This was 5 seconds, which is a long time to sit and wait.
225 Unless this is going though some terminal server or multiplexer or
226 other form of hairy serial connection, I would think 2 seconds would
228 static int timeout
= 2;
234 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
235 remote_open knows that we don't have a file open when the program
237 serial_t remote_desc
= NULL
;
239 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
240 and i386-stub.c. Normally, no one would notice because it only matters
241 for writing large chunks of memory (e.g. in downloads). Also, this needs
242 to be more than 400 if required to hold the registers (see below, where
243 we round it up based on REGISTER_BYTES). */
246 /* Maximum number of bytes to read/write at once. The value here
247 is chosen to fill up a packet (the headers account for the 32). */
248 #define MAXBUFBYTES ((PBUFSIZ-32)/2)
250 /* Round up PBUFSIZ to hold all the registers, at least. */
251 #if REGISTER_BYTES > MAXBUFBYTES
253 #define PBUFSIZ (REGISTER_BYTES * 2 + 32)
256 /* Clean up connection to a remote debugger. */
260 remote_close (quitting
)
264 SERIAL_CLOSE (remote_desc
);
268 /* Stub for catch_errors. */
271 remote_start_remote (dummy
)
274 immediate_quit
= 1; /* Allow user to interrupt it */
276 /* Ack any packet which the remote side has already sent. */
277 /* I'm not sure this \r is needed; we don't use it any other time we
279 SERIAL_WRITE (remote_desc
, "+\r", 2);
280 putpkt ("?"); /* initiate a query from remote machine */
283 start_remote (); /* Initialize gdb process mechanisms */
287 /* Open a connection to a remote debugger.
288 NAME is the filename used for communication. */
290 static DCACHE
*remote_dcache
;
293 remote_open (name
, from_tty
)
299 "To open a remote debug connection, you need to specify what serial\n\
300 device is attached to the remote system (e.g. /dev/ttya).");
302 target_preopen (from_tty
);
304 unpush_target (&remote_ops
);
306 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
308 remote_desc
= SERIAL_OPEN (name
);
310 perror_with_name (name
);
314 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
316 SERIAL_CLOSE (remote_desc
);
317 perror_with_name (name
);
321 SERIAL_RAW (remote_desc
);
323 /* If there is something sitting in the buffer we might take it as a
324 response to a command, which would be bad. */
325 SERIAL_FLUSH_INPUT (remote_desc
);
329 puts_filtered ("Remote debugging using ");
330 puts_filtered (name
);
331 puts_filtered ("\n");
333 push_target (&remote_ops
); /* Switch to using remote target now */
335 /* Start the remote connection; if error (0), discard this target.
336 In particular, if the user quits, be sure to discard it
337 (we'd be in an inconsistent state otherwise). */
338 if (!catch_errors (remote_start_remote
, (char *)0,
339 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
344 takes a program previously attached to and detaches it.
345 We better not have left any breakpoints
346 in the program or it'll die when it hits one.
347 Close the open connection to the remote debugger.
348 Use this when you want to detach and do something else
352 remote_detach (args
, from_tty
)
357 error ("Argument given to \"detach\" when remotely debugging.");
361 puts_filtered ("Ending remote debugging.\n");
364 /* Convert hex digit A to a number. */
370 if (a
>= '0' && a
<= '9')
372 else if (a
>= 'a' && a
<= 'f')
375 error ("Reply contains invalid hex digit");
379 /* Convert number NIB to a hex digit. */
391 /* Tell the remote machine to resume. */
394 remote_resume (pid
, step
, siggnal
)
396 enum target_signal siggnal
;
403 target_terminal_ours_for_output ();
405 ("Can't send signals to a remote system. %s not sent.\n",
406 target_signal_to_name (siggnal
));
407 target_terminal_inferior ();
410 dcache_flush (remote_dcache
);
412 strcpy (buf
, step
? "s": "c");
417 /* Send ^C to target to halt it. Target will respond, and send us a
421 remote_interrupt (signo
)
424 /* If this doesn't work, try more severe steps. */
425 signal (signo
, remote_interrupt_twice
);
428 printf_unfiltered ("remote_interrupt called\n");
430 SERIAL_WRITE (remote_desc
, "\003", 1); /* Send a ^C */
433 static void (*ofunc
)();
435 /* The user typed ^C twice. */
437 remote_interrupt_twice (signo
)
440 signal (signo
, ofunc
);
444 signal (signo
, remote_interrupt
);
447 /* Ask the user what to do when an interrupt is received. */
452 target_terminal_ours ();
454 if (query ("Interrupted while waiting for the program.\n\
455 Give up (and stop debugging it)? "))
457 target_mourn_inferior ();
458 return_to_top_level (RETURN_QUIT
);
461 target_terminal_inferior ();
464 /* Wait until the remote machine stops, then return,
465 storing status in STATUS just as `wait' would.
466 Returns "pid" (though it's not clear what, if anything, that
467 means in the case of this target). */
470 remote_wait (pid
, status
)
472 struct target_waitstatus
*status
;
474 unsigned char buf
[PBUFSIZ
];
476 status
->kind
= TARGET_WAITKIND_EXITED
;
477 status
->value
.integer
= 0;
483 ofunc
= (void (*)()) signal (SIGINT
, remote_interrupt
);
484 getpkt ((char *) buf
, 1);
485 signal (SIGINT
, ofunc
);
488 warning ("Remote failure reply: %s", buf
);
489 else if (buf
[0] == 'T')
493 char regs
[MAX_REGISTER_RAW_SIZE
];
495 /* Expedited reply, containing Signal, {regno, reg} repeat */
496 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
498 n... = register number
499 r... = register contents
502 p
= &buf
[3]; /* after Txx */
508 regno
= strtol (p
, &p1
, 16); /* Read the register number */
511 warning ("Remote sent badly formed register number: %s\nPacket: '%s'\n",
517 warning ("Malformed packet (missing colon): %s\nPacket: '%s'\n",
520 if (regno
>= NUM_REGS
)
521 warning ("Remote sent bad register number %d: %s\nPacket: '%s'\n",
524 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
526 if (p
[0] == 0 || p
[1] == 0)
527 warning ("Remote reply is too short: %s", buf
);
528 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
533 warning ("Remote register badly formatted: %s", buf
);
535 supply_register (regno
, regs
);
539 else if (buf
[0] == 'N')
542 bfd_vma text_addr
, data_addr
, bss_addr
;
544 /* Relocate object file. Format is NAATT;DD;BB where AA is
545 the signal number, TT is the new text address, DD is the
546 new data address, and BB is the new bss address. This is
547 used by the NLM stub; gdb may see more sections. */
549 text_addr
= strtoul (p
, &p1
, 16);
550 if (p1
== p
|| *p1
!= ';')
551 warning ("Malformed relocation packet: Packet '%s'", buf
);
553 data_addr
= strtoul (p
, &p1
, 16);
554 if (p1
== p
|| *p1
!= ';')
555 warning ("Malformed relocation packet: Packet '%s'", buf
);
557 bss_addr
= strtoul (p
, &p1
, 16);
559 warning ("Malformed relocation packet: Packet '%s'", buf
);
561 if (symfile_objfile
!= NULL
562 && (ANOFFSET (symfile_objfile
->section_offsets
,
563 SECT_OFF_TEXT
) != text_addr
564 || ANOFFSET (symfile_objfile
->section_offsets
,
565 SECT_OFF_DATA
) != data_addr
566 || ANOFFSET (symfile_objfile
->section_offsets
,
567 SECT_OFF_BSS
) != bss_addr
))
569 struct section_offsets
*offs
;
571 /* FIXME: This code assumes gdb-stabs.h is being used;
572 it's broken for xcoff, dwarf, sdb-coff, etc. But
573 there is no simple canonical representation for this
574 stuff. (Just what does "text" as seen by the stub
577 offs
= ((struct section_offsets
*)
578 alloca (sizeof (struct section_offsets
)
579 + (symfile_objfile
->num_sections
580 * sizeof (offs
->offsets
))));
581 memcpy (offs
, symfile_objfile
->section_offsets
,
582 (sizeof (struct section_offsets
)
583 + (symfile_objfile
->num_sections
584 * sizeof (offs
->offsets
))));
585 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
586 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
587 ANOFFSET (offs
, SECT_OFF_BSS
) = bss_addr
;
589 objfile_relocate (symfile_objfile
, offs
);
591 struct obj_section
*s
;
594 abfd
= symfile_objfile
->obfd
;
596 for (s
= symfile_objfile
->sections
;
597 s
< symfile_objfile
->sections_end
; ++s
)
601 flags
= bfd_get_section_flags (abfd
, s
->the_bfd_section
);
603 if (flags
& SEC_CODE
)
605 s
->addr
+= text_addr
;
606 s
->endaddr
+= text_addr
;
608 else if (flags
& (SEC_DATA
| SEC_LOAD
))
610 s
->addr
+= data_addr
;
611 s
->endaddr
+= data_addr
;
613 else if (flags
& SEC_ALLOC
)
616 s
->endaddr
+= bss_addr
;
623 else if (buf
[0] == 'W')
625 /* The remote process exited. */
626 status
->kind
= TARGET_WAITKIND_EXITED
;
627 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
630 else if (buf
[0] == 'S')
633 warning ("Invalid remote reply: %s", buf
);
636 status
->kind
= TARGET_WAITKIND_STOPPED
;
637 status
->value
.sig
= (enum target_signal
)
638 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
643 /* Number of bytes of registers this stub implements. */
644 static int register_bytes_found
;
646 /* Read the remote registers into the block REGS. */
647 /* Currently we just read all the registers, so we don't use regno. */
650 remote_fetch_registers (regno
)
656 char regs
[REGISTER_BYTES
];
661 /* Unimplemented registers read as all bits zero. */
662 memset (regs
, 0, REGISTER_BYTES
);
664 /* We can get out of synch in various cases. If the first character
665 in the buffer is not a hex character, assume that has happened
666 and try to fetch another packet to read. */
667 while ((buf
[0] < '0' || buf
[0] > '9')
668 && (buf
[0] < 'a' || buf
[0] > 'f'))
671 printf_unfiltered ("Bad register packet; fetching a new packet\n");
675 /* Reply describes registers byte by byte, each byte encoded as two
676 hex characters. Suck them all up, then supply them to the
677 register cacheing/storage mechanism. */
680 for (i
= 0; i
< REGISTER_BYTES
; i
++)
686 warning ("Remote reply is of odd length: %s", buf
);
687 /* Don't change register_bytes_found in this case, and don't
688 print a second warning. */
691 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
695 if (i
!= register_bytes_found
)
697 register_bytes_found
= i
;
698 #ifdef REGISTER_BYTES_OK
699 if (!REGISTER_BYTES_OK (i
))
700 warning ("Remote reply is too short: %s", buf
);
705 for (i
= 0; i
< NUM_REGS
; i
++)
706 supply_register (i
, ®s
[REGISTER_BYTE(i
)]);
709 /* Prepare to store registers. Since we send them all, we have to
710 read out the ones we don't want to change first. */
713 remote_prepare_to_store ()
715 /* Make sure the entire registers array is valid. */
716 read_register_bytes (0, (char *)NULL
, REGISTER_BYTES
);
719 /* Store the remote registers from the contents of the block REGISTERS.
720 FIXME, eventually just store one register if that's all that is needed. */
724 remote_store_registers (regno
)
733 /* Command describes registers byte by byte,
734 each byte encoded as two hex characters. */
737 /* remote_prepare_to_store insures that register_bytes_found gets set. */
738 for (i
= 0; i
< register_bytes_found
; i
++)
740 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
741 *p
++ = tohex (registers
[i
] & 0xf);
750 /* Use of the data cache is disabled because it loses for looking at
751 and changing hardware I/O ports and the like. Accepting `volatile'
752 would perhaps be one way to fix it, but a better way which would
753 win for more cases would be to use the executable file for the text
754 segment, like the `icache' code below but done cleanly (in some
755 target-independent place, perhaps in target_xfer_memory, perhaps
756 based on assigning each target a speed or perhaps by some simpler
759 /* Read a word from remote address ADDR and return it.
760 This goes through the data cache. */
763 remote_fetch_word (addr
)
769 extern CORE_ADDR text_start
, text_end
;
771 if (addr
>= text_start
&& addr
< text_end
)
774 xfer_core_file (addr
, &buffer
, sizeof (int));
779 return dcache_fetch (remote_dcache
, addr
);
782 /* Write a word WORD into remote address ADDR.
783 This goes through the data cache. */
786 remote_store_word (addr
, word
)
790 dcache_poke (remote_dcache
, addr
, word
);
794 /* Write memory data directly to the remote machine.
795 This does not inform the data cache; the data cache uses this.
796 MEMADDR is the address in the remote memory space.
797 MYADDR is the address of the buffer in our space.
798 LEN is the number of bytes.
800 Returns number of bytes transferred, or 0 for error. */
803 remote_write_bytes (memaddr
, myaddr
, len
)
805 unsigned char *myaddr
;
812 sprintf (buf
, "M%x,%x:", memaddr
, len
);
814 /* We send target system values byte by byte, in increasing byte addresses,
815 each byte encoded as two hex characters. */
817 p
= buf
+ strlen (buf
);
818 for (i
= 0; i
< len
; i
++)
820 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
821 *p
++ = tohex (myaddr
[i
] & 0xf);
830 /* There is no correspondance between what the remote protocol uses
831 for errors and errno codes. We would like a cleaner way of
832 representing errors (big enough to include errno codes, bfd_error
833 codes, and others). But for now just return EIO. */
840 /* Read memory data directly from the remote machine.
841 This does not use the data cache; the data cache uses this.
842 MEMADDR is the address in the remote memory space.
843 MYADDR is the address of the buffer in our space.
844 LEN is the number of bytes.
846 Returns number of bytes transferred, or 0 for error. */
849 remote_read_bytes (memaddr
, myaddr
, len
)
851 unsigned char *myaddr
;
858 if (len
> PBUFSIZ
/ 2 - 1)
861 sprintf (buf
, "m%x,%x", memaddr
, len
);
867 /* There is no correspondance between what the remote protocol uses
868 for errors and errno codes. We would like a cleaner way of
869 representing errors (big enough to include errno codes, bfd_error
870 codes, and others). But for now just return EIO. */
875 /* Reply describes memory byte by byte,
876 each byte encoded as two hex characters. */
879 for (i
= 0; i
< len
; i
++)
881 if (p
[0] == 0 || p
[1] == 0)
882 /* Reply is short. This means that we were able to read only part
883 of what we wanted to. */
885 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
891 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
892 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
893 nonzero. Returns length of data written or read; 0 for error. */
897 remote_xfer_memory(memaddr
, myaddr
, len
, should_write
, target
)
902 struct target_ops
*target
; /* ignored */
906 int total_xferred
= 0;
910 if (len
> MAXBUFBYTES
)
911 xfersize
= MAXBUFBYTES
;
916 bytes_xferred
= remote_write_bytes (memaddr
,
917 (unsigned char *)myaddr
, xfersize
);
919 bytes_xferred
= remote_read_bytes (memaddr
,
920 (unsigned char *)myaddr
, xfersize
);
922 /* If we get an error, we are done xferring. */
923 if (bytes_xferred
== 0)
926 memaddr
+= bytes_xferred
;
927 myaddr
+= bytes_xferred
;
928 len
-= bytes_xferred
;
929 total_xferred
+= bytes_xferred
;
931 return total_xferred
;
935 /* Enable after 4.12. */
938 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
939 addr_found
, data_found
)
947 CORE_ADDR
*addr_found
;
950 if (increment
== -4 && len
== 4)
952 long mask_long
, data_long
;
953 long data_found_long
;
954 CORE_ADDR addr_we_found
;
956 long returned_long
[2];
959 mask_long
= extract_unsigned_integer (mask
, len
);
960 data_long
= extract_unsigned_integer (data
, len
);
961 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
966 /* The stub doesn't support the 't' request. We might want to
967 remember this fact, but on the other hand the stub could be
968 switched on us. Maybe we should remember it only until
969 the next "target remote". */
970 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
971 hirange
, addr_found
, data_found
);
976 /* There is no correspondance between what the remote protocol uses
977 for errors and errno codes. We would like a cleaner way of
978 representing errors (big enough to include errno codes, bfd_error
979 codes, and others). But for now just use EIO. */
980 memory_error (EIO
, startaddr
);
983 while (*p
!= '\0' && *p
!= ',')
984 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
986 error ("Protocol error: short return for search");
989 while (*p
!= '\0' && *p
!= ',')
990 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
991 /* Ignore anything after this comma, for future extensions. */
993 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
999 *addr_found
= addr_we_found
;
1000 *data_found
= store_unsigned_integer (data_we_found
, len
);
1003 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
1004 hirange
, addr_found
, data_found
);
1009 remote_files_info (ignore
)
1010 struct target_ops
*ignore
;
1012 puts_filtered ("Debugging a target over a serial line.\n");
1015 /* Stuff for dealing with the packets which are part of this protocol.
1016 See comment at top of file for details. */
1018 /* Read a single character from the remote end, masking it down to 7 bits. */
1025 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
1033 /* Send the command in BUF to the remote machine,
1034 and read the reply into BUF.
1035 Report an error if we get an error reply. */
1046 error ("Remote failure reply: %s", buf
);
1049 /* Send a packet to the remote machine, with error checking.
1050 The data of the packet is in BUF. */
1057 unsigned char csum
= 0;
1059 int cnt
= strlen (buf
);
1063 /* Copy the packet into buffer BUF2, encapsulating it
1064 and giving it a checksum. */
1066 if (cnt
> sizeof(buf2
) - 5) /* Prosanity check */
1072 for (i
= 0; i
< cnt
; i
++)
1078 *p
++ = tohex ((csum
>> 4) & 0xf);
1079 *p
++ = tohex (csum
& 0xf);
1081 /* Send it over and over until we get a positive ack. */
1088 printf_unfiltered ("Sending packet: %s...", buf2
); gdb_flush(gdb_stdout
);
1090 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
1091 perror_with_name ("putpkt: write failed");
1093 /* read until either a timeout occurs (-2) or '+' is read */
1102 printf_unfiltered("Ack\n");
1104 case SERIAL_TIMEOUT
:
1105 break; /* Retransmit buffer */
1107 perror_with_name ("putpkt: couldn't read ACK");
1109 error ("putpkt: EOF while trying to read ACK");
1112 printf_unfiltered ("%02X %c ", ch
&0xFF, ch
);
1115 break; /* Here to retransmit */
1119 /* This is wrong. If doing a long backtrace, the user should be
1120 able to get out next time we call QUIT, without anything as violent
1121 as interrupt_query. If we want to provide a way out of here
1122 without getting to the next QUIT, it should be based on hitting
1123 ^C twice as in remote_wait. */
1133 /* Read a packet from the remote machine, with error checking,
1134 and store it in BUF. BUF is expected to be of size PBUFSIZ.
1135 If FOREVER, wait forever rather than timing out; this is used
1136 while the target is executing user code. */
1139 getpkt (retbuf
, forever
)
1146 unsigned char c1
, c2
;
1150 #define MAX_RETRIES 10
1155 /* This is wrong. If doing a long backtrace, the user should be
1156 able to get out time next we call QUIT, without anything as violent
1157 as interrupt_query. If we want to provide a way out of here
1158 without getting to the next QUIT, it should be based on hitting
1159 ^C twice as in remote_wait. */
1167 /* This can loop forever if the remote side sends us characters
1168 continuously, but if it pauses, we'll get a zero from readchar
1169 because of timeout. Then we'll count that as a retry. */
1172 if (c
> 0 && c
!= '$')
1175 if (c
== SERIAL_TIMEOUT
)
1179 if (++retries
>= MAX_RETRIES
)
1180 if (remote_debug
) puts_filtered ("Timed out.\n");
1184 if (c
== SERIAL_EOF
)
1185 error ("Remote connection closed");
1186 if (c
== SERIAL_ERROR
)
1187 perror_with_name ("Remote communication error");
1189 /* Force csum to be zero here because of possible error retry. */
1196 if (c
== SERIAL_TIMEOUT
)
1199 puts_filtered ("Timeout in mid-packet, retrying\n");
1200 goto whole
; /* Start a new packet, count retries */
1205 puts_filtered ("Saw new packet start in middle of old one\n");
1206 goto whole
; /* Start a new packet, count retries */
1210 if (bp
>= buf
+PBUFSIZ
-1)
1213 puts_filtered ("Remote packet too long: ");
1214 puts_filtered (buf
);
1215 puts_filtered ("\n");
1223 c1
= fromhex (readchar ());
1224 c2
= fromhex (readchar ());
1225 if ((csum
& 0xff) == (c1
<< 4) + c2
)
1227 printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
1228 (c1
<< 4) + c2
, csum
& 0xff);
1229 puts_filtered (buf
);
1230 puts_filtered ("\n");
1232 /* Try the whole thing again. */
1234 if (++retries
< MAX_RETRIES
)
1236 SERIAL_WRITE (remote_desc
, "-", 1);
1240 printf_unfiltered ("Ignoring packet error, continuing...\n");
1245 /* Deal with run-length encoding. */
1248 char *dest
= retbuf
;
1254 if (src
[1] == '\0' || src
[2] == '\0')
1257 puts_filtered ("Packet too short, retrying\n");
1260 repeat
= (fromhex (src
[1]) << 4) + fromhex (src
[2]);
1261 for (i
= 0; i
< repeat
; ++i
)
1271 } while (*src
++ != '\0');
1275 SERIAL_WRITE (remote_desc
, "+", 1);
1278 fprintf_unfiltered (gdb_stderr
,"Packet received: %s\n", buf
);
1285 /* Don't wait for it to die. I'm not really sure it matters whether
1286 we do or not. For the existing stubs, kill is a noop. */
1287 target_mourn_inferior ();
1293 unpush_target (&remote_ops
);
1294 generic_mourn_inferior ();
1297 #ifdef REMOTE_BREAKPOINT
1299 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
1300 than other targets. */
1301 static unsigned char break_insn
[] = REMOTE_BREAKPOINT
;
1303 /* Check that it fits in BREAKPOINT_MAX bytes. */
1304 static unsigned char check_break_insn_size
[BREAKPOINT_MAX
] = REMOTE_BREAKPOINT
;
1306 #else /* No REMOTE_BREAKPOINT. */
1308 /* Same old breakpoint instruction. This code does nothing different
1309 than mem-break.c. */
1310 static unsigned char break_insn
[] = BREAKPOINT
;
1312 #endif /* No REMOTE_BREAKPOINT. */
1314 /* Insert a breakpoint on targets that don't have any better breakpoint
1315 support. We read the contents of the target location and stash it,
1316 then overwrite it with a breakpoint instruction. ADDR is the target
1317 location in the target machine. CONTENTS_CACHE is a pointer to
1318 memory allocated for saving the target contents. It is guaranteed
1319 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
1320 is accomplished via BREAKPOINT_MAX). */
1323 remote_insert_breakpoint (addr
, contents_cache
)
1325 char *contents_cache
;
1329 val
= target_read_memory (addr
, contents_cache
, sizeof break_insn
);
1332 val
= target_write_memory (addr
, (char *)break_insn
, sizeof break_insn
);
1338 remote_remove_breakpoint (addr
, contents_cache
)
1340 char *contents_cache
;
1342 return target_write_memory (addr
, contents_cache
, sizeof break_insn
);
1345 /* Define the target subroutine names */
1347 struct target_ops remote_ops
= {
1348 "remote", /* to_shortname */
1349 "Remote serial target in gdb-specific protocol", /* to_longname */
1350 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
1351 Specify the serial device it is connected to (e.g. /dev/ttya).", /* to_doc */
1352 remote_open
, /* to_open */
1353 remote_close
, /* to_close */
1354 NULL
, /* to_attach */
1355 remote_detach
, /* to_detach */
1356 remote_resume
, /* to_resume */
1357 remote_wait
, /* to_wait */
1358 remote_fetch_registers
, /* to_fetch_registers */
1359 remote_store_registers
, /* to_store_registers */
1360 remote_prepare_to_store
, /* to_prepare_to_store */
1361 remote_xfer_memory
, /* to_xfer_memory */
1362 remote_files_info
, /* to_files_info */
1364 remote_insert_breakpoint
, /* to_insert_breakpoint */
1365 remote_remove_breakpoint
, /* to_remove_breakpoint */
1367 NULL
, /* to_terminal_init */
1368 NULL
, /* to_terminal_inferior */
1369 NULL
, /* to_terminal_ours_for_output */
1370 NULL
, /* to_terminal_ours */
1371 NULL
, /* to_terminal_info */
1372 remote_kill
, /* to_kill */
1373 generic_load
, /* to_load */
1374 NULL
, /* to_lookup_symbol */
1375 NULL
, /* to_create_inferior */
1376 remote_mourn
, /* to_mourn_inferior */
1378 0, /* to_notice_signals */
1379 process_stratum
, /* to_stratum */
1381 1, /* to_has_all_memory */
1382 1, /* to_has_memory */
1383 1, /* to_has_stack */
1384 1, /* to_has_registers */
1385 1, /* to_has_execution */
1386 NULL
, /* sections */
1387 NULL
, /* sections_end */
1388 OPS_MAGIC
/* to_magic */
1390 #endif /* Use remote. */
1393 _initialize_remote ()
1395 #if !defined(DONT_USE_REMOTE)
1396 add_target (&remote_ops
);
This page took 0.072026 seconds and 4 git commands to generate.