From d69939bded50d76179f97284df35879a385cf8c0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 6 Sep 2023 08:33:46 -0600 Subject: 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 --- gdb/remote.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'gdb/remote.c') 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. */ -- cgit v1.1