static enum bfd_endian default_byte_order = BFD_ENDIAN_UNKNOWN;
+/* Printable names of architectures. Used as the enum list of the
+ "set arch" command. */
+static std::vector<const char *> arches;
+
void
initialize_current_architecture (void)
{
- const char **arches = gdbarch_printable_names ();
+ arches = gdbarch_printable_names ();
/* Find a default architecture. */
if (default_bfd_arch == NULL)
/* Choose the architecture by taking the first one
alphabetically. */
const char *chosen = arches[0];
- const char **arch;
- for (arch = arches; *arch != NULL; arch++)
+
+ for (const char *arch : arches)
{
- if (strcmp (*arch, chosen) < 0)
- chosen = *arch;
+ if (strcmp (arch, chosen) < 0)
+ chosen = arch;
}
+
if (chosen == NULL)
internal_error (__FILE__, __LINE__,
_("initialize_current_architecture: No arch"));
+
default_bfd_arch = bfd_scan_arch (chosen);
if (default_bfd_arch == NULL)
internal_error (__FILE__, __LINE__,
list of architectures. */
{
/* Append ``auto''. */
- int nr;
- for (nr = 0; arches[nr] != NULL; nr++);
- arches = XRESIZEVEC (const char *, arches, nr + 2);
- arches[nr + 0] = "auto";
- arches[nr + 1] = NULL;
+ arches.push_back ("auto");
+ arches.push_back (nullptr);
set_show_commands architecture_cmds
= add_setshow_enum_cmd ("architecture", class_support,
- arches, &set_architecture_string,
+ arches.data (), &set_architecture_string,
_("Set architecture of target."),
_("Show architecture of target."), NULL,
set_architecture, show_architecture,
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;
}
gdbarch_dump_tdep_ftype *);
-/* Return a freshly allocated, NULL terminated, array of the valid
- architecture names. Since architectures are registered during the
- _initialize phase this function only returns useful information
- once initialization has been completed. */
+/* Return a vector of the valid architecture names. Since architectures are
+ registered during the _initialize phase this function only returns useful
+ information once initialization has been completed. */
-extern const char **gdbarch_printable_names (void);
+extern std::vector<const char *> gdbarch_printable_names ();
/* Helper function. Search the list of ARCHES for a GDBARCH that
gdbarch_dump_tdep_ftype *);
-/* Return a freshly allocated, NULL terminated, array of the valid
- architecture names. Since architectures are registered during the
- _initialize phase this function only returns useful information
- once initialization has been completed. */
+/* Return a vector of the valid architecture names. Since architectures are
+ registered during the _initialize phase this function only returns useful
+ information once initialization has been completed. */
-extern const char **gdbarch_printable_names (void);
+extern std::vector<const char *> gdbarch_printable_names ();
/* Helper function. Search the list of ARCHES for a GDBARCH that
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;
}
void operator() () const override
{
- const char **arches = gdbarch_printable_names ();
+ std::vector<const char *> arches = gdbarch_printable_names ();
bool pass = true;
- for (int i = 0; arches[i] != NULL; i++)
+ for (const char *arch : arches)
{
- if (strcmp ("fr300", arches[i]) == 0)
+ if (strcmp ("fr300", arch) == 0)
{
/* PR 20946 */
continue;
}
- else if (strcmp ("powerpc:EC603e", arches[i]) == 0
- || strcmp ("powerpc:e500mc", arches[i]) == 0
- || strcmp ("powerpc:e500mc64", arches[i]) == 0
- || strcmp ("powerpc:titan", arches[i]) == 0
- || strcmp ("powerpc:vle", arches[i]) == 0
- || strcmp ("powerpc:e5500", arches[i]) == 0
- || strcmp ("powerpc:e6500", arches[i]) == 0)
+ else if (strcmp ("powerpc:EC603e", arch) == 0
+ || strcmp ("powerpc:e500mc", arch) == 0
+ || strcmp ("powerpc:e500mc64", arch) == 0
+ || strcmp ("powerpc:titan", arch) == 0
+ || strcmp ("powerpc:vle", arch) == 0
+ || strcmp ("powerpc:e5500", arch) == 0
+ || strcmp ("powerpc:e6500", arch) == 0)
{
/* PR 19797 */
continue;
{
struct gdbarch_info info;
- info.bfd_arch_info = bfd_scan_arch (arches[i]);
+ info.bfd_arch_info = bfd_scan_arch (arch);
struct gdbarch *gdbarch = gdbarch_find_by_info (info);
SELF_CHECK (gdbarch != NULL);
{
pass = false;
exception_fprintf (gdb_stderr, ex,
- _("Self test failed: arch %s: "), arches[i]);
+ _("Self test failed: arch %s: "), arch);
}
reset ();