290e73fceb9a71d90055e37d6f210d7e34ab974a
1 /* Generic support for remote debugging interfaces.
3 Copyright 1993 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file actually contains two distinct logical "packages". They
22 are packaged together in this one file because they are typically
25 The first package is an addition to the serial package. The
26 addition provides reading and writing with debugging output and
27 timeouts based on user settable variables. These routines are
28 intended to support serial port based remote backends. These
29 functions are prefixed with sr_.
31 The second package is a collection of more or less generic
32 functions for use by remote backends. They support user settable
33 variables for debugging, retries, and the like.
37 * a pass through mode a la kermit or telnet.
39 * ask remote to change his baud rate.
40 * put generic load here.
50 #include "gdbcore.h" /* for exec_bfd */
51 #include "inferior.h" /* for generic_mourn_inferior */
52 #include "remote-utils.h"
54 struct _sr_settings sr_settings
= {
59 remote-bug.c had "with a timeout of 2, we time out waiting for
60 the prompt after an s-record dump."
62 remote.c had (2): This was 5 seconds, which is a long time to
63 sit and wait. Unless this is going though some terminal server
64 or multiplexer or other form of hairy serial connection, I
65 would think 2 seconds would be plenty.
70 NULL
, /* descriptor */
73 struct gr_settings
*gr_settings
= NULL
;
81 fprintf(stderr
, "Unrecognized arguments: `%s'.\n", junk
);
83 /* FIXME-now: service@host? */
85 error("Usage: target %s <device <speed <debug>>>\n\
86 or target %s <host> <port>\n", proto
, proto
);
91 #define CHECKDONE(p, q) \
103 sr_scan_args(proto
, args
)
112 /* if no args, then nothing to do. */
113 if (args
== NULL
|| *args
== '\0')
116 /* scan off white space. */
117 for (p
= args
; isspace(*p
); ++p
) ;;
119 /* find end of device name. */
120 for (q
= p
; *q
!= '\0' && !isspace(*q
); ++q
) ;;
122 /* check for missing or empty device name. */
124 sr_set_device(savestring(p
, q
- p
));
126 /* look for baud rate. */
127 n
= strtol(q
, &p
, 10);
129 /* check for missing or empty baud rate. */
133 /* look for debug value. */
134 n
= strtol(p
, &q
, 10);
136 /* check for missing or empty debug value. */
140 /* scan off remaining white space. */
141 for (p
= q
; isspace(*p
); ++p
) ;;
143 /* if not end of string, then there's unrecognized junk. */
158 gr_open(args
, from_tty
, gr
)
161 struct gr_settings
*gr
;
163 target_preopen(from_tty
);
164 sr_scan_args(gr
->ops
->to_shortname
, args
);
165 unpush_target(gr
->ops
);
169 gr_set_dcache(dcache_init(gr
->readfunc
, gr
->writefunc
));
171 if (sr_get_desc() != NULL
)
174 sr_set_desc(SERIAL_OPEN (sr_get_device()));
176 perror_with_name((char *) sr_get_device());
178 if (SERIAL_SETBAUDRATE(sr_get_desc(), sr_get_baud_rate()) != 0)
180 SERIAL_CLOSE(sr_get_desc());
181 perror_with_name(sr_get_device());
184 SERIAL_RAW (sr_get_desc());
186 /* default retries */
187 if (sr_get_retries() == 0)
190 /* default clear breakpoint function */
191 if (gr_settings
->clear_all_breakpoints
== NULL
)
192 gr_settings
->clear_all_breakpoints
= remove_breakpoints
;
195 printf_filtered ("Remote debugging using `%s' at baud rate of %d\n",
196 sr_get_device(), sr_get_baud_rate());
198 push_target(gr
->ops
);
200 gr_clear_all_breakpoints ();
204 /* Read a character from the remote system masking it down to 7 bits
205 and doing all the fancy timeout stuff. */
212 buf
= SERIAL_READCHAR (sr_get_desc(), sr_get_timeout());
214 if (buf
== SERIAL_TIMEOUT
)
215 error ("Timeout reading from remote system.");
217 if (sr_get_debug() > 0)
228 buf
= SERIAL_READCHAR (sr_get_desc(), 0);
229 if (buf
== SERIAL_TIMEOUT
)
231 if (sr_get_debug() > 0)
235 printf ("<empty character poll>");
240 /* Keep discarding input from the remote system, until STRING is found.
241 Let the user break out immediately. */
251 if (sr_readchar () == *p
)
272 if (SERIAL_WRITE (sr_get_desc(), a
, l
) != 0)
273 perror_with_name ("sr_write: Error writing to remote");
275 if (sr_get_debug() > 0)
276 for (i
= 0; i
< l
; i
++)
286 sr_write (s
, strlen (s
));
292 sr_timed_read (buf
, n
)
313 /* Get a hex digit from the remote system & return its value. If
314 ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
317 sr_get_hex_digit (ignore_space
)
325 if (ch
>= '0' && ch
<= '9')
327 else if (ch
>= 'A' && ch
<= 'F')
328 return ch
- 'A' + 10;
329 else if (ch
>= 'a' && ch
<= 'f')
330 return ch
- 'a' + 10;
331 else if (ch
!= ' ' || !ignore_space
)
334 error ("Invalid hex digit from remote system.");
339 /* Get a byte from the remote and put it in *BYT. Accept any number
342 sr_get_hex_byte (byt
)
347 val
= sr_get_hex_digit (1) << 4;
348 val
|= sr_get_hex_digit (0);
352 /* Read a 32-bit hex word from the remote, preceded by a space */
360 for (j
= 0; j
< 8; j
++)
361 val
= (val
<< 4) + sr_get_hex_digit (j
== 0);
365 /* Put a command string, in args, out to the remote. The remote is assumed to
366 be in raw mode, all writing/reading done through desc.
367 Ouput from the remote is placed on the users terminal until the
368 prompt from the remote is seen.
369 FIXME: Can't handle commands that take input. */
372 sr_com (args
, fromtty
)
381 /* Clear all input so only command relative output is displayed */
384 sr_write ("\030", 1);
392 gr_clear_all_breakpoints();
396 SERIAL_CLOSE (sr_get_desc());
404 takes a program previously attached to and detaches it.
405 We better not have left any breakpoints
406 in the program or it'll die when it hits one.
407 Close the open connection to the remote debugger.
408 Use this when you want to detach and do something else
412 gr_detach(args
, from_tty
)
417 error ("Argument given to \"detach\" when remotely debugging.");
420 gr_clear_all_breakpoints ();
424 puts_filtered ("Ending remote debugging.\n");
431 struct target_ops
*ops
;
433 char *file
= "nothing";
436 file
= bfd_get_filename (exec_bfd
);
441 printf_filtered ("\tAttached to DOS asynctsr\n");
443 printf_filtered ("\tAttached to %s at %d baud\n",
444 sr_get_device(), sr_get_baud_rate());
448 printf_filtered ("\tand running program %s\n", file
);
449 printf_filtered ("\tusing the %s protocol.\n", ops
->to_shortname
);
455 gr_clear_all_breakpoints ();
456 unpush_target (gr_get_ops());
457 generic_mourn_inferior ();
466 /* This is called not only when we first attach, but also when the
467 user types "run" after having attached. */
469 gr_create_inferior (execfile
, args
, env
)
477 error ("Can't pass arguments to remote process.");
479 if (execfile
== 0 || exec_bfd
== 0)
480 error ("No exec file specified");
482 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
486 gr_clear_all_breakpoints ();
488 init_wait_for_inferior ();
491 insert_breakpoints (); /* Needed to get correct instruction in cache */
492 proceed (entry_pt
, -1, 0);
495 /* Given a null terminated list of strings LIST, read the input until we find one of
496 them. Return the index of the string found or -1 on error. '?' means match
497 any single character. Note that with the algorithm we use, the initial
498 character of the string cannot recur in the string, or we will not find some
499 cases of the string in the input. If PASSTHROUGH is non-zero, then
500 pass non-matching data on. */
503 gr_multi_scan (list
, passthrough
)
507 char *swallowed
= NULL
; /* holding area */
508 char *swallowed_p
= swallowed
; /* Current position in swallowed. */
516 /* Look through the strings. Count them. Find the largest one so we can
517 allocate a holding area. */
519 for (max_length
= string_count
= i
= 0;
523 int length
= strlen(list
[i
]);
525 if (length
> max_length
)
529 /* if we have no strings, then something is wrong. */
530 if (string_count
== 0)
533 /* otherwise, we will need a holding area big enough to hold almost two
534 copies of our largest string. */
535 swallowed_p
= swallowed
= alloca(max_length
<< 1);
537 /* and a list of pointers to current scan points. */
538 plist
= (char **) alloca (string_count
* sizeof(*plist
));
541 for (i
= 0; i
< string_count
; ++i
)
544 for (ch
= sr_readchar(); /* loop forever */ ; ch
= sr_readchar())
546 QUIT
; /* Let user quit and leave process running */
549 for (i
= 0; i
< string_count
; ++i
)
551 if (ch
== *plist
[i
] || *plist
[i
] == '?')
554 if (*plist
[i
] == '\0')
570 /* Print out any characters which have been swallowed. */
573 for (p
= swallowed
; p
< swallowed_p
; ++p
)
579 swallowed_p
= swallowed
;
588 /* Get ready to modify the registers array. On machines which store
589 individual registers, this doesn't need to do anything. On machines
590 which store all the registers in one fell swoop, this makes sure
591 that registers contains all the registers from the program being
595 gr_prepare_to_store ()
597 /* Do nothing, since we assume we can store individual regs */
600 /* Read a word from remote address ADDR and return it.
601 * This goes through the data cache.
607 return dcache_fetch (gr_get_dcache(), addr
);
610 /* Write a word WORD into remote address ADDR.
611 This goes through the data cache. */
614 gr_store_word (addr
, word
)
618 dcache_poke (gr_get_dcache(), addr
, word
);
622 _initialize_sr_support ()
624 add_show_from_set (add_set_cmd ("remotedebug", no_class
,
625 var_zinteger
, (char *)&sr_settings
.debug
,
626 "Set debugging of remote serial I/O.\n\
627 When non-zero, each packet sent or received with the remote target\n\
628 is displayed. Higher numbers produce more debugging.", &setlist
),
631 /* FIXME-now: if target is open when baud changes... */
632 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
633 var_zinteger
, (char *)&sr_settings
.baud_rate
,
634 "Set baud rate for remote serial I/O.\n\
635 This value is used to set the speed of the serial port when debugging\n\
636 using remote targets.", &setlist
),
639 /* FIXME-now: if target is open... */
640 add_show_from_set (add_set_cmd ("remotedevice", no_class
,
641 var_filename
, (char *)&sr_settings
.device
,
642 "Set device for remote serial I/O.\n\
643 This device is used as the serial port when debugging using remote\n\
644 targets.", &setlist
),
647 add_com ("remote <command>", class_obscure
, sr_com
,
648 "Send a command to the remote monitor.");
This page took 0.042828 seconds and 4 git commands to generate.