This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch/rfc] Simplify local_hex_string_custom() et.al.


Hello,

The attached patch rationalises:

	local_hex_string(long )
	local_hex_string_custom(long)
	longest_local_hex_string(longest)
	longest_local_hex_string_custom(longest)

The long/LONGEST variants are merged.  The function that does all the 
work (local_hex_string_custom() nee longest_local_hex_string_custom()) 
is stripped of the convoluted #if CC_HAS_LONG_LONG and 
PRINTF_HAS_LONG_LONG cases and instead always does the conversion the 
hard way.

I figure that at least this way once a bug is fixed it is fixed for all 
platforms.

Thoughts?  I'll look to be committing this in ~a week.

There are, I think, several good follow-on patches:

	local_address_string{,_custom}()
		to handle the address case
		Get rid of all those if (TARGET_ADDR_BIT) ... else ...

	local_{decimal,octal}_string{,_custom}()
		so that print_longest() can receive
		similar treatment (and always work)

	(more tricky) make it possible to print 128 bit numbers.

enjoy,
Andrew
2002-05-04  Andrew Cagney  <ac131313@redhat.com>

	* language.c (local_hex_string_custom): Simplify.  Do not depend
	on PRINTF_HAS_LONG_LONG or CC_HAS_LONG_LONG.

	* memattr.c (mem_info_command): Replace calls to
	longest_local_hex_string and longest_local_hex_string_custom.
	* buildsym.c (make_blockvector): Ditto.
	* solib.c (info_sharedlibrary_command): Ditto.
	* tracepoint.c (tracepoints_info): Ditto.
	* symtab.c (print_msymbol_info): Ditto.

	* language.c (local_hex_string): Delete.
	(local_hex_string_custom): Delete.
	(longest_local_hex_string): Rename to local_hex_string.
	(longest_local_hex_string_custom): Rename to
	local_hex_string_custom.
	* language.h (local_hex_string): Change parameter type to LONGEST.
	(local_hex_string_custom): Ditto.
	(longest_local_hex_string): Delete declaration.
	(longest_local_hex_string_custom): Ditto.

	* solib.c: Update copyright.
	* memattr.c: Update copyright.
	
Index: buildsym.c
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.c,v
retrieving revision 1.14
diff -u -r1.14 buildsym.c
--- buildsym.c	20 Jan 2002 19:42:04 -0000	1.14
+++ buildsym.c	4 May 2002 22:02:54 -0000
@@ -36,7 +36,7 @@
 #include "complaints.h"
 #include "gdb_string.h"
 #include "expression.h"		/* For "enum exp_opcode" used by... */
-#include "language.h"		/* For "longest_local_hex_string_custom" */
+#include "language.h"		/* For "local_hex_string" */
 #include "bcache.h"
 #include "filenames.h"		/* For DOSish file names */
 /* Ask buildsym.h to define the vars it normally declares `extern'.  */
@@ -509,7 +509,7 @@
 		= BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
 
 	      complain (&blockvector_complaint,
-			longest_local_hex_string ((LONGEST) start));
+			local_hex_string ((LONGEST) start));
 	    }
 	}
     }
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.23
diff -u -r1.23 language.c
--- language.c	28 Mar 2002 01:35:55 -0000	1.23
+++ language.c	4 May 2002 22:02:55 -0000
@@ -595,34 +595,12 @@
   return form;
 }
 
-/* Converts a number to hexadecimal and stores it in a static
+/* Converts a LONGEST to custom hexadecimal and stores it in a static
    string.  Returns a pointer to this string. */
 char *
