aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-06-14 16:01:24 -0700
committerTom Tromey <tom@tromey.com>2018-09-17 00:42:18 -0600
commitc7c4d3fa80d2fef74fd4bd6b1e22c0399b19455f (patch)
treed42df5d986adb8a733883a1f1f66cbb159adf1b3
parentee841dd8fee73c355587533027aecc8983bd5478 (diff)
downloadgdb-c7c4d3fa80d2fef74fd4bd6b1e22c0399b19455f.zip
gdb-c7c4d3fa80d2fef74fd4bd6b1e22c0399b19455f.tar.gz
gdb-c7c4d3fa80d2fef74fd4bd6b1e22c0399b19455f.tar.bz2
Remove two infrun cleanups
This removes a couple of cleanups from infrun by introducing a couple of unique_ptr specializations. gdb/ChangeLog 2018-09-17 Tom Tromey <tom@tromey.com> * inferior.h (struct infcall_suspend_state_deleter): New. (infcall_suspend_state_up): New typedef. (struct infcall_control_state_deleter): New. (infcall_control_state_up): New typedef. (make_cleanup_restore_infcall_suspend_state) (make_cleanup_restore_infcall_control_state): Don't declare. * infcall.c (call_function_by_hand_dummy): Update. * infrun.c (do_restore_infcall_suspend_state_cleanup) (make_cleanup_restore_infcall_suspend_state): Remove. (do_restore_infcall_control_state_cleanup) (make_cleanup_restore_infcall_control_state): Remove.
-rw-r--r--gdb/ChangeLog14
-rw-r--r--gdb/infcall.c39
-rw-r--r--gdb/inferior.h31
-rw-r--r--gdb/infrun.c26
4 files changed, 55 insertions, 55 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 681ed3a..3c5ebb5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,19 @@
2018-09-17 Tom Tromey <tom@tromey.com>
+ * inferior.h (struct infcall_suspend_state_deleter): New.
+ (infcall_suspend_state_up): New typedef.
+ (struct infcall_control_state_deleter): New.
+ (infcall_control_state_up): New typedef.
+ (make_cleanup_restore_infcall_suspend_state)
+ (make_cleanup_restore_infcall_control_state): Don't declare.
+ * infcall.c (call_function_by_hand_dummy): Update.
+ * infrun.c (do_restore_infcall_suspend_state_cleanup)
+ (make_cleanup_restore_infcall_suspend_state): Remove.
+ (do_restore_infcall_control_state_cleanup)
+ (make_cleanup_restore_infcall_control_state): Remove.
+
+2018-09-17 Tom Tromey <tom@tromey.com>
+
* gdbthread.h (struct thread_control_state): Add initializer.
(class thread_info) <control>: Remove initializer.
* inferior.h (struct inferior_control_state): Add initializer.
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 7b1d44c..96d4370 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -721,9 +721,6 @@ call_function_by_hand_dummy (struct value *function,
struct type *target_values_type;
unsigned char struct_return = 0, hidden_first_param_p = 0;
CORE_ADDR struct_addr = 0;
- struct infcall_control_state *inf_status;
- struct cleanup *inf_status_cleanup;
- struct infcall_suspend_state *caller_state;
CORE_ADDR real_pc;
CORE_ADDR bp_addr;
struct frame_id dummy_id;
@@ -757,19 +754,16 @@ call_function_by_hand_dummy (struct value *function,
if (!gdbarch_push_dummy_call_p (gdbarch))
error (_("This target does not support function calls."));
- /* A cleanup for the inferior status.
+ /* A holder for the inferior status.
This is only needed while we're preparing the inferior function call. */
- inf_status = save_infcall_control_state ();
- inf_status_cleanup
- = make_cleanup_restore_infcall_control_state (inf_status);
+ infcall_control_state_up inf_status (save_infcall_control_state ());
/* Save the caller's registers and other state associated with the
inferior itself so that they can be restored once the
callee returns. To allow nested calls the registers are (further
- down) pushed onto a dummy frame stack. Include a cleanup (which
- is tossed once the regcache has been pushed). */
- caller_state = save_infcall_suspend_state ();
- make_cleanup_restore_infcall_suspend_state (caller_state);
+ down) pushed onto a dummy frame stack. This unique pointer
+ is released once the regcache has been pushed). */
+ infcall_suspend_state_up caller_state (save_infcall_suspend_state ());
/* Ensure that the initial SP is correctly aligned. */
{
@@ -1126,15 +1120,10 @@ call_function_by_hand_dummy (struct value *function,
if (unwind_on_terminating_exception_p)
set_std_terminate_breakpoint ();
- /* Discard both inf_status and caller_state cleanups.
- From this point on we explicitly restore the associated state
- or discard it. */
- discard_cleanups (inf_status_cleanup);
-
/* Everything's ready, push all the info needed to restore the
caller (and identify the dummy-frame) onto the dummy-frame
stack. */
- dummy_frame_push (caller_state, &dummy_id, call_thread.get ());
+ dummy_frame_push (caller_state.release (), &dummy_id, call_thread.get ());
if (dummy_dtor != NULL)
register_dummy_frame_dtor (dummy_id, call_thread.get (),
dummy_dtor, dummy_dtor_data);
@@ -1189,7 +1178,7 @@ call_function_by_hand_dummy (struct value *function,
suspend state, and restore the inferior control
state. */
dummy_frame_pop (dummy_id, call_thread.get ());
- restore_infcall_control_state (inf_status);
+ restore_infcall_control_state (inf_status.release ());
/* Get the return value. */
retval = sm->return_value;
@@ -1220,7 +1209,7 @@ call_function_by_hand_dummy (struct value *function,
const char *name = get_function_name (funaddr,
name_buf, sizeof (name_buf));
- discard_infcall_control_state (inf_status);
+ discard_infcall_control_state (inf_status.release ());
/* We could discard the dummy frame here if the program exited,
but it will get garbage collected the next time the program is
@@ -1251,7 +1240,7 @@ When the function is done executing, GDB will silently stop."),
/* If we try to restore the inferior status,
we'll crash as the inferior is no longer running. */
- discard_infcall_control_state (inf_status);
+ discard_infcall_control_state (inf_status.release ());
/* We could discard the dummy frame here given that the program exited,
but it will get garbage collected the next time the program is
@@ -1273,7 +1262,7 @@ When the function is done executing, GDB will silently stop."),
signal or breakpoint while our thread was running.
There's no point in restoring the inferior status,
we're in a different thread. */
- discard_infcall_control_state (inf_status);
+ discard_infcall_control_state (inf_status.release ());
/* Keep the dummy frame record, if the user switches back to the
thread with the hand-call, we'll need it. */
if (stopped_by_random_signal)
@@ -1314,7 +1303,7 @@ When the function is done executing, GDB will silently stop."),
/* We also need to restore inferior status to that before the
dummy call. */
- restore_infcall_control_state (inf_status);
+ restore_infcall_control_state (inf_status.release ());
/* FIXME: Insert a bunch of wrap_here; name can be very
long if it's a C++ name with arguments and stuff. */
@@ -1332,7 +1321,7 @@ Evaluation of the expression containing the function\n\
(default).
Discard inferior status, we're not at the same point
we started at. */
- discard_infcall_control_state (inf_status);
+ discard_infcall_control_state (inf_status.release ());
/* FIXME: Insert a bunch of wrap_here; name can be very
long if it's a C++ name with arguments and stuff. */
@@ -1355,7 +1344,7 @@ When the function is done executing, GDB will silently stop."),
/* We also need to restore inferior status to that before
the dummy call. */
- restore_infcall_control_state (inf_status);
+ restore_infcall_control_state (inf_status.release ());
error (_("\
The program being debugged entered a std::terminate call, most likely\n\
@@ -1374,7 +1363,7 @@ will be abandoned."),
Keep the dummy frame, the user may want to examine its state.
Discard inferior status, we're not at the same point
we started at. */
- discard_infcall_control_state (inf_status);
+ discard_infcall_control_state (inf_status.release ());
/* The following error message used to say "The expression
which contained the function call has been discarded."
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 9f431de..5c8ef33 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -63,10 +63,33 @@ extern struct infcall_control_state *save_infcall_control_state (void);
extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
extern void restore_infcall_control_state (struct infcall_control_state *);
-extern struct cleanup *make_cleanup_restore_infcall_suspend_state
- (struct infcall_suspend_state *);
-extern struct cleanup *make_cleanup_restore_infcall_control_state
- (struct infcall_control_state *);
+/* A deleter for infcall_suspend_state that calls
+ restore_infcall_suspend_state. */
+struct infcall_suspend_state_deleter
+{
+ void operator() (struct infcall_suspend_state *state) const
+ {
+ restore_infcall_suspend_state (state);
+ }
+};
+
+/* A unique_ptr specialization for infcall_suspend_state. */
+typedef std::unique_ptr<infcall_suspend_state, infcall_suspend_state_deleter>
+ infcall_suspend_state_up;
+
+/* A deleter for infcall_control_state that calls
+ restore_infcall_control_state. */
+struct infcall_control_state_deleter
+{
+ void operator() (struct infcall_control_state *state) const
+ {
+ restore_infcall_control_state (state);
+ }
+};
+
+/* A unique_ptr specialization for infcall_control_state. */
+typedef std::unique_ptr<infcall_control_state, infcall_control_state_deleter>
+ infcall_control_state_up;
extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
extern void discard_infcall_control_state (struct infcall_control_state *);
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 0df539a..4828720 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8893,19 +8893,6 @@ restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
discard_infcall_suspend_state (inf_state);
}
-static void
-do_restore_infcall_suspend_state_cleanup (void *state)
-{
- restore_infcall_suspend_state ((struct infcall_suspend_state *) state);
-}
-
-struct cleanup *
-make_cleanup_restore_infcall_suspend_state
- (struct infcall_suspend_state *inf_state)
-{
- return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
-}
-
void
discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
{
@@ -9030,19 +9017,6 @@ restore_infcall_control_state (struct infcall_control_state *inf_status)
delete inf_status;
}
-static void
-do_restore_infcall_control_state_cleanup (void *sts)
-{
- restore_infcall_control_state ((struct infcall_control_state *) sts);
-}
-
-struct cleanup *
-make_cleanup_restore_infcall_control_state
- (struct infcall_control_state *inf_status)
-{
- return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
-}
-
void
discard_infcall_control_state (struct infcall_control_state *inf_status)
{