+/* Information passed between the "maintenance info sections" command, and
+ the worker function that prints each section. */
+struct maint_print_section_data
+{
+ /* The GDB objfile we're printing this section for. */
+ struct objfile *objfile;
+
+ /* The argument string passed by the user to the top level maintenance
+ info sections command. Used for filtering which sections are
+ printed. */
+ const char *arg;
+
+ /* The number of digits in the highest section index for all sections
+ from the bfd object associated with OBJFILE. Used when pretty
+ printing the index number to ensure all of the indexes line up. */
+ int index_digits;
+
+ /* Constructor. */
+ maint_print_section_data (struct objfile *objfile, const char *arg,
+ bfd *abfd)
+ : objfile (objfile),
+ arg(arg)
+ {
+ int section_count = gdb_bfd_count_sections (abfd);
+ index_digits = ((int) log10 ((float) section_count)) + 1;
+ }
+
+private:
+ maint_print_section_data () = delete;
+ maint_print_section_data (const maint_print_section_data &) = delete;
+};
+
+/* Helper function to pretty-print the section index of ASECT from ABFD.
+ The INDEX_DIGITS is the number of digits in the largest index that will
+ be printed, and is used to pretty-print the resulting string. */
+
+static void
+print_section_index (bfd *abfd,
+ asection *asect,
+ int index_digits)
+{
+ std::string result
+ = string_printf (" [%d] ", gdb_bfd_section_index (abfd, asect));
+ /* The '+ 4' for the leading and trailing characters. */
+ printf_filtered ("%-*s", (index_digits + 4), result.c_str ());
+}
+
+/* Print information about ASECT from ABFD. DATUM holds a pointer to a
+ maint_print_section_data object. The section will be printed using the
+ VMA's from the bfd, which will not be the relocated addresses for bfds
+ that should be relocated. The information must be printed with the
+ same layout as PRINT_OBJFILE_SECTION_INFO below. */
+