aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/remote.c')
-rw-r--r--gdb/remote.c113
1 files changed, 31 insertions, 82 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index 8e8ee6f..ff59a0f 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;
@@ -7844,8 +7845,6 @@ store_registers_using_G (const struct regcache *regcache)
each byte encoded as two hex characters. */
p = rs->buf;
*p++ = 'G';
- /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
- updated. */
bin2hex (regs, p, rsa->sizeof_g_packet);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
@@ -8471,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. */
@@ -8489,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),
@@ -8508,8 +8496,6 @@ remote_flash_erase (struct target_ops *ops,
default:
break;
}
-
- do_cleanups (back_to);
}
static enum target_xfer_status
@@ -8517,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)
{
@@ -8588,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);
+ {
+ 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 ();
-
- do_cleanups (old_chain);
+ if (rs->got_ctrlc_during_io)
+ set_quit_flag ();
+ }
if (ch >= 0)
return ch;
@@ -8630,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;
@@ -8644,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
@@ -9544,12 +9519,9 @@ extended_remote_run (const std::string &args)
if (!args.empty ())
{
- struct cleanup *back_to;
int i;
- char **argv;
- argv = gdb_buildargv (args.c_str ());
- back_to = make_cleanup_freeargv (argv);
+ gdb_argv argv (args.c_str ());
for (i = 0; argv[i] != NULL; i++)
{
if (strlen (argv[i]) * 2 + 1 + len >= get_remote_packet_size ())
@@ -9558,7 +9530,6 @@ extended_remote_run (const std::string &args)
len += 2 * bin2hex ((gdb_byte *) argv[i], rs->buf + len,
strlen (argv[i]));
}
- do_cleanups (back_to);
}
rs->buf[len++] = '\0';
@@ -11904,7 +11875,6 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty)
{
struct cleanup *back_to, *close_cleanup;
int retcode, fd, remote_errno, bytes, io_size;
- FILE *file;
gdb_byte *buffer;
int bytes_in_buffer;
int saw_eof;
@@ -11914,10 +11884,9 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty)
if (!rs->remote_desc)
error (_("command can only be used with remote target"));
- file = gdb_fopen_cloexec (local_file, "rb");
+ gdb_file_up file = gdb_fopen_cloexec (local_file, "rb");
if (file == NULL)
perror_with_name (local_file);
- back_to = make_cleanup_fclose (file);
fd = remote_hostio_open (find_target_at (process_stratum), NULL,
remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT
@@ -11930,7 +11899,7 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty)
remote packet limit, so we'll transfer slightly fewer. */
io_size = get_remote_packet_size ();
buffer = (gdb_byte *) xmalloc (io_size);
- make_cleanup (xfree, buffer);
+ back_to = make_cleanup (xfree, buffer);
close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd);
@@ -11943,10 +11912,10 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty)
{
bytes = fread (buffer + bytes_in_buffer, 1,
io_size - bytes_in_buffer,
- file);
+ file.get ());
if (bytes == 0)
{
- if (ferror (file))
+ if (ferror (file.get ()))
error (_("Error reading %s."), local_file);
else
{
@@ -11997,7 +11966,6 @@ remote_file_get (const char *remote_file, const char *local_file, int from_tty)
{
struct cleanup *back_to, *close_cleanup;
int fd, remote_errno, bytes, io_size;
- FILE *file;
gdb_byte *buffer;
ULONGEST offset;
struct remote_state *rs = get_remote_state ();
@@ -12011,16 +11979,15 @@ remote_file_get (const char *remote_file, const char *local_file, int from_tty)
if (fd == -1)
remote_hostio_error (remote_errno);
- file = gdb_fopen_cloexec (local_file, "wb");
+ gdb_file_up file = gdb_fopen_cloexec (local_file, "wb");
if (file == NULL)
perror_with_name (local_file);
- back_to = make_cleanup_fclose (file);
/* Send up to this many bytes at once. They won't all fit in the
remote packet limit, so we'll transfer slightly fewer. */
io_size = get_remote_packet_size ();
buffer = (gdb_byte *) xmalloc (io_size);
- make_cleanup (xfree, buffer);
+ back_to = make_cleanup (xfree, buffer);
close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd);
@@ -12037,7 +12004,7 @@ remote_file_get (const char *remote_file, const char *local_file, int from_tty)
offset += bytes;
- bytes = fwrite (buffer, 1, bytes, file);
+ bytes = fwrite (buffer, 1, bytes, file.get ());
if (bytes == 0)
perror_with_name (local_file);
}
@@ -12072,58 +12039,40 @@ remote_file_delete (const char *remote_file, int from_tty)
static void
remote_put_command (char *args, int from_tty)
{
- struct cleanup *back_to;
- char **argv;
-
if (args == NULL)
error_no_arg (_("file to put"));
- argv = gdb_buildargv (args);
- back_to = make_cleanup_freeargv (argv);
+ gdb_argv argv (args);
if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
error (_("Invalid parameters to remote put"));
remote_file_put (argv[0], argv[1], from_tty);
-
- do_cleanups (back_to);
}
static void
remote_get_command (char *args, int from_tty)
{
- struct cleanup *back_to;
- char **argv;
-
if (args == NULL)
error_no_arg (_("file to get"));
- argv = gdb_buildargv (args);
- back_to = make_cleanup_freeargv (argv);
+ gdb_argv argv (args);
if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
error (_("Invalid parameters to remote get"));
remote_file_get (argv[0], argv[1], from_tty);
-
- do_cleanups (back_to);
}
static void
remote_delete_command (char *args, int from_tty)
{
- struct cleanup *back_to;
- char **argv;
-
if (args == NULL)
error_no_arg (_("file to delete"));
- argv = gdb_buildargv (args);
- back_to = make_cleanup_freeargv (argv);
+ gdb_argv argv (args);
if (argv[0] == NULL || argv[1] != NULL)
error (_("Invalid parameters to remote delete"));
remote_file_delete (argv[0], from_tty);
-
- do_cleanups (back_to);
}
static void