diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2021-08-09 21:47:02 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2021-08-12 15:20:26 -0400 |
commit | 9b1f59fc95da32963f3ba22f8587ea0c12899e05 (patch) | |
tree | 27ece8ea76f043dec5c489e0055047c068144df7 /gdb/arch-utils.c | |
parent | 65f82b1972cca3476b3ef6abf1d9923d34f5d4f5 (diff) | |
download | binutils-gdb-9b1f59fc95da32963f3ba22f8587ea0c12899e05.tar.gz |
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/arch-utils.c')
-rw-r--r-- | gdb/arch-utils.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 4290d637ce1..862f26b6cf7 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -669,10 +669,14 @@ static const bfd_target *default_bfd_vec; 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) @@ -680,15 +684,17 @@ initialize_current_architecture (void) /* 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__, @@ -743,14 +749,11 @@ initialize_current_architecture (void) 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, |