aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-09-06 08:33:46 -0600
committerTom Tromey <tromey@adacore.com>2023-11-27 12:55:14 -0700
commitd69939bded50d76179f97284df35879a385cf8c0 (patch)
tree965bb45900e7a4442d3ce67e551d5cafe73e8691 /gdb/remote.c
parenta2e0acea420cca881296c6fcf58920f3d7c05a45 (diff)
downloadfsf-binutils-gdb-d69939bded50d76179f97284df35879a385cf8c0.zip
fsf-binutils-gdb-d69939bded50d76179f97284df35879a385cf8c0.tar.gz
fsf-binutils-gdb-d69939bded50d76179f97284df35879a385cf8c0.tar.bz2
Change serial_send_break and serial_write to throw
This changes serial_send_break and serial_write to throw exceptions rather than attempt to set errno and return an error indicator. This lets us correctly report failures on Windows. Both functions had to be converted in a single patch because one implementation of send_break works via write. This also introduces remote_serial_send_break to handle error checking when attempting to send a break. This was previously ignored. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30770
Diffstat (limited to 'gdb/remote.c')
-rw-r--r--gdb/remote.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index 03ebcc6..49c1c96 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1264,6 +1264,7 @@ public: /* Remote specific methods. */
int readchar (int timeout);
void remote_serial_write (const char *str, int len);
+ void remote_serial_send_break ();
int putpkt (const char *buf);
int putpkt_binary (const char *buf, int cnt);
@@ -4623,15 +4624,13 @@ remote_target::get_offsets ()
void
remote_target::send_interrupt_sequence ()
{
- struct remote_state *rs = get_remote_state ();
-
if (interrupt_sequence_mode == interrupt_sequence_control_c)
remote_serial_write ("\x03", 1);
else if (interrupt_sequence_mode == interrupt_sequence_break)
- serial_send_break (rs->remote_desc);
+ remote_serial_send_break ();
else if (interrupt_sequence_mode == interrupt_sequence_break_g)
{
- serial_send_break (rs->remote_desc);
+ remote_serial_send_break ();
remote_serial_write ("g", 1);
}
else
@@ -4639,7 +4638,6 @@ remote_target::send_interrupt_sequence ()
interrupt_sequence_mode);
}
-
/* If STOP_REPLY is a T stop reply, look for the "thread" register,
and extract the PTID. Returns NULL_PTID if not found. */
@@ -9859,16 +9857,42 @@ remote_target::remote_serial_write (const char *str, int len)
rs->got_ctrlc_during_io = 0;
- if (serial_write (rs->remote_desc, str, len))
+ try
{
- unpush_and_perror (this, _("Remote communication error. "
- "Target disconnected"));
+ serial_write (rs->remote_desc, str, len);
+ }
+ catch (const gdb_exception_error &ex)
+ {
+ remote_unpush_target (this);
+ throw_error (TARGET_CLOSE_ERROR,
+ _("Remote communication error. "
+ "Target disconnected: %s"),
+ ex.what ());
}
if (rs->got_ctrlc_during_io)
set_quit_flag ();
}
+void
+remote_target::remote_serial_send_break ()
+{
+ struct remote_state *rs = get_remote_state ();
+
+ try
+ {
+ serial_send_break (rs->remote_desc);
+ }
+ catch (const gdb_exception_error &ex)
+ {
+ remote_unpush_target (this);
+ throw_error (TARGET_CLOSE_ERROR,
+ _("Remote communication error. "
+ "Target disconnected: %s"),
+ ex.what ());
+ }
+}
+
/* Return a string representing an escaped version of BUF, of len N.
E.g. \n is converted to \\n, \t to \\t, etc. */