+ for (asection *sect : gdb_bfd_sections (abfd))
+ {
+ obj_section *osect = nullptr;
+
+ if (objfile != nullptr)
+ {
+ gdb_assert (objfile->sections != nullptr);
+ osect
+ = maint_obj_section_from_bfd_section (abfd, sect, objfile);
+ if (osect->the_bfd_section == nullptr)
+ osect = nullptr;
+ }
+
+ if (osect == nullptr)
+ print_bfd_section_info (abfd, sect, arg, digits);
+ else
+ print_objfile_section_info (abfd, osect, arg, digits);
+ }
+}
+
+/* The options for the "maintenance info sections" command. */
+
+struct maint_info_sections_opts
+{
+ /* For "-all-objects". */
+ bool all_objects = false;
+};
+
+static const gdb::option::option_def maint_info_sections_option_defs[] = {
+
+ gdb::option::flag_option_def<maint_info_sections_opts> {
+ "all-objects",
+ [] (maint_info_sections_opts *opts) { return &opts->all_objects; },
+ N_("Display information from all loaded object files."),
+ },
+};
+
+/* Create an option_def_group for the "maintenance info sections" options,
+ with CC_OPTS as context. */
+
+static inline gdb::option::option_def_group
+make_maint_info_sections_options_def_group (maint_info_sections_opts *cc_opts)
+{
+ return {{maint_info_sections_option_defs}, cc_opts};
+}
+
+/* Completion for the "maintenance info sections" command. */
+
+static void
+maint_info_sections_completer (struct cmd_list_element *cmd,
+ completion_tracker &tracker,
+ const char *text, const char * /* word */)
+{
+ /* Complete command options. */
+ const auto group = make_maint_info_sections_options_def_group (nullptr);
+ if (gdb::option::complete_options
+ (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group))
+ return;
+ const char *word = advance_to_expression_complete_word_point (tracker, text);
+
+ /* Offer completion for section flags, but not section names. This is
+ only a maintenance command after all, no point going over the top. */
+ std::vector<const char *> flags;
+ for (const auto &f : bfd_flag_info)
+ flags.push_back (f.name);
+ flags.push_back (nullptr);
+ complete_on_enum (tracker, flags.data (), text, word);