-local_hex_string (unsigned long num)
+local_hex_string (LONGEST num)
 {
-  static char res[50];
-
-  sprintf (res, local_hex_format (), num);
-  return res;
-}
-
-/* Converts a LONGEST number to hexadecimal and stores it in a static
-   string.  Returns a pointer to this string. */
-char *
-longest_local_hex_string (LONGEST num)
-{
-  return longest_local_hex_string_custom (num, "l");
-}
-
-/* Converts a number to custom hexadecimal and stores it in a static
-   string.  Returns a pointer to this string. */
-char *
-local_hex_string_custom (unsigned long num, char *pre)
-{
-  static char res[50];
-
-  sprintf (res, local_hex_format_custom (pre), num);
-  return res;
+  return local_hex_string_custom (num, "l");
 }
 
 /* Converts a LONGEST number to custom hexadecimal and stores it in a static
@@ -630,12 +608,11 @@
    should end with "l", e.g. "08l" as with calls to local_hex_string_custom */
 
 char *
-longest_local_hex_string_custom (LONGEST num, char *width)
+local_hex_string_custom (LONGEST num, char *width)
 {
 #define RESULT_BUF_LEN 50
   static char res2[RESULT_BUF_LEN];
   char format[RESULT_BUF_LEN];
-#if !defined (PRINTF_HAS_LONG_LONG)
   int field_width;
   int num_len;
   int num_pad_chars;
@@ -643,24 +620,7 @@
   int pad_on_left;
   char *parse_ptr;
   char temp_nbr_buf[RESULT_BUF_LEN];
-#endif
 
-#ifndef CC_HAS_LONG_LONG
-  /* If there is no long long, then LONGEST should be just long and we
-     can use local_hex_string_custom 
-   */
-  return local_hex_string_custom ((unsigned long) num, width);
-#elif defined (PRINTF_HAS_LONG_LONG)
-  /* Just use printf.  */
-  strcpy (format, local_hex_format_prefix ());	/* 0x */
-  strcat (format, "%");
-  strcat (format, width);	/* e.g. "08l" */
-  strcat (format, "l");		/* need "ll" for long long */
-  strcat (format, local_hex_format_specifier ());	/* "x" */
-  strcat (format, local_hex_format_suffix ());	/* "" */
-  sprintf (res2, format, num);
-  return res2;
-#else /* !defined (PRINTF_HAS_LONG_LONG) */
   /* Use phex_nz to print the number into a string, then
      build the result string from local_hex_format_prefix, padding and 
      the hex representation as indicated by "width".  */
@@ -687,7 +647,7 @@
   if (strlen (local_hex_format_prefix ()) + num_len + num_pad_chars
       >= RESULT_BUF_LEN)		/* paranoia */
     internal_error (__FILE__, __LINE__,
-		    "longest_local_hex_string_custom: insufficient space to store result");
+		    "local_hex_string_custom: insufficient space to store result");
 
   strcpy (res2, local_hex_format_prefix ());
   if (pad_on_left)
@@ -708,9 +668,8 @@
 	}
     }
   return res2;
-#endif
 
-}				/* longest_local_hex_string_custom */
+}				/* local_hex_string_custom */
 
 /* Returns the appropriate printf format for octal
    numbers. */
Index: language.h
===================================================================
RCS file: /cvs/src/src/gdb/language.h,v
retrieving revision 1.9
diff -u -r1.9 language.h
--- language.h	2 Feb 2002 02:28:40 -0000	1.9
+++ language.h	4 May 2002 22:02:55 -0000
@@ -395,13 +395,9 @@
    (language-specific) formats.  Result is static and is overwritten by
    the next call.  Takes printf options like "08l" or "l".  */
 
-extern char *local_hex_string (unsigned long);	/* language.c */
+extern char *local_hex_string (LONGEST);	/* language.c */
 
-extern char *longest_local_hex_string (LONGEST);	/* language.c */
-
-extern char *local_hex_string_custom (unsigned long, char *);	/* language.c */
-
-extern char *longest_local_hex_string_custom (LONGEST, char *);	/* language.c */
+extern char *local_hex_string_custom (LONGEST, char *);	/* language.c */
 
 /* Type predicates */
 
Index: memattr.c
===================================================================
RCS file: /cvs/src/src/gdb/memattr.c,v
retrieving revision 1.10
diff -u -r1.10 memattr.c
--- memattr.c	27 Feb 2002 01:40:35 -0000	1.10
+++ memattr.c	4 May 2002 22:02:55 -0000
@@ -1,5 +1,6 @@
 /* Memory attributes support, for GDB.
-   Copyright 2001 Free Software Foundation, Inc.
+
+   Copyright 2001, 2002 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -238,16 +239,16 @@
 		       m->number,
 		       m->enabled_p ? 'y' : 'n');
       if (TARGET_ADDR_BIT <= 32)
-	tmp = longest_local_hex_string_custom ((unsigned long) m->lo, "08l");
+	tmp = local_hex_string_custom ((unsigned long) m->lo, "08l");
       else
-	tmp = longest_local_hex_string_custom ((unsigned long) m->lo, "016l");
+	tmp = local_hex_string_custom ((unsigned long) m->lo, "016l");
       
       printf_filtered ("%s ", tmp);
       
       if (TARGET_ADDR_BIT <= 32)
-	tmp = longest_local_hex_string_custom ((unsigned long) m->hi, "08l");
+	tmp = local_hex_string_custom ((unsigned long) m->hi, "08l");
       else
-	tmp = longest_local_hex_string_custom ((unsigned long) m->hi, "016l");
+	tmp = local_hex_string_custom ((unsigned long) m->hi, "016l");
       
       printf_filtered ("%s ", tmp);
 
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.49
diff -u -r1.49 solib.c
--- solib.c	6 Mar 2002 06:28:33 -0000	1.49
+++ solib.c	4 May 2002 22:02:56 -0000
@@ -1,7 +1,7 @@
 /* Handle shared libraries for GDB, the GNU Debugger.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001
-   Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -652,13 +652,13 @@
 
 	  printf_unfiltered ("%-*s", addr_width,
 			     so->textsection != NULL 
-			       ? longest_local_hex_string_custom (
+			       ? local_hex_string_custom (
 			           (LONGEST) so->textsection->addr,
 	                           addr_fmt)
 			       : "");
 	  printf_unfiltered ("%-*s", addr_width,
 			     so->textsection != NULL 
-			       ? longest_local_hex_string_custom (
+			       ? local_hex_string_custom (
 			           (LONGEST) so->textsection->endaddr,
 	                           addr_fmt)
 			       : "");
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.62
diff -u -r1.62 symtab.c
--- symtab.c	6 Apr 2002 18:28:20 -0000	1.62
+++ symtab.c	4 May 2002 22:03:06 -0000
@@ -2961,12 +2961,12 @@
   char *tmp;
 
   if (TARGET_ADDR_BIT <= 32)
-    tmp = longest_local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol)
-					   & (CORE_ADDR) 0xffffffff,
-					   "08l");
+    tmp = local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol)
+				   & (CORE_ADDR) 0xffffffff,
+				   "08l");
   else
-    tmp = longest_local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol),
-					   "016l");
+    tmp = local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol),
+				   "016l");
   printf_filtered ("%s  %s\n",
 		   tmp, SYMBOL_SOURCE_NAME (msymbol));
 }
Index: tracepoint.c
===================================================================
RCS file: /cvs/src/src/gdb/tracepoint.c,v
retrieving revision 1.37
diff -u -r1.37 tracepoint.c
--- tracepoint.c	21 Apr 2002 20:23:33 -0000	1.37
+++ tracepoint.c	4 May 2002 22:03:26 -0000
@@ -502,11 +502,11 @@
 	  char *tmp;
 
 	  if (TARGET_ADDR_BIT <= 32)
-	    tmp = longest_local_hex_string_custom (t->address
-						   & (CORE_ADDR) 0xffffffff, 
-						   "08l");
+	    tmp = local_hex_string_custom (t->address
+					   & (CORE_ADDR) 0xffffffff, 
+					   "08l");
 	  else
-	    tmp = longest_local_hex_string_custom (t->address, "016l");
+	    tmp = local_hex_string_custom (t->address, "016l");
 
 	  printf_filtered ("%s ", tmp);
 	}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]