aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2020-09-02 14:36:50 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2020-09-02 14:36:50 -0400
commitc5065df0439783d9ce7436bc855d18fd0c9e0b0b (patch)
treead7ebd5f6121a7aa22295b3364acb247fb7ea3bf
parent02c6f3f1fc2af7ad02bc649f0adfb479bf163441 (diff)
downloadgdb-c5065df0439783d9ce7436bc855d18fd0c9e0b0b.zip
gdb-c5065df0439783d9ce7436bc855d18fd0c9e0b0b.tar.gz
gdb-c5065df0439783d9ce7436bc855d18fd0c9e0b0b.tar.bz2
gdb: remove maint_print_section_data
Since the "maintenance info sections" helper functions are not used through a callback with a void* parameter anymore, the maint_print_section_data is not needed anymore. Remove it, replace it with regular parameters. Break out the index digits computation in its own function. gdb/ChangeLog: * maint.c (index_digits): New function. (struct maint_print_section_data): Remove. (print_bfd_section_info): Remove print_data parameter, add arg and index_digits. (print_objfile_section_info): Likewise. (print_bfd_section_info_maybe_relocated): Likewise (plus objfile). (maintenance_info_sections): Adjust calls. Change-Id: Idfeca5e7e0a95e72fade15cb1488058865c0258e
-rw-r--r--gdb/ChangeLog11
-rw-r--r--gdb/maint.c101
2 files changed, 53 insertions, 59 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8ace83b..1ac7454 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,14 @@
+2020-09-02 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * maint.c (index_digits): New function.
+ (struct maint_print_section_data): Remove.
+ (print_bfd_section_info): Remove print_data parameter, add arg
+ and index_digits.
+ (print_objfile_section_info): Likewise.
+ (print_bfd_section_info_maybe_relocated): Likewise (plus
+ objfile).
+ (maintenance_info_sections): Adjust calls.
+
2020-09-02 Tom Tromey <tromey@adacore.com>
* ada-varobj.c (ada_varobj_get_ptr_number_of_children): Return 0
diff --git a/gdb/maint.c b/gdb/maint.c
index be0b160..46dd99f 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -245,37 +245,16 @@ maint_print_section_info (const char *name, flagword flags,
printf_filtered ("\n");
}
-/* Information passed between the "maintenance info sections" command, and
- the worker function that prints each section. */
-struct maint_print_section_data
+/* Return the number of digits required to display COUNT in decimal.
+
+ Used when pretty printing index numbers to ensure all of the indexes line
+ up.*/
+
+static int
+index_digits (int count)
{
- /* 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;
-};
+ return ((int) log10 ((float) count)) + 1;
+}
/* 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
@@ -295,16 +274,17 @@ print_section_index (bfd *abfd,
/* Print information about ASECT from ABFD. 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. */
+ layout as PRINT_OBJFILE_SECTION_INFO below.
+
+ ARG is the argument string passed by the user to the top level maintenance
+ info sections command. Used for filtering which sections are printed. */
static void
-print_bfd_section_info (bfd *abfd,
- asection *asect,
- const maint_print_section_data &print_data)
+print_bfd_section_info (bfd *abfd, asection *asect, const char *arg,
+ int index_digits)
{
flagword flags = bfd_section_flags (asect);
const char *name = bfd_section_name (asect);
- const char *arg = print_data.arg;
if (arg == NULL || *arg == '\0'
|| match_substring (arg, name)
@@ -316,7 +296,7 @@ print_bfd_section_info (bfd *abfd,
addr = bfd_section_vma (asect);
endaddr = addr + bfd_section_size (asect);
- print_section_index (abfd, asect, print_data.index_digits);
+ print_section_index (abfd, asect, index_digits);
maint_print_section_info (name, flags, addr, endaddr,
asect->filepos, addr_size);
}
@@ -325,26 +305,26 @@ print_bfd_section_info (bfd *abfd,
/* Print information about ASECT which is GDB's wrapper around a section
from ABFD. The information must be printed with the same layout as
PRINT_BFD_SECTION_INFO above. PRINT_DATA holds information used to
- filter which sections are printed, and for formatting the output. */
+ filter which sections are printed, and for formatting the output.
+
+ ARG is the argument string passed by the user to the top level maintenance
+ info sections command. Used for filtering which sections are printed. */
static void
-print_objfile_section_info (bfd *abfd,
- struct obj_section *asect,
- const maint_print_section_data &print_data)
+print_objfile_section_info (bfd *abfd, struct obj_section *asect,
+ const char *arg, int index_digits)
{
flagword flags = bfd_section_flags (asect->the_bfd_section);
const char *name = bfd_section_name (asect->the_bfd_section);
- const char *string = print_data.arg;
- if (string == NULL || *string == '\0'
- || match_substring (string, name)
- || match_bfd_flags (string, flags))
+ if (arg == NULL || *arg == '\0'
+ || match_substring (arg, name)
+ || match_bfd_flags (arg, flags))
{
struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
int addr_size = gdbarch_addr_bit (gdbarch) / 8;
- print_section_index (abfd, asect->the_bfd_section,
- print_data.index_digits);
+ print_section_index (abfd, asect->the_bfd_section, index_digits);
maint_print_section_info (name, flags,
obj_section_addr (asect),
obj_section_endaddr (asect),
@@ -375,22 +355,24 @@ maint_obj_section_from_bfd_section (bfd *abfd,
}
/* Print information about ASECT from ABFD. Where possible the information for
- ASECT will print the relocated addresses of the section. */
+ ASECT will print the relocated addresses of the section.
+
+ ARG is the argument string passed by the user to the top level maintenance
+ info sections command. Used for filtering which sections are printed. */
static void
-print_bfd_section_info_maybe_relocated
- (bfd *abfd, asection *asect, const maint_print_section_data &print_data)
+print_bfd_section_info_maybe_relocated (bfd *abfd, asection *asect,
+ objfile *objfile, const char *arg,
+ int index_digits)
{
- objfile *objfile = print_data.objfile;
-
gdb_assert (objfile->sections != NULL);
obj_section *osect
= maint_obj_section_from_bfd_section (abfd, asect, objfile);
if (osect->the_bfd_section == NULL)
- print_bfd_section_info (abfd, asect, print_data);
+ print_bfd_section_info (abfd, asect, arg, index_digits);
else
- print_objfile_section_info (abfd, osect, print_data);
+ print_objfile_section_info (abfd, osect, arg, index_digits);
}
/* Implement the "maintenance info sections" command. */
@@ -425,25 +407,26 @@ maintenance_info_sections (const char *arg, int from_tty)
else if (ofile->obfd != exec_bfd)
continue;
- maint_print_section_data print_data (ofile, arg, ofile->obfd);
+ int section_count = gdb_bfd_count_sections (ofile->obfd);
for (asection *sect : gdb_bfd_sections (ofile->obfd))
- print_bfd_section_info_maybe_relocated (ofile->obfd, sect,
- print_data);
+ print_bfd_section_info_maybe_relocated
+ (ofile->obfd, sect, ofile, arg, index_digits (section_count));
}
}
if (core_bfd)
{
- maint_print_section_data print_data (nullptr, arg, core_bfd);
-
printf_filtered (_("Core file:\n"));
printf_filtered (" `%s', ", bfd_get_filename (core_bfd));
wrap_here (" ");
printf_filtered (_("file type %s.\n"), bfd_get_target (core_bfd));
+ int section_count = gdb_bfd_count_sections (core_bfd);
+
for (asection *sect : gdb_bfd_sections (core_bfd))
- print_bfd_section_info (core_bfd, sect, print_data);
+ print_bfd_section_info (core_bfd, sect, arg,
+ index_digits (section_count));
}
}