gdb: store interps in an intrusive_list

Use intrusive_list, instead of hand-made linked list.

Change-Id: Idc857b40dfa3e3c35671045898331cca2c928097
This commit is contained in:
Simon Marchi
2023-04-28 14:27:12 -04:00
parent 13d03262f2
commit 4a91f820ef
2 changed files with 9 additions and 17 deletions

View File

@@ -49,7 +49,7 @@ struct ui_interp_info
DISABLE_COPY_AND_ASSIGN (ui_interp_info);
/* Each top level has its own independent set of interpreters. */
interp *interp_list = nullptr;
intrusive_list<interp> interp_list;
interp *current_interpreter = nullptr;
interp *top_level_interpreter = nullptr;
@@ -132,8 +132,7 @@ interp_add (struct ui *ui, struct interp *interp)
gdb_assert (interp_lookup_existing (ui, interp->name ()) == NULL);
interp->next = ui_interp.interp_list;
ui_interp.interp_list = interp;
ui_interp.interp_list.push_back (*interp);
}
/* This sets the current interpreter to be INTERP. If INTERP has not
@@ -204,17 +203,12 @@ static struct interp *
interp_lookup_existing (struct ui *ui, const char *name)
{
ui_interp_info &ui_interp = get_interp_info (ui);
struct interp *interp;
for (interp = ui_interp.interp_list;
interp != NULL;
interp = interp->next)
{
if (strcmp (interp->name (), name) == 0)
return interp;
}
for (interp &interp : ui_interp.interp_list)
if (strcmp (interp.name (), name) == 0)
return &interp;
return NULL;
return nullptr;
}
/* See interps.h. */

View File

@@ -22,6 +22,8 @@
#ifndef INTERPS_H
#define INTERPS_H
#include "gdbsupport/intrusive_list.h"
struct ui_out;
struct interp;
struct ui;
@@ -40,7 +42,7 @@ extern void interp_factory_register (const char *name,
extern void interp_exec (struct interp *interp, const char *command);
class interp
class interp : public intrusive_list_node<interp>
{
public:
explicit interp (const char *name);
@@ -85,10 +87,6 @@ private:
const char *m_name;
public:
/* Interpreters are stored in a linked list, this is the next
one... */
interp *next = nullptr;
/* Has the init method been run? */
bool inited = false;
};