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.
This commit is contained in:
parent
b3bc84537b
commit
2ec845e758
5 changed files with 56 additions and 115 deletions
|
@ -1,3 +1,16 @@
|
||||||
|
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.
|
||||||
|
|
||||||
2017-08-03 Tom Tromey <tom@tromey.com>
|
2017-08-03 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* utils.h (make_cleanup_free_so): Remove.
|
* utils.h (make_cleanup_free_so): Remove.
|
||||||
|
|
|
@ -645,26 +645,14 @@ source_script (const char *file, int from_tty)
|
||||||
source_script_with_search (file, from_tty, 0);
|
source_script_with_search (file, from_tty, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the source_verbose global variable to its previous state
|
|
||||||
on exit from the source command, by whatever means. */
|
|
||||||
static void
|
|
||||||
source_verbose_cleanup (void *old_value)
|
|
||||||
{
|
|
||||||
source_verbose = *(int *)old_value;
|
|
||||||
xfree (old_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
source_command (char *args, int from_tty)
|
source_command (char *args, int from_tty)
|
||||||
{
|
{
|
||||||
struct cleanup *old_cleanups;
|
|
||||||
char *file = args;
|
char *file = args;
|
||||||
int *old_source_verbose = XNEW (int);
|
int *old_source_verbose = XNEW (int);
|
||||||
int search_path = 0;
|
int search_path = 0;
|
||||||
|
|
||||||
*old_source_verbose = source_verbose;
|
scoped_restore save_source_verbose = make_scoped_restore (&source_verbose);
|
||||||
old_cleanups = make_cleanup (source_verbose_cleanup,
|
|
||||||
old_source_verbose);
|
|
||||||
|
|
||||||
/* -v causes the source command to run in verbose mode.
|
/* -v causes the source command to run in verbose mode.
|
||||||
-s causes the file to be searched in the source search path,
|
-s causes the file to be searched in the source search path,
|
||||||
|
@ -705,8 +693,6 @@ source_command (char *args, int from_tty)
|
||||||
}
|
}
|
||||||
|
|
||||||
source_script_with_search (file, from_tty, search_path);
|
source_script_with_search (file, from_tty, search_path);
|
||||||
|
|
||||||
do_cleanups (old_cleanups);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1585,58 +1585,34 @@ document_command (char *comname, int from_tty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct source_cleanup_lines_args
|
|
||||||
{
|
|
||||||
int old_line;
|
|
||||||
const char *old_file;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
source_cleanup_lines (void *args)
|
|
||||||
{
|
|
||||||
struct source_cleanup_lines_args *p =
|
|
||||||
(struct source_cleanup_lines_args *) args;
|
|
||||||
|
|
||||||
source_line_number = p->old_line;
|
|
||||||
source_file_name = p->old_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Used to implement source_command. */
|
/* Used to implement source_command. */
|
||||||
|
|
||||||
void
|
void
|
||||||
script_from_file (FILE *stream, const char *file)
|
script_from_file (FILE *stream, const char *file)
|
||||||
{
|
{
|
||||||
struct cleanup *old_cleanups;
|
|
||||||
struct source_cleanup_lines_args old_lines;
|
|
||||||
|
|
||||||
if (stream == NULL)
|
if (stream == NULL)
|
||||||
internal_error (__FILE__, __LINE__, _("called with NULL file pointer!"));
|
internal_error (__FILE__, __LINE__, _("called with NULL file pointer!"));
|
||||||
|
|
||||||
old_lines.old_line = source_line_number;
|
scoped_restore restore_line_number
|
||||||
old_lines.old_file = source_file_name;
|
= make_scoped_restore (&source_line_number, 0);
|
||||||
old_cleanups = make_cleanup (source_cleanup_lines, &old_lines);
|
scoped_restore resotre_file
|
||||||
source_line_number = 0;
|
= make_scoped_restore (&source_file_name, file);
|
||||||
source_file_name = file;
|
|
||||||
|
|
||||||
{
|
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
|
||||||
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
|
|
||||||
|
|
||||||
TRY
|
TRY
|
||||||
{
|
{
|
||||||
read_command_file (stream);
|
read_command_file (stream);
|
||||||
}
|
}
|
||||||
CATCH (e, RETURN_MASK_ERROR)
|
CATCH (e, RETURN_MASK_ERROR)
|
||||||
{
|
{
|
||||||
/* Re-throw the error, but with the file name information
|
/* Re-throw the error, but with the file name information
|
||||||
prepended. */
|
prepended. */
|
||||||
throw_error (e.error,
|
throw_error (e.error,
|
||||||
_("%s:%d: Error in sourced command file:\n%s"),
|
_("%s:%d: Error in sourced command file:\n%s"),
|
||||||
source_file_name, source_line_number, e.message);
|
source_file_name, source_line_number, e.message);
|
||||||
}
|
}
|
||||||
END_CATCH
|
END_CATCH
|
||||||
}
|
|
||||||
|
|
||||||
do_cleanups (old_cleanups);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print the definition of user command C to STREAM. Or, if C is a
|
/* Print the definition of user command C to STREAM. Or, if C is a
|
||||||
|
|
63
gdb/remote.c
63
gdb/remote.c
|
@ -72,6 +72,7 @@
|
||||||
#include "btrace.h"
|
#include "btrace.h"
|
||||||
#include "record-btrace.h"
|
#include "record-btrace.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include "common/scoped_restore.h"
|
||||||
|
|
||||||
/* Temp hacks for tracepoint encoding migration. */
|
/* Temp hacks for tracepoint encoding migration. */
|
||||||
static char *target_buf;
|
static char *target_buf;
|
||||||
|
@ -8469,14 +8470,6 @@ remote_send_printf (const char *format, ...)
|
||||||
return packet_check_result (rs->buf);
|
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
|
/* Flash writing can take quite some time. We'll set
|
||||||
effectively infinite timeout for flash operations.
|
effectively infinite timeout for flash operations.
|
||||||
In future, we'll need to decide on a better approach. */
|
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)
|
ULONGEST address, LONGEST length)
|
||||||
{
|
{
|
||||||
int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
|
int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
|
||||||
int saved_remote_timeout = remote_timeout;
|
|
||||||
enum packet_result ret;
|
enum packet_result ret;
|
||||||
struct cleanup *back_to = make_cleanup (restore_remote_timeout,
|
scoped_restore restore_timeout
|
||||||
&saved_remote_timeout);
|
= make_scoped_restore (&remote_timeout, remote_flash_timeout);
|
||||||
|
|
||||||
remote_timeout = remote_flash_timeout;
|
|
||||||
|
|
||||||
ret = remote_send_printf ("vFlashErase:%s,%s",
|
ret = remote_send_printf ("vFlashErase:%s,%s",
|
||||||
phex (address, addr_size),
|
phex (address, addr_size),
|
||||||
|
@ -8506,8 +8496,6 @@ remote_flash_erase (struct target_ops *ops,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_cleanups (back_to);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum target_xfer_status
|
static enum target_xfer_status
|
||||||
|
@ -8515,30 +8503,21 @@ remote_flash_write (struct target_ops *ops, ULONGEST address,
|
||||||
ULONGEST length, ULONGEST *xfered_len,
|
ULONGEST length, ULONGEST *xfered_len,
|
||||||
const gdb_byte *data)
|
const gdb_byte *data)
|
||||||
{
|
{
|
||||||
int saved_remote_timeout = remote_timeout;
|
scoped_restore restore_timeout
|
||||||
enum target_xfer_status ret;
|
= make_scoped_restore (&remote_timeout, remote_flash_timeout);
|
||||||
struct cleanup *back_to = make_cleanup (restore_remote_timeout,
|
return remote_write_bytes_aux ("vFlashWrite:", address, data, length, 1,
|
||||||
&saved_remote_timeout);
|
xfered_len,'X', 0);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
remote_flash_done (struct target_ops *ops)
|
remote_flash_done (struct target_ops *ops)
|
||||||
{
|
{
|
||||||
int saved_remote_timeout = remote_timeout;
|
|
||||||
int ret;
|
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");
|
ret = remote_send_printf ("vFlashDone");
|
||||||
do_cleanups (back_to);
|
|
||||||
|
|
||||||
switch (ret)
|
switch (ret)
|
||||||
{
|
{
|
||||||
|
@ -8586,18 +8565,18 @@ readchar (int timeout)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
struct remote_state *rs = get_remote_state ();
|
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)
|
if (rs->got_ctrlc_during_io)
|
||||||
set_quit_flag ();
|
set_quit_flag ();
|
||||||
|
}
|
||||||
do_cleanups (old_chain);
|
|
||||||
|
|
||||||
if (ch >= 0)
|
if (ch >= 0)
|
||||||
return ch;
|
return ch;
|
||||||
|
@ -8628,9 +8607,9 @@ static void
|
||||||
remote_serial_write (const char *str, int len)
|
remote_serial_write (const char *str, int len)
|
||||||
{
|
{
|
||||||
struct remote_state *rs = get_remote_state ();
|
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;
|
||||||
|
|
||||||
|
@ -8642,8 +8621,6 @@ remote_serial_write (const char *str, int len)
|
||||||
|
|
||||||
if (rs->got_ctrlc_during_io)
|
if (rs->got_ctrlc_during_io)
|
||||||
set_quit_flag ();
|
set_quit_flag ();
|
||||||
|
|
||||||
do_cleanups (old_chain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send the command in *BUF to the remote machine, and read the reply
|
/* Send the command in *BUF to the remote machine, and read the reply
|
||||||
|
|
|
@ -30,13 +30,6 @@
|
||||||
/* User interface:
|
/* User interface:
|
||||||
reverse-step, reverse-next etc. */
|
reverse-step, reverse-next etc. */
|
||||||
|
|
||||||
static void
|
|
||||||
exec_direction_default (void *notused)
|
|
||||||
{
|
|
||||||
/* Return execution direction to default state. */
|
|
||||||
execution_direction = EXEC_FORWARD;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* exec_reverse_once -- accepts an arbitrary gdb command (string),
|
/* exec_reverse_once -- accepts an arbitrary gdb command (string),
|
||||||
and executes it with exec-direction set to 'reverse'.
|
and executes it with exec-direction set to 'reverse'.
|
||||||
|
|
||||||
|
@ -45,9 +38,7 @@ exec_direction_default (void *notused)
|
||||||
static void
|
static void
|
||||||
exec_reverse_once (const char *cmd, char *args, int from_tty)
|
exec_reverse_once (const char *cmd, char *args, int from_tty)
|
||||||
{
|
{
|
||||||
char *reverse_command;
|
|
||||||
enum exec_direction_kind dir = execution_direction;
|
enum exec_direction_kind dir = execution_direction;
|
||||||
struct cleanup *old_chain;
|
|
||||||
|
|
||||||
if (dir == EXEC_REVERSE)
|
if (dir == EXEC_REVERSE)
|
||||||
error (_("Already in reverse mode. Use '%s' or 'set exec-dir forward'."),
|
error (_("Already in reverse mode. Use '%s' or 'set exec-dir forward'."),
|
||||||
|
@ -56,12 +47,10 @@ exec_reverse_once (const char *cmd, char *args, int from_tty)
|
||||||
if (!target_can_execute_reverse)
|
if (!target_can_execute_reverse)
|
||||||
error (_("Target %s does not support this command."), target_shortname);
|
error (_("Target %s does not support this command."), target_shortname);
|
||||||
|
|
||||||
reverse_command = xstrprintf ("%s %s", cmd, args ? args : "");
|
std::string reverse_command = string_printf ("%s %s", cmd, args ? args : "");
|
||||||
old_chain = make_cleanup (exec_direction_default, NULL);
|
scoped_restore restore_exec_dir
|
||||||
make_cleanup (xfree, reverse_command);
|
= make_scoped_restore (&execution_direction, EXEC_REVERSE);
|
||||||
execution_direction = EXEC_REVERSE;
|
execute_command (&reverse_command[0], from_tty);
|
||||||
execute_command (reverse_command, from_tty);
|
|
||||||
do_cleanups (old_chain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue