aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-04-26 22:53:40 -0600
committerTom Tromey <tom@tromey.com>2017-08-03 07:59:00 -0600
commit2ec845e758762030f2333c21fa532fc57fe3762f (patch)
tree9732e9de0eb998580859fcc3d2a33285b454d561 /gdb/remote.c
parentb3bc84537bc6de78e2bbd550ce9c57dd4b7e2ec6 (diff)
downloadgdb-2ec845e758762030f2333c21fa532fc57fe3762f.zip
gdb-2ec845e758762030f2333c21fa532fc57fe3762f.tar.gz
gdb-2ec845e758762030f2333c21fa532fc57fe3762f.tar.bz2
More uses of scoped_restore
There were a few more places in gdb that could easily use scoped_restore, replacing some cleanups. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * reverse.c (exec_direction_default): Remove. (exec_reverse_once): Use scoped_restore. * remote.c (restore_remote_timeout): Remove. (remote_flash_erase, remote_flash_write, remote_flash_done) (readchar, remote_serial_write): Use scoped_restore. * cli/cli-script.c (struct source_cleanup_lines_args) (source_cleanup_lines): Remove. (script_from_file): Use scoped_restore. * cli/cli-cmds.c (source_verbose_cleanup): Remove. (source_command): Use scoped_restore.
Diffstat (limited to 'gdb/remote.c')
-rw-r--r--gdb/remote.c63
1 files changed, 20 insertions, 43 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index c381743..5adf5eb 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -72,6 +72,7 @@
#include "btrace.h"
#include "record-btrace.h"
#include <algorithm>
+#include "common/scoped_restore.h"
/* Temp hacks for tracepoint encoding migration. */
static char *target_buf;
@@ -8469,14 +8470,6 @@ remote_send_printf (const char *format, ...)
return packet_check_result (rs->buf);
}
-static void
-restore_remote_timeout (void *p)
-{
- int value = *(int *)p;
-
- remote_timeout = value;
-}
-
/* Flash writing can take quite some time. We'll set
effectively infinite timeout for flash operations.
In future, we'll need to decide on a better approach. */
@@ -8487,12 +8480,9 @@ remote_flash_erase (struct target_ops *ops,
ULONGEST address, LONGEST length)
{
int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
- int saved_remote_timeout = remote_timeout;
enum packet_result ret;
- struct cleanup *back_to = make_cleanup (restore_remote_timeout,
- &saved_remote_timeout);
-
- remote_timeout = remote_flash_timeout;
+ scoped_restore restore_timeout
+ = make_scoped_restore (&remote_timeout, remote_flash_timeout);
ret = remote_send_printf ("vFlashErase:%s,%s",
phex (address, addr_size),
@@ -8506,8 +8496,6 @@ remote_flash_erase (struct target_ops *ops,
default:
break;
}
-
- do_cleanups (back_to);
}
static enum target_xfer_status
@@ -8515,30 +8503,21 @@ remote_flash_write (struct target_ops *ops, ULONGEST address,
ULONGEST length, ULONGEST *xfered_len,
const gdb_byte *data)
{
- int saved_remote_timeout = remote_timeout;
- enum target_xfer_status ret;
- struct cleanup *back_to = make_cleanup (restore_remote_timeout,
- &saved_remote_timeout);
-
- remote_timeout = remote_flash_timeout;
- ret = remote_write_bytes_aux ("vFlashWrite:", address, data, length, 1,
- xfered_len,'X', 0);
- do_cleanups (back_to);
-
- return ret;
+ scoped_restore restore_timeout
+ = make_scoped_restore (&remote_timeout, remote_flash_timeout);
+ return remote_write_bytes_aux ("vFlashWrite:", address, data, length, 1,
+ xfered_len,'X', 0);
}
static void
remote_flash_done (struct target_ops *ops)
{
- int saved_remote_timeout = remote_timeout;
int ret;
- struct cleanup *back_to = make_cleanup (restore_remote_timeout,
- &saved_remote_timeout);
- remote_timeout = remote_flash_timeout;
+ scoped_restore restore_timeout
+ = make_scoped_restore (&remote_timeout, remote_flash_timeout);
+
ret = remote_send_printf ("vFlashDone");
- do_cleanups (back_to);
switch (ret)
{
@@ -8586,18 +8565,18 @@ readchar (int timeout)
{
int ch;
struct remote_state *rs = get_remote_state ();
- struct cleanup *old_chain;
-
- old_chain = make_cleanup_override_quit_handler (remote_serial_quit_handler);
- rs->got_ctrlc_during_io = 0;
+ {
+ scoped_restore restore_quit
+ = make_scoped_restore (&quit_handler, remote_serial_quit_handler);
- ch = serial_readchar (rs->remote_desc, timeout);
+ rs->got_ctrlc_during_io = 0;
- if (rs->got_ctrlc_during_io)
- set_quit_flag ();
+ ch = serial_readchar (rs->remote_desc, timeout);
- do_cleanups (old_chain);
+ if (rs->got_ctrlc_during_io)
+ set_quit_flag ();
+ }
if (ch >= 0)
return ch;
@@ -8628,9 +8607,9 @@ static void
remote_serial_write (const char *str, int len)
{
struct remote_state *rs = get_remote_state ();
- struct cleanup *old_chain;
- old_chain = make_cleanup_override_quit_handler (remote_serial_quit_handler);
+ scoped_restore restore_quit
+ = make_scoped_restore (&quit_handler, remote_serial_quit_handler);
rs->got_ctrlc_during_io = 0;
@@ -8642,8 +8621,6 @@ remote_serial_write (const char *str, int len)
if (rs->got_ctrlc_during_io)
set_quit_flag ();
-
- do_cleanups (old_chain);
}
/* Send the command in *BUF to the remote machine, and read the reply