* [RFA v2 6/6] Make save_infcall_*_state return unique pointers
2018-07-18 14:09 [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
` (2 preceding siblings ...)
2018-07-18 14:09 ` [RFA v2 4/6] Remove two infrun cleanups Tom Tromey
@ 2018-07-18 14:09 ` Tom Tromey
2018-07-18 14:09 ` [RFA v2 5/6] Remove release_stop_context_cleanup Tom Tromey
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2018-07-18 14:09 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
Simon pointed out that save_infcall_suspend_state and
save_infcall_control_state could return unique pointers. This patch
implements this idea.
gdb/ChangeLog
2018-07-18 Tom Tromey <tom@tromey.com>
* infrun.c (save_infcall_suspend_state): Return
infcall_suspend_state_up.
(save_infcall_control_state): Return infcall_control_state_up.
* inferior.h (save_infcall_suspend_state)
(save_infcall_control_state): Declare later. Return unique
pointers.
---
gdb/ChangeLog | 9 +++++++++
gdb/inferior.h | 7 ++++---
gdb/infrun.c | 13 ++++++-------
3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d786f1f3838..733b513c4b2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2018-07-18 Tom Tromey <tom@tromey.com>
+
+ * infrun.c (save_infcall_suspend_state): Return
+ infcall_suspend_state_up.
+ (save_infcall_control_state): Return infcall_control_state_up.
+ * inferior.h (save_infcall_suspend_state)
+ (save_infcall_control_state): Declare later. Return unique
+ pointers.
+
2018-07-18 Tom Tromey <tom@tromey.com>
* infrun.c (struct stop_context): Declare constructor,
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 02fb71e4b3e..e02500fdb1e 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -57,9 +57,6 @@ struct thread_info;
struct infcall_suspend_state;
struct infcall_control_state;
-extern struct infcall_suspend_state *save_infcall_suspend_state (void);
-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 *);
@@ -77,6 +74,8 @@ struct infcall_suspend_state_deleter
typedef std::unique_ptr<infcall_suspend_state, infcall_suspend_state_deleter>
infcall_suspend_state_up;
+extern infcall_suspend_state_up save_infcall_suspend_state ();
+
/* A deleter for infcall_control_state that calls
restore_infcall_control_state. */
struct infcall_control_state_deleter
@@ -91,6 +90,8 @@ struct infcall_control_state_deleter
typedef std::unique_ptr<infcall_control_state, infcall_control_state_deleter>
infcall_control_state_up;
+extern infcall_control_state_up save_infcall_control_state ();
+
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 15bdf004b1a..d74953e4417 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8816,10 +8816,9 @@ struct infcall_suspend_state
gdb::unique_xmalloc_ptr<gdb_byte> siginfo_data;
};
-struct infcall_suspend_state *
-save_infcall_suspend_state (void)
+infcall_suspend_state_up
+save_infcall_suspend_state ()
{
- struct infcall_suspend_state *inf_state;
struct thread_info *tp = inferior_thread ();
struct regcache *regcache = get_current_regcache ();
struct gdbarch *gdbarch = regcache->arch ();
@@ -8840,7 +8839,7 @@ save_infcall_suspend_state (void)
}
}
- inf_state = new struct infcall_suspend_state;
+ infcall_suspend_state_up inf_state (new struct infcall_suspend_state);
if (siginfo_data)
{
@@ -8920,10 +8919,10 @@ struct infcall_control_state
/* Save all of the information associated with the inferior<==>gdb
connection. */
-struct infcall_control_state *
-save_infcall_control_state (void)
+infcall_control_state_up
+save_infcall_control_state ()
{
- struct infcall_control_state *inf_status = new struct infcall_control_state;
+ infcall_control_state_up inf_status (new struct infcall_control_state);
struct thread_info *tp = inferior_thread ();
struct inferior *inf = current_inferior ();
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFA v2 1/6] Use new and delete for struct infcall_suspend_state
2018-07-18 14:09 [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
2018-07-18 14:09 ` [RFA v2 3/6] Use new and delete for struct infcall_control_state Tom Tromey
@ 2018-07-18 14:09 ` Tom Tromey
2018-07-18 14:09 ` [RFA v2 4/6] Remove two infrun cleanups Tom Tromey
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2018-07-18 14:09 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes infrun.c to use new and delete for infcall_suspend_state.
This enables the coming cleanups.
gdb/ChangeLog
2018-07-18 Tom Tromey <tom@tromey.com>
* gdbthread.h (struct thread_suspend_state): Add initializers.
(class thread_info) <suspend>: Remove initializer.
* infrun.c (struct infcall_suspend_state): Add initializers.
(save_infcall_suspend_state): Use new.
(discard_infcall_suspend_state): Use delete.
---
gdb/ChangeLog | 8 ++++++++
gdb/gdbthread.h | 12 ++++++------
gdb/infrun.c | 10 +++++-----
3 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7e7f88a12b9..79675a060ce 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2018-07-18 Tom Tromey <tom@tromey.com>
+
+ * gdbthread.h (struct thread_suspend_state): Add initializers.
+ (class thread_info) <suspend>: Remove initializer.
+ * infrun.c (struct infcall_suspend_state): Add initializers.
+ (save_infcall_suspend_state): Use new.
+ (discard_infcall_suspend_state): Use delete.
+
2018-07-17 Tom Tromey <tom@tromey.com>
* guile/scm-param.c (pascm_set_func, pascm_show_func)
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 2c402543ddb..99de5ff0d80 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -155,16 +155,16 @@ struct thread_suspend_state
"signal" command, which overrides "handle nopass". If the signal
should be suppressed, the core will take care of clearing this
before the target is resumed. */
- enum gdb_signal stop_signal;
+ enum gdb_signal stop_signal = GDB_SIGNAL_0;
/* The reason the thread last stopped, if we need to track it
(breakpoint, watchpoint, etc.) */
- enum target_stop_reason stop_reason;
+ enum target_stop_reason stop_reason = TARGET_STOPPED_BY_NO_REASON;
/* The waitstatus for this thread's last event. */
- struct target_waitstatus waitstatus;
+ struct target_waitstatus waitstatus {};
/* If true WAITSTATUS hasn't been handled yet. */
- int waitstatus_pending_p;
+ int waitstatus_pending_p = 0;
/* Record the pc of the thread the last time it stopped. (This is
not the current thread's PC as that may have changed since the
@@ -181,7 +181,7 @@ struct thread_suspend_state
- If the thread is running, this is set to -1, to avoid leaving
it with a stale value, to make it easier to catch bugs. */
- CORE_ADDR stop_pc;
+ CORE_ADDR stop_pc = 0;
};
/* Base class for target-specific thread data. */
@@ -300,7 +300,7 @@ public:
/* State of inferior thread to restore after GDB is done with an inferior
call. See `struct thread_suspend_state'. */
- thread_suspend_state suspend {};
+ thread_suspend_state suspend;
int current_line = 0;
struct symtab *current_symtab = NULL;
diff --git a/gdb/infrun.c b/gdb/infrun.c
index dd7e69e718e..c9d3a0075ba 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8813,15 +8813,15 @@ struct infcall_suspend_state
struct thread_suspend_state thread_suspend;
/* Other fields: */
- readonly_detached_regcache *registers;
+ readonly_detached_regcache *registers = nullptr;
/* Format of SIGINFO_DATA or NULL if it is not present. */
- struct gdbarch *siginfo_gdbarch;
+ struct gdbarch *siginfo_gdbarch = nullptr;
/* The inferior format depends on SIGINFO_GDBARCH and it has a length of
TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
content would be invalid. */
- gdb_byte *siginfo_data;
+ gdb_byte *siginfo_data = nullptr;
};
struct infcall_suspend_state *
@@ -8853,7 +8853,7 @@ save_infcall_suspend_state (void)
}
}
- inf_state = XCNEW (struct infcall_suspend_state);
+ inf_state = new struct infcall_suspend_state;
if (siginfo_data)
{
@@ -8919,7 +8919,7 @@ discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
{
delete inf_state->registers;
xfree (inf_state->siginfo_data);
- xfree (inf_state);
+ delete inf_state;
}
readonly_detached_regcache *
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFA v2 3/6] Use new and delete for struct infcall_control_state
2018-07-18 14:09 [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
@ 2018-07-18 14:09 ` Tom Tromey
2018-07-18 14:09 ` [RFA v2 1/6] Use new and delete for struct infcall_suspend_state Tom Tromey
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2018-07-18 14:09 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes infrun.c to use new and delete for infcall_control_state.
gdb/ChangeLog
2018-07-18 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.
(class inferior) <control>: Remove initializer.
(exit_inferior_1): Update.
* infrun.c (struct infcall_control_state): Add constructors.
(save_infcall_control_state): Use new.
(restore_infcall_control_state, discard_infcall_control_state):
Use delete.
---
gdb/ChangeLog | 12 ++++++++++++
gdb/gdbthread.h | 34 +++++++++++++++++-----------------
gdb/inferior.c | 2 +-
gdb/inferior.h | 12 +++++++++++-
gdb/infrun.c | 13 ++++++-------
5 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 86bb06f0776..ee2c4051e77 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,15 @@
+2018-07-18 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.
+ (class inferior) <control>: Remove initializer.
+ (exit_inferior_1): Update.
+ * infrun.c (struct infcall_control_state): Add constructors.
+ (save_infcall_control_state): Use new.
+ (restore_infcall_control_state, discard_infcall_control_state):
+ Use delete.
+
2018-07-18 Tom Tromey <tom@tromey.com>
* infrun.c (struct infcall_suspend_state) <registers>: Now a
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 99de5ff0d80..2738e44da9f 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -52,17 +52,17 @@ struct thread_control_state
/* User/external stepping state. */
/* Step-resume or longjmp-resume breakpoint. */
- struct breakpoint *step_resume_breakpoint;
+ struct breakpoint *step_resume_breakpoint = nullptr;
/* Exception-resume breakpoint. */
- struct breakpoint *exception_resume_breakpoint;
+ struct breakpoint *exception_resume_breakpoint = nullptr;
/* Breakpoints used for software single stepping. Plural, because
it may have multiple locations. E.g., if stepping over a
conditional branch instruction we can't decode the condition for,
we'll need to put a breakpoint at the branch destination, and
another at the instruction after the branch. */
- struct breakpoint *single_step_breakpoints;
+ struct breakpoint *single_step_breakpoints = nullptr;
/* Range to single step within.
@@ -74,11 +74,11 @@ struct thread_control_state
wait_for_inferior in a minor way if this were changed to the
address of the instruction and that address plus one. But maybe
not). */
- CORE_ADDR step_range_start; /* Inclusive */
- CORE_ADDR step_range_end; /* Exclusive */
+ CORE_ADDR step_range_start = 0; /* Inclusive */
+ CORE_ADDR step_range_end = 0; /* Exclusive */
/* Function the thread was in as of last it started stepping. */
- struct symbol *step_start_function;
+ struct symbol *step_start_function = nullptr;
/* If GDB issues a target step request, and this is nonzero, the
target should single-step this thread once, and then continue
@@ -86,16 +86,16 @@ struct thread_control_state
thread stops in the step range above. If this is zero, the
target should ignore the step range, and only issue one single
step. */
- int may_range_step;
+ int may_range_step = 0;
/* Stack frame address as of when stepping command was issued.
This is how we know when we step into a subroutine call, and how
to set the frame for the breakpoint used to step out. */
- struct frame_id step_frame_id;
+ struct frame_id step_frame_id {};
/* Similarly, the frame ID of the underlying stack frame (skipping
any inlined frames). */
- struct frame_id step_stack_frame_id;
+ struct frame_id step_stack_frame_id {};
/* Nonzero if we are presently stepping over a breakpoint.
@@ -119,29 +119,29 @@ struct thread_control_state
wait_for_inferior, which calls handle_inferior_event in a loop,
and until wait_for_inferior exits, this variable is changed only
by keep_going. */
- int trap_expected;
+ int trap_expected = 0;
/* Nonzero if the thread is being proceeded for a "finish" command
or a similar situation when return value should be printed. */
- int proceed_to_finish;
+ int proceed_to_finish = 0;
/* Nonzero if the thread is being proceeded for an inferior function
call. */
- int in_infcall;
+ int in_infcall = 0;
- enum step_over_calls_kind step_over_calls;
+ enum step_over_calls_kind step_over_calls = STEP_OVER_NONE;
/* Nonzero if stopped due to a step command. */
- int stop_step;
+ int stop_step = 0;
/* Chain containing status of breakpoint(s) the thread stopped
at. */
- bpstat stop_bpstat;
+ bpstat stop_bpstat = nullptr;
/* Whether the command that started the thread was a stepping
command. This is used to decide whether "set scheduler-locking
step" behaves like "on" or "off". */
- int stepping_command;
+ int stepping_command = 0;
};
/* Inferior thread specific part of `struct infcall_suspend_state'. */
@@ -296,7 +296,7 @@ public:
/* State of GDB control of inferior thread execution.
See `struct thread_control_state'. */
- thread_control_state control {};
+ thread_control_state control;
/* State of inferior thread to restore after GDB is done with an inferior
call. See `struct thread_suspend_state'. */
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 16991d41b3b..58c892586d2 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -226,7 +226,7 @@ exit_inferior_1 (struct inferior *inftoex, int silent)
inf->pending_detach = 0;
/* Reset it. */
- inf->control = {NO_STOP_QUIETLY};
+ inf->control = inferior_control_state (NO_STOP_QUIETLY);
}
void
diff --git a/gdb/inferior.h b/gdb/inferior.h
index c5dc324fa39..e79c17ea8cd 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -283,6 +283,16 @@ struct private_inferior
struct inferior_control_state
{
+ inferior_control_state ()
+ : stop_soon (NO_STOP_QUIETLY)
+ {
+ }
+
+ explicit inferior_control_state (enum stop_kind when)
+ : stop_soon (when)
+ {
+ }
+
/* See the definition of stop_kind above. */
enum stop_kind stop_soon;
};
@@ -341,7 +351,7 @@ public:
/* State of GDB control of inferior process execution.
See `struct inferior_control_state'. */
- inferior_control_state control {NO_STOP_QUIETLY};
+ inferior_control_state control;
/* True if this was an auto-created inferior, e.g. created from
following a fork; false, if this inferior was manually added by
diff --git a/gdb/infrun.c b/gdb/infrun.c
index b430a731693..f6bf86e5a19 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8931,11 +8931,11 @@ struct infcall_control_state
struct inferior_control_state inferior_control;
/* Other fields: */
- enum stop_stack_kind stop_stack_dummy;
- int stopped_by_random_signal;
+ enum stop_stack_kind stop_stack_dummy = STOP_NONE;
+ int stopped_by_random_signal = 0;
/* ID if the selected frame when the inferior function call was made. */
- struct frame_id selected_frame_id;
+ struct frame_id selected_frame_id {};
};
/* Save all of the information associated with the inferior<==>gdb
@@ -8944,8 +8944,7 @@ struct infcall_control_state
struct infcall_control_state *
save_infcall_control_state (void)
{
- struct infcall_control_state *inf_status =
- XNEW (struct infcall_control_state);
+ struct infcall_control_state *inf_status = new struct infcall_control_state;
struct thread_info *tp = inferior_thread ();
struct inferior *inf = current_inferior ();
@@ -9031,7 +9030,7 @@ restore_infcall_control_state (struct infcall_control_state *inf_status)
END_CATCH
}
- xfree (inf_status);
+ delete inf_status;
}
static void
@@ -9061,7 +9060,7 @@ discard_infcall_control_state (struct infcall_control_state *inf_status)
/* See save_infcall_control_state for info on stop_bpstat. */
bpstat_clear (&inf_status->thread_control.stop_bpstat);
- xfree (inf_status);
+ delete inf_status;
}
\f
/* See infrun.h. */
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFA v2 0/6] remove some infrun-related cleanups
@ 2018-07-18 14:09 Tom Tromey
2018-07-18 14:09 ` [RFA v2 3/6] Use new and delete for struct infcall_control_state Tom Tromey
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Tom Tromey @ 2018-07-18 14:09 UTC (permalink / raw)
To: gdb-patches
This is v2 of the series to remove some infrun-related cleanups.
v1 was here:
https://sourceware.org/ml/gdb-patches/2018-07/msg00304.html
I believe this version addresses all the review comments.
Tested by the buildbot.
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFA v2 5/6] Remove release_stop_context_cleanup
2018-07-18 14:09 [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
` (3 preceding siblings ...)
2018-07-18 14:09 ` [RFA v2 6/6] Make save_infcall_*_state return unique pointers Tom Tromey
@ 2018-07-18 14:09 ` Tom Tromey
2018-07-18 14:12 ` [RFA v2 2/6] Remove cleanup from infrun.c Tom Tromey
2018-09-17 6:42 ` [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2018-07-18 14:09 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This removes release_stop_context_cleanup, replacing it with a
stop_context destructor. It also mildly c++-ifies this struct.
gdb/ChangeLog
2018-07-18 Tom Tromey <tom@tromey.com>
* infrun.c (struct stop_context): Declare constructor,
destructor, "changed" method.
(stop_context::stop_context): Rename from save_stop_context.
(stop_context::~stop_context): Rename from
release_stop_context_cleanup.
(normal_stop): Update.
(stop_context::changed): Rename from stop_context_changed. Return
bool.
---
gdb/ChangeLog | 11 ++++++++
gdb/infrun.c | 74 +++++++++++++++++++++++----------------------------
2 files changed, 44 insertions(+), 41 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e0dd2988f72..d786f1f3838 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,14 @@
+2018-07-18 Tom Tromey <tom@tromey.com>
+
+ * infrun.c (struct stop_context): Declare constructor,
+ destructor, "changed" method.
+ (stop_context::stop_context): Rename from save_stop_context.
+ (stop_context::~stop_context): Rename from
+ release_stop_context_cleanup.
+ (normal_stop): Update.
+ (stop_context::changed): Rename from stop_context_changed. Return
+ bool.
+
2018-07-18 Tom Tromey <tom@tromey.com>
* inferior.h (struct infcall_suspend_state_deleter): New.
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 9dbea4a58ac..15bdf004b1a 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8098,6 +8098,13 @@ maybe_remove_breakpoints (void)
struct stop_context
{
+ stop_context ();
+ ~stop_context ();
+
+ DISABLE_COPY_AND_ASSIGN (stop_context);
+
+ bool changed () const;
+
/* The stop ID. */
ULONGEST stop_id;
@@ -8113,59 +8120,50 @@ struct stop_context
int inf_num;
};
-/* Returns a new stop context. If stopped for a thread event, this
+/* Initializes a new stop context. If stopped for a thread event, this
takes a strong reference to the thread. */
-static struct stop_context *
-save_stop_context (void)
+stop_context::stop_context ()
{
- struct stop_context *sc = XNEW (struct stop_context);
-
- sc->stop_id = get_stop_id ();
- sc->ptid = inferior_ptid;
- sc->inf_num = current_inferior ()->num;
+ stop_id = get_stop_id ();
+ ptid = inferior_ptid;
+ inf_num = current_inferior ()->num;
if (inferior_ptid != null_ptid)
{
/* Take a strong reference so that the thread can't be deleted
yet. */
- sc->thread = inferior_thread ();
- sc->thread->incref ();
+ thread = inferior_thread ();
+ thread->incref ();
}
else
- sc->thread = NULL;
-
- return sc;
+ thread = NULL;
}
/* Release a stop context previously created with save_stop_context.
Releases the strong reference to the thread as well. */
-static void
-release_stop_context_cleanup (void *arg)
+stop_context::~stop_context ()
{
- struct stop_context *sc = (struct stop_context *) arg;
-
- if (sc->thread != NULL)
- sc->thread->decref ();
- xfree (sc);
+ if (thread != NULL)
+ thread->decref ();
}
/* Return true if the current context no longer matches the saved stop
context. */
-static int
-stop_context_changed (struct stop_context *prev)
-{
- if (prev->ptid != inferior_ptid)
- return 1;
- if (prev->inf_num != current_inferior ()->num)
- return 1;
- if (prev->thread != NULL && prev->thread->state != THREAD_STOPPED)
- return 1;
- if (get_stop_id () != prev->stop_id)
- return 1;
- return 0;
+bool
+stop_context::changed () const
+{
+ if (ptid != inferior_ptid)
+ return true;
+ if (inf_num != current_inferior ()->num)
+ return true;
+ if (thread != NULL && thread->state != THREAD_STOPPED)
+ return true;
+ if (get_stop_id () != stop_id)
+ return true;
+ return false;
}
/* See infrun.h. */
@@ -8308,9 +8306,7 @@ normal_stop (void)
of stop_command's pre-hook not existing). */
if (stop_command != NULL)
{
- struct stop_context *saved_context = save_stop_context ();
- struct cleanup *old_chain
- = make_cleanup (release_stop_context_cleanup, saved_context);
+ stop_context saved_context;
TRY
{
@@ -8328,12 +8324,8 @@ normal_stop (void)
gone. Likewise if the command switches thread or inferior --
the observers would print a stop for the wrong
thread/inferior. */
- if (stop_context_changed (saved_context))
- {
- do_cleanups (old_chain);
- return 1;
- }
- do_cleanups (old_chain);
+ if (saved_context.changed ())
+ return 1;
}
/* Notify observers about the stop. This is where the interpreters
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFA v2 4/6] Remove two infrun cleanups
2018-07-18 14:09 [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
2018-07-18 14:09 ` [RFA v2 3/6] Use new and delete for struct infcall_control_state Tom Tromey
2018-07-18 14:09 ` [RFA v2 1/6] Use new and delete for struct infcall_suspend_state Tom Tromey
@ 2018-07-18 14:09 ` Tom Tromey
2018-07-18 14:09 ` [RFA v2 6/6] Make save_infcall_*_state return unique pointers Tom Tromey
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2018-07-18 14:09 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This removes a couple of cleanups from infrun by introducing a couple
of unique_ptr specializations.
gdb/ChangeLog
2018-07-18 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.
---
gdb/ChangeLog | 14 ++++++++++++++
gdb/infcall.c | 39 ++++++++++++++-------------------------
gdb/inferior.h | 31 +++++++++++++++++++++++++++----
gdb/infrun.c | 26 --------------------------
4 files changed, 55 insertions(+), 55 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ee2c4051e77..e0dd2988f72 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,17 @@
+2018-07-18 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-07-18 Tom Tromey <tom@tromey.com>
* gdbthread.h (struct thread_control_state): Add initializer.
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 172c26ac820..b7071a722f1 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -724,9 +724,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;
@@ -760,19 +757,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. */
{
@@ -1133,15 +1127,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);
@@ -1196,7 +1185,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;
@@ -1227,7 +1216,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
@@ -1258,7 +1247,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
@@ -1280,7 +1269,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)
@@ -1321,7 +1310,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. */
@@ -1339,7 +1328,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. */
@@ -1362,7 +1351,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\
@@ -1381,7 +1370,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 e79c17ea8cd..02fb71e4b3e 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 f6bf86e5a19..9dbea4a58ac 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8896,19 +8896,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)
{
@@ -9033,19 +9020,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)
{
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFA v2 2/6] Remove cleanup from infrun.c
2018-07-18 14:09 [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
` (4 preceding siblings ...)
2018-07-18 14:09 ` [RFA v2 5/6] Remove release_stop_context_cleanup Tom Tromey
@ 2018-07-18 14:12 ` Tom Tromey
2018-09-17 6:42 ` [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2018-07-18 14:12 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This removes a cleanup from infrun.c by taking advantage of the
previous patch to introduce a use of unique_xmalloc_ptr.
gdb/ChangeLog
2018-07-18 Tom Tromey <tom@tromey.com>
* infrun.c (struct infcall_suspend_state) <registers>: Now a
unique_ptr.
<siginfo_data>: Now a unique_xmalloc_ptr.
(save_infcall_suspend_state, restore_infcall_suspend_state)
(discard_infcall_suspend_state)
(get_infcall_suspend_state_regcache): Update.
---
gdb/ChangeLog | 9 +++++++++
gdb/infrun.c | 29 +++++++++++------------------
2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 79675a060ce..86bb06f0776 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2018-07-18 Tom Tromey <tom@tromey.com>
+
+ * infrun.c (struct infcall_suspend_state) <registers>: Now a
+ unique_ptr.
+ <siginfo_data>: Now a unique_xmalloc_ptr.
+ (save_infcall_suspend_state, restore_infcall_suspend_state)
+ (discard_infcall_suspend_state)
+ (get_infcall_suspend_state_regcache): Update.
+
2018-07-18 Tom Tromey <tom@tromey.com>
* gdbthread.h (struct thread_suspend_state): Add initializers.
diff --git a/gdb/infrun.c b/gdb/infrun.c
index c9d3a0075ba..b430a731693 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8813,7 +8813,7 @@ struct infcall_suspend_state
struct thread_suspend_state thread_suspend;
/* Other fields: */
- readonly_detached_regcache *registers = nullptr;
+ std::unique_ptr<readonly_detached_regcache> registers;
/* Format of SIGINFO_DATA or NULL if it is not present. */
struct gdbarch *siginfo_gdbarch = nullptr;
@@ -8821,7 +8821,7 @@ struct infcall_suspend_state
/* The inferior format depends on SIGINFO_GDBARCH and it has a length of
TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
content would be invalid. */
- gdb_byte *siginfo_data = nullptr;
+ gdb::unique_xmalloc_ptr<gdb_byte> siginfo_data;
};
struct infcall_suspend_state *
@@ -8831,25 +8831,20 @@ save_infcall_suspend_state (void)
struct thread_info *tp = inferior_thread ();
struct regcache *regcache = get_current_regcache ();
struct gdbarch *gdbarch = regcache->arch ();
- gdb_byte *siginfo_data = NULL;
+ gdb::unique_xmalloc_ptr<gdb_byte> siginfo_data;
if (gdbarch_get_siginfo_type_p (gdbarch))
{
struct type *type = gdbarch_get_siginfo_type (gdbarch);
size_t len = TYPE_LENGTH (type);
- struct cleanup *back_to;
- siginfo_data = (gdb_byte *) xmalloc (len);
- back_to = make_cleanup (xfree, siginfo_data);
+ siginfo_data.reset ((gdb_byte *) xmalloc (len));
if (target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL,
- siginfo_data, 0, len) == len)
- discard_cleanups (back_to);
- else
+ siginfo_data.get (), 0, len) != len)
{
/* Errors ignored. */
- do_cleanups (back_to);
- siginfo_data = NULL;
+ siginfo_data.reset (nullptr);
}
}
@@ -8858,7 +8853,7 @@ save_infcall_suspend_state (void)
if (siginfo_data)
{
inf_state->siginfo_gdbarch = gdbarch;
- inf_state->siginfo_data = siginfo_data;
+ inf_state->siginfo_data = std::move (siginfo_data);
}
inf_state->thread_suspend = tp->suspend;
@@ -8867,7 +8862,7 @@ save_infcall_suspend_state (void)
GDB_SIGNAL_0 anyway. */
tp->suspend.stop_signal = GDB_SIGNAL_0;
- inf_state->registers = new readonly_detached_regcache (*regcache);
+ inf_state->registers.reset (new readonly_detached_regcache (*regcache));
return inf_state;
}
@@ -8889,14 +8884,14 @@ restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
/* Errors ignored. */
target_write (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL,
- inf_state->siginfo_data, 0, TYPE_LENGTH (type));
+ inf_state->siginfo_data.get (), 0, TYPE_LENGTH (type));
}
/* The inferior can be gone if the user types "print exit(0)"
(and perhaps other times). */
if (target_has_execution)
/* NB: The register write goes through to the target. */
- regcache->restore (inf_state->registers);
+ regcache->restore (inf_state->registers.get ());
discard_infcall_suspend_state (inf_state);
}
@@ -8917,15 +8912,13 @@ make_cleanup_restore_infcall_suspend_state
void
discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
{
- delete inf_state->registers;
- xfree (inf_state->siginfo_data);
delete inf_state;
}
readonly_detached_regcache *
get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
{
- return inf_state->registers;
+ return inf_state->registers.get ();
}
/* infcall_control_state contains state regarding gdb's control of the
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA v2 0/6] remove some infrun-related cleanups
2018-07-18 14:09 [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
` (5 preceding siblings ...)
2018-07-18 14:12 ` [RFA v2 2/6] Remove cleanup from infrun.c Tom Tromey
@ 2018-09-17 6:42 ` Tom Tromey
6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2018-09-17 6:42 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
Tom> This is v2 of the series to remove some infrun-related cleanups.
Tom> v1 was here:
Tom> https://sourceware.org/ml/gdb-patches/2018-07/msg00304.html
Tom> I believe this version addresses all the review comments.
Tom> Tested by the buildbot.
I forgot about this for a while. Pedro had approved v1, and Simon asked
for a change, which I added in v2. Since the change was just changing
some types, I am going to check this in now.
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-09-17 6:42 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-18 14:09 [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
2018-07-18 14:09 ` [RFA v2 3/6] Use new and delete for struct infcall_control_state Tom Tromey
2018-07-18 14:09 ` [RFA v2 1/6] Use new and delete for struct infcall_suspend_state Tom Tromey
2018-07-18 14:09 ` [RFA v2 4/6] Remove two infrun cleanups Tom Tromey
2018-07-18 14:09 ` [RFA v2 6/6] Make save_infcall_*_state return unique pointers Tom Tromey
2018-07-18 14:09 ` [RFA v2 5/6] Remove release_stop_context_cleanup Tom Tromey
2018-07-18 14:12 ` [RFA v2 2/6] Remove cleanup from infrun.c Tom Tromey
2018-09-17 6:42 ` [RFA v2 0/6] remove some infrun-related cleanups Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).