@@ -21,6 +21,7 @@
#include "defs.h"
#include "infrun.h"
#include <ctype.h>
+#include <list>
#include "symtab.h"
#include "frame.h"
#include "inferior.h"
@@ -1484,9 +1485,6 @@ displaced_step_closure::~displaced_step_closure () = default;
/* Per-inferior displaced stepping state. */
struct displaced_step_inferior_state
{
- /* Pointer to next in linked list. */
- struct displaced_step_inferior_state *next;
-
/* The process this displaced step state refers to. */
inferior *inf;
@@ -1516,22 +1514,18 @@ struct displaced_step_inferior_state
/* The list of states of processes involved in displaced stepping
presently. */
-static struct displaced_step_inferior_state *displaced_step_inferior_states;
+static std::list<displaced_step_inferior_state> displaced_step_inferior_states;
/* Get the displaced stepping state of process PID. */
static struct displaced_step_inferior_state *
get_displaced_stepping_state (inferior *inf)
{
- struct displaced_step_inferior_state *state;
-
- for (state = displaced_step_inferior_states;
- state != NULL;
- state = state->next)
- if (state->inf == inf)
- return state;
+ for (displaced_step_inferior_state &state : displaced_step_inferior_states)
+ if (state.inf == inf)
+ return &state;
- return NULL;
+ return nullptr;
}
/* Returns true if any inferior has a thread doing a displaced
@@ -1540,12 +1534,8 @@ get_displaced_stepping_state (inferior *inf)
static int
displaced_step_in_progress_any_inferior (void)
{
- struct displaced_step_inferior_state *state;
-
- for (state = displaced_step_inferior_states;
- state != NULL;
- state = state->next)
- if (state->step_thread != nullptr)
+ for (displaced_step_inferior_state &state : displaced_step_inferior_states)
+ if (state.step_thread != nullptr)
return 1;
return 0;
@@ -1587,20 +1577,13 @@ displaced_step_in_progress (inferior *inf)
static struct displaced_step_inferior_state *
add_displaced_stepping_state (inferior *inf)
{
- struct displaced_step_inferior_state *state;
+ for (displaced_step_inferior_state &state : displaced_step_inferior_states)
+ if (state.inf == inf)
+ return &state;
- for (state = displaced_step_inferior_states;
- state != NULL;
- state = state->next)
- if (state->inf == inf)
- return state;
+ displaced_step_inferior_states.push_front({inf});
- state = XCNEW (struct displaced_step_inferior_state);
- state->inf = inf;
- state->next = displaced_step_inferior_states;
- displaced_step_inferior_states = state;
-
- return state;
+ return &displaced_step_inferior_states.front();
}
/* If inferior is in displaced stepping, and ADDR equals to starting address
@@ -1627,24 +1610,14 @@ get_displaced_step_closure_by_addr (CORE_ADDR addr)
static void
remove_displaced_stepping_state (inferior *inf)
{
- struct displaced_step_inferior_state *it, **prev_next_p;
-
gdb_assert (inf != nullptr);
- it = displaced_step_inferior_states;
- prev_next_p = &displaced_step_inferior_states;
- while (it)
- {
- if (it->inf == inf)
- {
- *prev_next_p = it->next;
- xfree (it);
- return;
- }
-
- prev_next_p = &it->next;
- it = *prev_next_p;
- }
+ for (auto I = displaced_step_inferior_states.begin(), E = displaced_step_inferior_states.end(); I != E; ) {
+ if (I->inf == inf)
+ I = displaced_step_inferior_states.erase(I);
+ else
+ ++I;
+ }
}
static void