aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbarch.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-08-09 21:47:02 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-08-12 15:20:26 -0400
commit9b1f59fc95da32963f3ba22f8587ea0c12899e05 (patch)
tree27ece8ea76f043dec5c489e0055047c068144df7 /gdb/gdbarch.c
parent65f82b1972cca3476b3ef6abf1d9923d34f5d4f5 (diff)
downloadgdb-9b1f59fc95da32963f3ba22f8587ea0c12899e05.zip
gdb-9b1f59fc95da32963f3ba22f8587ea0c12899e05.tar.gz
gdb-9b1f59fc95da32963f3ba22f8587ea0c12899e05.tar.bz2
gdb: make gdbarch_printable_names return a vector
I noticed that gdbarch_selftest::operator() leaked the value returned by gdbarch_printable_names. Make gdbarch_printable_names return an std::vector and update callers. That makes it easier for everyone involved, less manual memory management. Change-Id: Ia8fc028bdb91f787410cca34f10bf3c5a6da1498
Diffstat (limited to 'gdb/gdbarch.c')
-rw-r--r--gdb/gdbarch.c30
1 files changed, 10 insertions, 20 deletions
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 830a86d..f89dcc5 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -5549,40 +5549,30 @@ struct gdbarch_registration
static struct gdbarch_registration *gdbarch_registry = NULL;
-static void
-append_name (const char ***buf, int *nr, const char *name)
-{
- *buf = XRESIZEVEC (const char *, *buf, *nr + 1);
- (*buf)[*nr] = name;
- *nr += 1;
-}
-
-const char **
-gdbarch_printable_names (void)
+std::vector<const char *>
+gdbarch_printable_names ()
{
/* Accumulate a list of names based on the registed list of
architectures. */
- int nr_arches = 0;
- const char **arches = NULL;
- struct gdbarch_registration *rego;
+ std::vector<const char *> arches;
- for (rego = gdbarch_registry;
- rego != NULL;
+ for (gdbarch_registration *rego = gdbarch_registry;
+ rego != nullptr;
rego = rego->next)
{
- const struct bfd_arch_info *ap;
- ap = bfd_lookup_arch (rego->bfd_architecture, 0);
- if (ap == NULL)
+ const struct bfd_arch_info *ap
+ = bfd_lookup_arch (rego->bfd_architecture, 0);
+ if (ap == nullptr)
internal_error (__FILE__, __LINE__,
_("gdbarch_architecture_names: multi-arch unknown"));
do
{
- append_name (&arches, &nr_arches, ap->printable_name);
+ arches.push_back (ap->printable_name);
ap = ap->next;
}
while (ap != NULL);
}
- append_name (&arches, &nr_arches, NULL);
+
return arches;
}