e723a5612e1f117c72fc3f02750d6f3dd2b9c816
1 /* Generic support for remote debugging interfaces.
3 Copyright 1993, 1994, 1998 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* This file actually contains two distinct logical "packages". They
23 are packaged together in this one file because they are typically
26 The first package is an addition to the serial package. The
27 addition provides reading and writing with debugging output and
28 timeouts based on user settable variables. These routines are
29 intended to support serial port based remote backends. These
30 functions are prefixed with sr_.
32 The second package is a collection of more or less generic
33 functions for use by remote backends. They support user settable
34 variables for debugging, retries, and the like.
38 * a pass through mode a la kermit or telnet.
40 * ask remote to change his baud rate.
46 #include "gdb_string.h"
50 #include "gdbcore.h" /* for exec_bfd */
51 #include "inferior.h" /* for generic_mourn_inferior */
52 #include "remote-utils.h"
55 void _initialize_sr_support (void);
57 struct _sr_settings sr_settings
=
61 remote-bug.c had "with a timeout of 2, we time out waiting for
62 the prompt after an s-record dump."
64 remote.c had (2): This was 5 seconds, which is a long time to
65 sit and wait. Unless this is going though some terminal server
66 or multiplexer or other form of hairy serial connection, I
67 would think 2 seconds would be plenty.
72 NULL
, /* descriptor */
75 struct gr_settings
*gr_settings
= NULL
;
77 static void usage (char *, char *);
78 static void sr_com (char *, int);
81 usage (char *proto
, char *junk
)
84 fprintf_unfiltered (gdb_stderr
, "Unrecognized arguments: `%s'.\n", junk
);
86 error ("Usage: target %s [DEVICE [SPEED [DEBUG]]]\n\
87 where DEVICE is the name of a device or HOST:PORT", proto
, proto
);
92 #define CHECKDONE(p, q) \
104 sr_scan_args (char *proto
, char *args
)
109 /* if no args, then nothing to do. */
110 if (args
== NULL
|| *args
== '\0')
113 /* scan off white space. */
114 for (p
= args
; isspace (*p
); ++p
);;
116 /* find end of device name. */
117 for (q
= p
; *q
!= '\0' && !isspace (*q
); ++q
);;
119 /* check for missing or empty device name. */
121 sr_set_device (savestring (p
, q
- p
));
123 /* look for baud rate. */
124 n
= strtol (q
, &p
, 10);
126 /* check for missing or empty baud rate. */
130 /* look for debug value. */
131 n
= strtol (p
, &q
, 10);
133 /* check for missing or empty debug value. */
137 /* scan off remaining white space. */
138 for (p
= q
; isspace (*p
); ++p
);;
140 /* if not end of string, then there's unrecognized junk. */
148 gr_generic_checkin (void)
155 gr_open (char *args
, int from_tty
, struct gr_settings
*gr
)
157 target_preopen (from_tty
);
158 sr_scan_args (gr
->ops
->to_shortname
, args
);
159 unpush_target (gr
->ops
);
163 if (sr_get_desc () != NULL
)
166 /* If no args are specified, then we use the device specified by a
167 previous command or "set remotedevice". But if there is no
168 device, better stop now, not dump core. */
170 if (sr_get_device () == NULL
)
171 usage (gr
->ops
->to_shortname
, NULL
);
173 sr_set_desc (SERIAL_OPEN (sr_get_device ()));
175 perror_with_name ((char *) sr_get_device ());
179 if (SERIAL_SETBAUDRATE (sr_get_desc (), baud_rate
) != 0)
181 SERIAL_CLOSE (sr_get_desc ());
182 perror_with_name (sr_get_device ());
186 SERIAL_RAW (sr_get_desc ());
188 /* If there is something sitting in the buffer we might take it as a
189 response to a command, which would be bad. */
190 SERIAL_FLUSH_INPUT (sr_get_desc ());
192 /* default retries */
193 if (sr_get_retries () == 0)
196 /* default clear breakpoint function */
197 if (gr_settings
->clear_all_breakpoints
== NULL
)
198 gr_settings
->clear_all_breakpoints
= remove_breakpoints
;
202 printf_filtered ("Remote debugging using `%s'", sr_get_device ());
204 printf_filtered (" at baud rate of %d",
206 printf_filtered ("\n");
209 push_target (gr
->ops
);
211 gr_clear_all_breakpoints ();
215 /* Read a character from the remote system masking it down to 7 bits
216 and doing all the fancy timeout stuff. */
223 buf
= SERIAL_READCHAR (sr_get_desc (), sr_get_timeout ());
225 if (buf
== SERIAL_TIMEOUT
)
226 error ("Timeout reading from remote system.");
228 if (sr_get_debug () > 0)
229 printf_unfiltered ("%c", buf
);
239 buf
= SERIAL_READCHAR (sr_get_desc (), 0);
240 if (buf
== SERIAL_TIMEOUT
)
242 if (sr_get_debug () > 0)
245 printf_unfiltered ("%c", buf
);
247 printf_unfiltered ("<empty character poll>");
253 /* Keep discarding input from the remote system, until STRING is found.
254 Let the user break out immediately. */
256 sr_expect (char *string
)
263 if (sr_readchar () == *p
)
278 sr_write (char *a
, int l
)
282 if (SERIAL_WRITE (sr_get_desc (), a
, l
) != 0)
283 perror_with_name ("sr_write: Error writing to remote");
285 if (sr_get_debug () > 0)
286 for (i
= 0; i
< l
; i
++)
287 printf_unfiltered ("%c", a
[i
]);
293 sr_write_cr (char *s
)
295 sr_write (s
, strlen (s
));
301 sr_timed_read (char *buf
, int n
)
320 /* Get a hex digit from the remote system & return its value. If
321 ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
324 sr_get_hex_digit (int ignore_space
)
331 if (ch
>= '0' && ch
<= '9')
333 else if (ch
>= 'A' && ch
<= 'F')
334 return ch
- 'A' + 10;
335 else if (ch
>= 'a' && ch
<= 'f')
336 return ch
- 'a' + 10;
337 else if (ch
!= ' ' || !ignore_space
)
340 error ("Invalid hex digit from remote system.");
345 /* Get a byte from the remote and put it in *BYT. Accept any number
348 sr_get_hex_byte (char *byt
)
352 val
= sr_get_hex_digit (1) << 4;
353 val
|= sr_get_hex_digit (0);
357 /* Read a 32-bit hex word from the remote, preceded by a space */
359 sr_get_hex_word (void)
365 for (j
= 0; j
< 8; j
++)
366 val
= (val
<< 4) + sr_get_hex_digit (j
== 0);
370 /* Put a command string, in args, out to the remote. The remote is assumed to
371 be in raw mode, all writing/reading done through desc.
372 Ouput from the remote is placed on the users terminal until the
373 prompt from the remote is seen.
374 FIXME: Can't handle commands that take input. */
377 sr_com (char *args
, int fromtty
)
384 /* Clear all input so only command relative output is displayed */
387 sr_write ("\030", 1);
388 registers_changed ();
393 gr_close (int quitting
)
395 gr_clear_all_breakpoints ();
399 SERIAL_CLOSE (sr_get_desc ());
407 takes a program previously attached to and detaches it.
408 We better not have left any breakpoints
409 in the program or it'll die when it hits one.
410 Close the open connection to the remote debugger.
411 Use this when you want to detach and do something else
415 gr_detach (char *args
, int from_tty
)
418 error ("Argument given to \"detach\" when remotely debugging.");
421 gr_clear_all_breakpoints ();
425 puts_filtered ("Ending remote debugging.\n");
431 gr_files_info (struct target_ops
*ops
)
434 printf_filtered ("\tAttached to DOS asynctsr\n");
436 printf_filtered ("\tAttached to %s", sr_get_device ());
438 printf_filtered ("at %d baud", baud_rate
);
439 printf_filtered ("\n");
444 printf_filtered ("\tand running program %s\n",
445 bfd_get_filename (exec_bfd
));
447 printf_filtered ("\tusing the %s protocol.\n", ops
->to_shortname
);
453 gr_clear_all_breakpoints ();
454 unpush_target (gr_get_ops ());
455 generic_mourn_inferior ();
464 /* This is called not only when we first attach, but also when the
465 user types "run" after having attached. */
467 gr_create_inferior (char *execfile
, char *args
, char **env
)
472 error ("Can't pass arguments to remote process.");
474 if (execfile
== 0 || exec_bfd
== 0)
475 error ("No executable file specified");
477 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
481 gr_clear_all_breakpoints ();
483 init_wait_for_inferior ();
486 insert_breakpoints (); /* Needed to get correct instruction in cache */
487 proceed (entry_pt
, -1, 0);
490 /* Given a null terminated list of strings LIST, read the input until we find one of
491 them. Return the index of the string found or -1 on error. '?' means match
492 any single character. Note that with the algorithm we use, the initial
493 character of the string cannot recur in the string, or we will not find some
494 cases of the string in the input. If PASSTHROUGH is non-zero, then
495 pass non-matching data on. */
498 gr_multi_scan (char *list
[], int passthrough
)
500 char *swallowed
= NULL
; /* holding area */
501 char *swallowed_p
= swallowed
; /* Current position in swallowed. */
509 /* Look through the strings. Count them. Find the largest one so we can
510 allocate a holding area. */
512 for (max_length
= string_count
= i
= 0;
516 int length
= strlen (list
[i
]);
518 if (length
> max_length
)
522 /* if we have no strings, then something is wrong. */
523 if (string_count
== 0)
526 /* otherwise, we will need a holding area big enough to hold almost two
527 copies of our largest string. */
528 swallowed_p
= swallowed
= alloca (max_length
<< 1);
530 /* and a list of pointers to current scan points. */
531 plist
= (char **) alloca (string_count
* sizeof (*plist
));
534 for (i
= 0; i
< string_count
; ++i
)
537 for (ch
= sr_readchar (); /* loop forever */ ; ch
= sr_readchar ())
539 QUIT
; /* Let user quit and leave process running */
542 for (i
= 0; i
< string_count
; ++i
)
544 if (ch
== *plist
[i
] || *plist
[i
] == '?')
547 if (*plist
[i
] == '\0')
563 /* Print out any characters which have been swallowed. */
566 for (p
= swallowed
; p
< swallowed_p
; ++p
)
567 fputc_unfiltered (*p
, gdb_stdout
);
569 fputc_unfiltered (ch
, gdb_stdout
);
572 swallowed_p
= swallowed
;
581 /* Get ready to modify the registers array. On machines which store
582 individual registers, this doesn't need to do anything. On machines
583 which store all the registers in one fell swoop, this makes sure
584 that registers contains all the registers from the program being
588 gr_prepare_to_store (void)
590 /* Do nothing, since we assume we can store individual regs */
594 _initialize_sr_support (void)
596 /* FIXME-now: if target is open... */
597 add_show_from_set (add_set_cmd ("remotedevice", no_class
,
598 var_filename
, (char *) &sr_settings
.device
,
599 "Set device for remote serial I/O.\n\
600 This device is used as the serial port when debugging using remote\n\
601 targets.", &setlist
),
604 add_com ("remote <command>", class_obscure
, sr_com
,
605 "Send a command to the remote monitor.");
This page took 0.041795 seconds and 4 git commands to generate.