[PATCH] gdbsupport: move index_digits function here

Simon Marchi simon.marchi@polymtl.ca
Wed Sep 2 19:20:30 GMT 2020


Move the index_digits function, currently defined in gdb/maint.c, to
gdbsupport/print-utils.h.  Use it for gdb/tui/tui-source.c.

gdb/ChangeLog:

	* maint.c (index_digits): Move to gdbsupport.
	* tui/tui-source.c (tui_source_window::set_contents): Use
	index_digits.

gdbsupport/ChangeLog:

	* print-utils.h (index_digits): Move here from gdb.

Change-Id: I26a1b6a8c2aec11c3bd1c65a67f8d7f8955ac5e9
---
 gdb/maint.c              | 11 -----------
 gdb/tui/tui-source.c     |  7 +------
 gdbsupport/print-utils.h | 13 +++++++++++++
 3 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/gdb/maint.c b/gdb/maint.c
index 46dd99f6ccf6..dab0235e891e 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -245,17 +245,6 @@ maint_print_section_info (const char *name, flagword flags,
   printf_filtered ("\n");
 }
 
-/* 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)
-{
-  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
    be printed, and is used to pretty-print the resulting string.  */
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index fd5bd7dd9608..999a5fff7ff8 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -80,12 +80,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
 
   int digits = 0;
   if (compact_source)
-    {
-      /* Solaris 11+gcc 5.5 has ambiguous overloads of log10, so we
-	 cast to double to get the right one.  */
-      double l = log10 ((double) offsets->size ());
-      digits = 1 + (int) l;
-    }
+    digits = index_digits (offsets->size ());
 
   const char *iter = srclines.c_str ();
   m_content.resize (nlines);
diff --git a/gdbsupport/print-utils.h b/gdbsupport/print-utils.h
index 7541791489d8..262fbaf87186 100644
--- a/gdbsupport/print-utils.h
+++ b/gdbsupport/print-utils.h
@@ -20,6 +20,8 @@
 #ifndef COMMON_PRINT_UTILS_H
 #define COMMON_PRINT_UTILS_H
 
+#include <math.h>
+
 /* How many characters (including the terminating null byte) fit in a
    cell.  */
 #define PRINT_CELL_SIZE 50
@@ -82,4 +84,15 @@ extern const char *host_address_to_string_1 (const void *addr);
 
 extern char *get_print_cell (void);
 
+/* 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 inline int
+index_digits (int count)
+{
+  return ((int) log10 ((float) count)) + 1;
+}
+
 #endif /* COMMON_PRINT_UTILS_H */
-- 
2.28.0



More information about the Gdb-patches mailing list