aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-08-29 08:22:09 -0600
committerTom Tromey <tromey@adacore.com>2023-11-27 12:55:14 -0700
commit0da23004a064e7149373b484fa671f2a2105ec9b (patch)
treecd41c9b455ae17a9ab41b8b14a423efc94053204 /gdb/remote.c
parentd69939bded50d76179f97284df35879a385cf8c0 (diff)
downloadfsf-binutils-gdb-0da23004a064e7149373b484fa671f2a2105ec9b.zip
fsf-binutils-gdb-0da23004a064e7149373b484fa671f2a2105ec9b.tar.gz
fsf-binutils-gdb-0da23004a064e7149373b484fa671f2a2105ec9b.tar.bz2
Change serial_readchar to throw
This changes serial_readchar to throw an exception rather than trying to set and preserve errno. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30770
Diffstat (limited to 'gdb/remote.c')
-rw-r--r--gdb/remote.c56
1 files changed, 21 insertions, 35 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index 49c1c96..22215b5 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -9779,22 +9779,6 @@ remote_target::flash_done ()
/* Stuff for dealing with the packets which are part of this protocol.
See comment at top of file for details. */
-/* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
- error to higher layers. Called when a serial error is detected.
- The exception message is STRING, followed by a colon and a blank,
- the system error message for errno at function entry and final dot
- for output compatibility with throw_perror_with_name. */
-
-static void
-unpush_and_perror (remote_target *target, const char *string)
-{
- int saved_errno = errno;
-
- remote_unpush_target (target);
- throw_error (TARGET_CLOSE_ERROR, "%s: %s.", string,
- safe_strerror (saved_errno));
-}
-
/* Read a single character from the remote end. The current quit
handler is overridden to avoid quitting in the middle of packet
sequence, as that would break communication with the remote server.
@@ -9806,36 +9790,38 @@ remote_target::readchar (int timeout)
int ch;
struct remote_state *rs = get_remote_state ();
- {
- scoped_restore restore_quit_target
- = make_scoped_restore (&curr_quit_handler_target, this);
- scoped_restore restore_quit
- = make_scoped_restore (&quit_handler, ::remote_serial_quit_handler);
+ try
+ {
+ scoped_restore restore_quit_target
+ = make_scoped_restore (&curr_quit_handler_target, this);
+ scoped_restore restore_quit
+ = make_scoped_restore (&quit_handler, ::remote_serial_quit_handler);
- rs->got_ctrlc_during_io = 0;
+ rs->got_ctrlc_during_io = 0;
- ch = serial_readchar (rs->remote_desc, timeout);
+ ch = serial_readchar (rs->remote_desc, timeout);
- if (rs->got_ctrlc_during_io)
- set_quit_flag ();
- }
+ if (rs->got_ctrlc_during_io)
+ set_quit_flag ();
+ }
+ catch (const gdb_exception_error &ex)
+ {
+ remote_unpush_target (this);
+ throw_error (TARGET_CLOSE_ERROR,
+ _("Remote communication error. "
+ "Target disconnected: %s"),
+ ex.what ());
+ }
if (ch >= 0)
return ch;
- switch ((enum serial_rc) ch)
+ if (ch == SERIAL_EOF)
{
- case SERIAL_EOF:
remote_unpush_target (this);
throw_error (TARGET_CLOSE_ERROR, _("Remote connection closed"));
- /* no return */
- case SERIAL_ERROR:
- unpush_and_perror (this, _("Remote communication error. "
- "Target disconnected"));
- /* no return */
- case SERIAL_TIMEOUT:
- break;
}
+
return ch;
}