Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] printf support for DFP values
@ 2007-10-27  6:25 Luis Machado
  2007-10-27 12:05 ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Luis Machado @ 2007-10-27  6:25 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1167 bytes --]

Hi folks,

Libdecnumber has been already integrated into GDB, but there are still
some missing features that must be addressed for DFP types.

GDB's printf command currently does not support printing of DFP values
(Decimal32, Decimal64 and Decimal128). The following patch proposes to
fix that by allowing GDB's printf command to deal with those numbers.

Native DFP printing support with printf is not yet ready, but it should
be in some time eventually. Due to this, i'm testing for native printf
support for DFP in the configure script and setting a constant to
reflect the result (PRINTF_HAS_DECFLOAT). Based on that GDB has two ways
of dealing with the problem:

1 - If we have native support (and thus PRINTF_HAS_DECFLOAT is set), we
just send the DFP value straight to the standard printing routine with
its format specifiers (printf_filtered).

2 - If there's currently no support, we stick with converting the DFP
values to strings and using string format specifiers to print them. This
should make things flexible enough for both systems, one that has native
printf support for DFP and one that doesn't.

I'd appreciate comments on this one.

Regards,
Luis

[-- Attachment #2: printf-dfp.diff --]
[-- Type: text/x-patch, Size: 7166 bytes --]

2007-10-26  Luis Machado  <luisgpm@br.ibm.com>

  * printcmd.c: (printf_command): Add new DFP modifiers %H, %D and
    %DD.
  * configure.ac: Add check for DECFLOAT printf support.
  * configure: Regenerated.

Index: git/gdb/printcmd.c
===================================================================
--- git.orig/gdb/printcmd.c	2007-10-26 17:43:36.000000000 -0700
+++ git/gdb/printcmd.c	2007-10-26 17:58:07.000000000 -0700
@@ -41,6 +41,7 @@
 #include "gdb_assert.h"
 #include "block.h"
 #include "disasm.h"
+#include "dfp.h"
 
 #ifdef TUI
 #include "tui/tui.h"		/* For tui_active et.al.   */
@@ -1819,7 +1820,7 @@
     enum argclass
       {
 	int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
-	double_arg, long_double_arg
+	double_arg, long_double_arg, decfloat_arg
       };
     enum argclass *argclass;
     enum argclass this_argclass;
@@ -1928,6 +1929,31 @@
 		bad = 1;
 	      break;
 
+	    /* DFP Decimal32 types.  */
+	    case 'H':
+	      this_argclass = decfloat_arg;
+
+              if (lcount || seen_h || seen_big_l)
+                bad = 1;
+              if (seen_prec || seen_zero || seen_space || seen_plus)
+                bad = 1;
+	      break;
+
+	    /* DFP Decimal64 and Decimal128 types.  */
+	    case 'D':
+	      this_argclass = decfloat_arg;
+
+              if (lcount || seen_h || seen_big_l)
+                bad = 1;
+              if (seen_prec || seen_zero || seen_space || seen_plus)
+                bad = 1;
+
+	      if (*(++f) == 'D')
+		printf_unfiltered("\nDecimal 128\n");
+	      else
+		printf_unfiltered("\nDecimal 64\n");
+	      break;
+
 	    case 'c':
 	      this_argclass = int_arg;
 	      if (lcount || seen_h || seen_big_l)
@@ -2094,6 +2120,55 @@
 	      printf_filtered (current_substring, val);
 	      break;
 	    }
+
+	  /* Handles decimal floating point values.  */
+	  case decfloat_arg:
+	    {
+	      char *eos;
+	      char decstr[128];
+	      unsigned int dfp_len = TYPE_LENGTH (value_type (val_args[i]));
+	      uint8_t *dfp_value_ptr = (uint8_t *) value_contents_all (val_args[i])
+                                      + value_offset (val_args[i]);
+
+#if defined (PRINTF_HAS_DECFLOAT)
+	      printf_filtered(current_substring, dfp_value_ptr);
+#else
+	      if (TYPE_CODE (value_type (val_args[i])) != TYPE_CODE_DECFLOAT)
+		error (_("Cannot convert parameter to decfloat."));
+
+	      /* As a workaround until vasprintf has native support for DFP
+		 we convert the DFP values to string and print them using
+		 the %s format specifier.  */
+	      decimal_to_string (dfp_value_ptr, dfp_len, decstr);
+
+	      /* Points to the end of the string so that we can go back
+		 and check for DFP format specifiers.  */
+	      eos = current_substring + strlen(current_substring);
+
+	      /* Replace %H, %D and %DD for %s's.  */
+	      while(*--eos != '%')
+		if (*eos == 'D' && *(eos - 1) == 'D')
+		  {
+		    *(eos - 1) = 's';
+
+		    /* If we've found a %DD format specifier we need to go
+		       through the whole string pulling back one character
+		       since this format specifier has two chars.  */
+		    while (eos < last_arg)
+		      {
+			*eos = *(eos + 1);
+			eos++;
+		      }
+		  }
+		else if (*eos == 'D' || *eos == 'H')
+		  *eos = 's';
+
+	      /* Print the DFP value.  */
+	      printf_filtered(current_substring, decstr);
+	      break;
+#endif
+	    }
+
 	  case ptr_arg:
 	    {
 	      /* We avoid the host's %p because pointers are too
Index: git/gdb/configure.ac
===================================================================
--- git.orig/gdb/configure.ac	2007-10-26 17:43:36.000000000 -0700
+++ git/gdb/configure.ac	2007-10-26 17:52:25.000000000 -0700
@@ -927,6 +927,25 @@
             [Define to 1 if the "%ll" format works to print long longs.])
 fi
 
+# Check if the compiler and runtime support printing decfloats.
+
+AC_CACHE_CHECK([for decfloat support in printf],
+               gdb_cv_printf_has_decfloat,
+               [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
+[[char buf[64];
+  _Decimal32 d32 = 1.2345df;
+  _Decimal64 d64 = 1.2345dd;
+  _Decimal128 d128 = 1.2345dl;
+  sprintf (buf, "Decimal32: %H\nDecimal64: %D\nDecimal128: %DD", d32, d64, d128);
+  return (strcmp ("Decimal32: 1.2345\nDecimal64: 1.2345\nDecimal128: 1.2345", buf));]])],
+                              gdb_cv_printf_has_decfloat=yes,
+                              gdb_cv_printf_has_decfloat=no,
+                              gdb_cv_printf_has_decfloat=no)])
+if test $gdb_cv_printf_has_decfloat = yes; then
+  AC_DEFINE(PRINTF_HAS_DECFLOAT, 1,
+            [Define to 1 if the "%H, %D and %DD" formats work to print decfloats.])
+fi
+
 # Check if the compiler supports the `long double' type.  We can't use
 # AC_C_LONG_DOUBLE because that one does additional checks on the
 # constants defined in <float.h> that fail on some systems,
Index: git/gdb/configure
===================================================================
--- git.orig/gdb/configure	2007-10-26 17:43:36.000000000 -0700
+++ git/gdb/configure	2007-10-26 17:59:22.000000000 -0700
@@ -21132,6 +21132,69 @@
 
 fi
 
+# Check if the compiler and runtime support printing decfloats.
+
+echo "$as_me:$LINENO: checking for decfloat support in printf" >&5
+echo $ECHO_N "checking for decfloat support in printf... $ECHO_C" >&6
+if test "${gdb_cv_printf_has_decfloat+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  gdb_cv_printf_has_decfloat=no
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+char buf[64];
+  _Decimal32 d32 = 1.2345df;
+  _Decimal64 d64 = 1.2345dd;
+  _Decimal128 d128 = 1.2345dl;
+  sprintf (buf, "Decimal32: %H\nDecimal64: %D\nDecimal128: %DD", d32, d64, d128);
+  return (strcmp ("Decimal32: 1.2345\nDecimal64: 1.2345\nDecimal128: 1.2345", buf));
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  gdb_cv_printf_has_decfloat=yes
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+gdb_cv_printf_has_decfloat=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+echo "$as_me:$LINENO: result: $gdb_cv_printf_has_decfloat" >&5
+echo "${ECHO_T}$gdb_cv_printf_has_decfloat" >&6
+if test $gdb_cv_printf_has_decfloat = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define PRINTF_HAS_DECFLOAT 1
+_ACEOF
+
+fi
+
 # Check if the compiler supports the `long double' type.  We can't use
 # AC_C_LONG_DOUBLE because that one does additional checks on the
 # constants defined in <float.h> that fail on some systems,

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-10-27  6:25 [PATCH] printf support for DFP values Luis Machado
@ 2007-10-27 12:05 ` Eli Zaretskii
  2007-10-29 15:03   ` Luis Machado
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2007-10-27 12:05 UTC (permalink / raw)
  To: luisgpm; +Cc: gdb-patches

> From: Luis Machado <luisgpm@linux.vnet.ibm.com>
> Date: Fri, 26 Oct 2007 22:44:57 -0300
> 
> GDB's printf command currently does not support printing of DFP values
> (Decimal32, Decimal64 and Decimal128). The following patch proposes to
> fix that by allowing GDB's printf command to deal with those numbers.

Thanks.

> Native DFP printing support with printf is not yet ready, but it should
> be in some time eventually. Due to this, i'm testing for native printf
> support for DFP in the configure script and setting a constant to
> reflect the result (PRINTF_HAS_DECFLOAT). Based on that GDB has two ways
> of dealing with the problem:
> 
> 1 - If we have native support (and thus PRINTF_HAS_DECFLOAT is set), we
> just send the DFP value straight to the standard printing routine with
> its format specifiers (printf_filtered).
> 
> 2 - If there's currently no support, we stick with converting the DFP
> values to strings and using string format specifiers to print them. This
> should make things flexible enough for both systems, one that has native
> printf support for DFP and one that doesn't.
> 
> I'd appreciate comments on this one.

If we can implement DFP printing in GDB, why should we also check for
native DFP support and use that if available?  Are there any
advantages in the native DFP printing, and if so, what are they?

Also, if this patch is accepted, please submit also a suitable patch
for the manual (doc/gdb.texinfo), where we describe the format
conversions supported by the `printf' command (node "Output").

A few questions/comments to the patch itself:

> -	double_arg, long_double_arg
> +	double_arg, long_double_arg, decfloat_arg

You are using decfloat_arg unconditionally, but I don't see it defined
anywhere in today's CVS.  Am I missing something?

> +	      /* Replace %H, %D and %DD for %s's.  */

Did you mean "Replace ... _with_ %s's"?


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-10-27 12:05 ` Eli Zaretskii
@ 2007-10-29 15:03   ` Luis Machado
  2007-10-29 20:12     ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Luis Machado @ 2007-10-29 15:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1305 bytes --]

Thanks for reviewing Eli.

> If we can implement DFP printing in GDB, why should we also check for
> native DFP support and use that if available?  Are there any
> advantages in the native DFP printing, and if so, what are they?

Yes. With native DFP support we would have access to all the modifiers
(precision, width etc) available for printf, whereas, in the string
conversion solution we would just have a straight value-to-string
conversion mechanism without any additional capability.

> Also, if this patch is accepted, please submit also a suitable patch
> for the manual (doc/gdb.texinfo), where we describe the format
> conversions supported by the `printf' command (node "Output").

No problem. I'll supply that patch.

> A few questions/comments to the patch itself:
> 
> > -	double_arg, long_double_arg
> > +	double_arg, long_double_arg, decfloat_arg
> 
> You are using decfloat_arg unconditionally, but I don't see it defined
> anywhere in today's CVS.  Am I missing something?

decfloat_arg is being defined in an "enum" structure together with the
other values (double_arg, long_double_arg, int_arg etc). Is there a
different place you think it needs to be defined as well?

> +	      /* Replace %H, %D and %DD for %s's.  */
> Did you mean "Replace ... _with_ %s's"?
Fixed.

Regards,
Luis

[-- Attachment #2: printf-dfp.diff --]
[-- Type: text/x-patch, Size: 7168 bytes --]

2007-10-29  Luis Machado  <luisgpm@br.ibm.com>

  * printcmd.c: (printf_command): Add new DFP modifiers %H, %D and 
    %DD.
  * configure.ac: Add check for DECFLOAT printf support.
  * configure: Regenerated.

Index: git/gdb/printcmd.c
===================================================================
--- git.orig/gdb/printcmd.c	2007-10-26 17:43:36.000000000 -0700
+++ git/gdb/printcmd.c	2007-10-29 04:41:23.000000000 -0700
@@ -41,6 +41,7 @@
 #include "gdb_assert.h"
 #include "block.h"
 #include "disasm.h"
+#include "dfp.h"
 
 #ifdef TUI
 #include "tui/tui.h"		/* For tui_active et.al.   */
@@ -1819,7 +1820,7 @@
     enum argclass
       {
 	int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
-	double_arg, long_double_arg
+	double_arg, long_double_arg, decfloat_arg
       };
     enum argclass *argclass;
     enum argclass this_argclass;
@@ -1928,6 +1929,31 @@
 		bad = 1;
 	      break;
 
+	    /* DFP Decimal32 types.  */
+	    case 'H':
+	      this_argclass = decfloat_arg;
+
+              if (lcount || seen_h || seen_big_l)
+                bad = 1;
+              if (seen_prec || seen_zero || seen_space || seen_plus)
+                bad = 1;
+	      break;
+
+	    /* DFP Decimal64 and Decimal128 types.  */
+	    case 'D':
+	      this_argclass = decfloat_arg;
+
+              if (lcount || seen_h || seen_big_l)
+                bad = 1;
+              if (seen_prec || seen_zero || seen_space || seen_plus)
+                bad = 1;
+
+	      if (*(++f) == 'D')
+		printf_unfiltered("\nDecimal 128\n");
+	      else
+		printf_unfiltered("\nDecimal 64\n");
+	      break;
+
 	    case 'c':
 	      this_argclass = int_arg;
 	      if (lcount || seen_h || seen_big_l)
@@ -2094,6 +2120,55 @@
 	      printf_filtered (current_substring, val);
 	      break;
 	    }
+
+	  /* Handles decimal floating point values.  */
+	  case decfloat_arg:
+	    {
+	      char *eos;
+	      char decstr[128];
+	      unsigned int dfp_len = TYPE_LENGTH (value_type (val_args[i]));
+	      uint8_t *dfp_value_ptr = (uint8_t *) value_contents_all (val_args[i])
+                                      + value_offset (val_args[i]);
+
+#if defined (PRINTF_HAS_DECFLOAT)
+	      printf_filtered(current_substring, dfp_value_ptr);
+#else
+	      if (TYPE_CODE (value_type (val_args[i])) != TYPE_CODE_DECFLOAT)
+		error (_("Cannot convert parameter to decfloat."));
+
+	      /* As a workaround until vasprintf has native support for DFP
+		 we convert the DFP values to string and print them using
+		 the %s format specifier.  */
+	      decimal_to_string (dfp_value_ptr, dfp_len, decstr);
+
+	      /* Points to the end of the string so that we can go back
+		 and check for DFP format specifiers.  */
+	      eos = current_substring + strlen(current_substring);
+
+	      /* Replace %H, %D and %DD with %s's.  */
+	      while(*--eos != '%')
+		if (*eos == 'D' && *(eos - 1) == 'D')
+		  {
+		    *(eos - 1) = 's';
+
+		    /* If we've found a %DD format specifier we need to go
+		       through the whole string pulling back one character
+		       since this format specifier has two chars.  */
+		    while (eos < last_arg)
+		      {
+			*eos = *(eos + 1);
+			eos++;
+		      }
+		  }
+		else if (*eos == 'D' || *eos == 'H')
+		  *eos = 's';
+
+	      /* Print the DFP value.  */
+	      printf_filtered(current_substring, decstr);
+	      break;
+#endif
+	    }
+
 	  case ptr_arg:
 	    {
 	      /* We avoid the host's %p because pointers are too
Index: git/gdb/configure.ac
===================================================================
--- git.orig/gdb/configure.ac	2007-10-26 17:43:36.000000000 -0700
+++ git/gdb/configure.ac	2007-10-26 17:52:25.000000000 -0700
@@ -927,6 +927,25 @@
             [Define to 1 if the "%ll" format works to print long longs.])
 fi
 
+# Check if the compiler and runtime support printing decfloats.
+
+AC_CACHE_CHECK([for decfloat support in printf],
+               gdb_cv_printf_has_decfloat,
+               [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
+[[char buf[64];
+  _Decimal32 d32 = 1.2345df;
+  _Decimal64 d64 = 1.2345dd;
+  _Decimal128 d128 = 1.2345dl;
+  sprintf (buf, "Decimal32: %H\nDecimal64: %D\nDecimal128: %DD", d32, d64, d128);
+  return (strcmp ("Decimal32: 1.2345\nDecimal64: 1.2345\nDecimal128: 1.2345", buf));]])],
+                              gdb_cv_printf_has_decfloat=yes,
+                              gdb_cv_printf_has_decfloat=no,
+                              gdb_cv_printf_has_decfloat=no)])
+if test $gdb_cv_printf_has_decfloat = yes; then
+  AC_DEFINE(PRINTF_HAS_DECFLOAT, 1,
+            [Define to 1 if the "%H, %D and %DD" formats work to print decfloats.])
+fi
+
 # Check if the compiler supports the `long double' type.  We can't use
 # AC_C_LONG_DOUBLE because that one does additional checks on the
 # constants defined in <float.h> that fail on some systems,
Index: git/gdb/configure
===================================================================
--- git.orig/gdb/configure	2007-10-26 17:43:36.000000000 -0700
+++ git/gdb/configure	2007-10-26 17:59:22.000000000 -0700
@@ -21132,6 +21132,69 @@
 
 fi
 
+# Check if the compiler and runtime support printing decfloats.
+
+echo "$as_me:$LINENO: checking for decfloat support in printf" >&5
+echo $ECHO_N "checking for decfloat support in printf... $ECHO_C" >&6
+if test "${gdb_cv_printf_has_decfloat+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  gdb_cv_printf_has_decfloat=no
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+char buf[64];
+  _Decimal32 d32 = 1.2345df;
+  _Decimal64 d64 = 1.2345dd;
+  _Decimal128 d128 = 1.2345dl;
+  sprintf (buf, "Decimal32: %H\nDecimal64: %D\nDecimal128: %DD", d32, d64, d128);
+  return (strcmp ("Decimal32: 1.2345\nDecimal64: 1.2345\nDecimal128: 1.2345", buf));
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  gdb_cv_printf_has_decfloat=yes
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+gdb_cv_printf_has_decfloat=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+echo "$as_me:$LINENO: result: $gdb_cv_printf_has_decfloat" >&5
+echo "${ECHO_T}$gdb_cv_printf_has_decfloat" >&6
+if test $gdb_cv_printf_has_decfloat = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define PRINTF_HAS_DECFLOAT 1
+_ACEOF
+
+fi
+
 # Check if the compiler supports the `long double' type.  We can't use
 # AC_C_LONG_DOUBLE because that one does additional checks on the
 # constants defined in <float.h> that fail on some systems,

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-10-29 15:03   ` Luis Machado
@ 2007-10-29 20:12     ` Eli Zaretskii
  2007-10-29 20:19       ` Daniel Jacobowitz
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2007-10-29 20:12 UTC (permalink / raw)
  To: luisgpm; +Cc: gdb-patches

> From: Luis Machado <luisgpm@linux.vnet.ibm.com>
> Cc: gdb-patches@sourceware.org
> Date: Mon, 29 Oct 2007 11:46:55 -0300
> 
> > > -	double_arg, long_double_arg
> > > +	double_arg, long_double_arg, decfloat_arg
> > 
> > You are using decfloat_arg unconditionally, but I don't see it defined
> > anywhere in today's CVS.  Am I missing something?
> 
> decfloat_arg is being defined in an "enum" structure together with the
> other values (double_arg, long_double_arg, int_arg etc).

Defined where?  I probably missed some file, because I searched for it
in the current CVS and couldn't find, and neither do I see it in your
patch.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-10-29 20:12     ` Eli Zaretskii
@ 2007-10-29 20:19       ` Daniel Jacobowitz
  2007-10-30  4:20         ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Jacobowitz @ 2007-10-29 20:19 UTC (permalink / raw)
  To: gdb-patches

On Mon, Oct 29, 2007 at 10:05:41PM +0200, Eli Zaretskii wrote:
> > From: Luis Machado <luisgpm@linux.vnet.ibm.com>
> > Cc: gdb-patches@sourceware.org
> > Date: Mon, 29 Oct 2007 11:46:55 -0300
> > 
> > > > -	double_arg, long_double_arg
> > > > +	double_arg, long_double_arg, decfloat_arg
> > > 
> > > You are using decfloat_arg unconditionally, but I don't see it defined
> > > anywhere in today's CVS.  Am I missing something?
> > 
> > decfloat_arg is being defined in an "enum" structure together with the
> > other values (double_arg, long_double_arg, int_arg etc).
> 
> Defined where?  I probably missed some file, because I searched for it
> in the current CVS and couldn't find, and neither do I see it in your
> patch.

The above is a definition:

    enum argclass
      {
        int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
        double_arg, long_double_arg
      };

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-10-29 20:19       ` Daniel Jacobowitz
@ 2007-10-30  4:20         ` Eli Zaretskii
  2007-10-30  4:39           ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2007-10-30  4:20 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

> Date: Mon, 29 Oct 2007 16:12:53 -0400
> From: Daniel Jacobowitz <drow@false.org>
> 
> The above is a definition:

Oops, you are write.  Too small loophole, I guess...

Sorry.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-10-30  4:20         ` Eli Zaretskii
@ 2007-10-30  4:39           ` Eli Zaretskii
  2007-10-30 18:19             ` Luis Machado
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2007-10-30  4:39 UTC (permalink / raw)
  To: drow, gdb-patches

> Date: Tue, 30 Oct 2007 06:05:34 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> CC: gdb-patches@sourceware.org
> 
> Oops, you are write.
                ^^^^^
Sigh.  Sorry again.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-10-30  4:39           ` Eli Zaretskii
@ 2007-10-30 18:19             ` Luis Machado
  2007-10-30 20:58               ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Luis Machado @ 2007-10-30 18:19 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: drow, gdb-patches

On Tue, 2007-10-30 at 06:20 +0200, Eli Zaretskii wrote:
> > Date: Tue, 30 Oct 2007 06:05:34 +0200
> > From: Eli Zaretskii <eliz@gnu.org>
> > CC: gdb-patches@sourceware.org
> > 
> > Oops, you are write.
>                 ^^^^^
> Sigh.  Sorry again.

Daniel did it before me. :-)

So, given the advantages of having the native printf support for DFP and
the disadvantages of not having support on glibc on some systems, is it
ok to commit this one? (Documentation and testcases will follow).

Regards,
Luis



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-10-30 18:19             ` Luis Machado
@ 2007-10-30 20:58               ` Eli Zaretskii
  2007-11-01  1:18                 ` Luis Machado
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2007-10-30 20:58 UTC (permalink / raw)
  To: luisgpm; +Cc: drow, gdb-patches

> From: Luis Machado <luisgpm@linux.vnet.ibm.com>
> Cc: drow@false.org, gdb-patches@sourceware.org
> Date: Tue, 30 Oct 2007 11:14:09 -0300
> 
> So, given the advantages of having the native printf support for DFP and
> the disadvantages of not having support on glibc on some systems, is it
> ok to commit this one? (Documentation and testcases will follow).

It's okay to commit this one _when_ the documentation is part of the
patch.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-10-30 20:58               ` Eli Zaretskii
@ 2007-11-01  1:18                 ` Luis Machado
  2007-11-01  4:11                   ` Eli Zaretskii
  2007-11-01 15:34                   ` Daniel Jacobowitz
  0 siblings, 2 replies; 18+ messages in thread
From: Luis Machado @ 2007-11-01  1:18 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 282 bytes --]

Eli,

> It's okay to commit this one _when_ the documentation is part of the
> patch.

How does this manual entry look? I tried to make it clear, but if i
missed something please let me know.

Regards,
-- 
Luis Machado
IBM Linux Technology Center
e-mail: luisgpm@linux.vnet.ibm.com

[-- Attachment #2: printf-dfp.diff --]
[-- Type: text/x-patch, Size: 11822 bytes --]

2007-10-31  Luis Machado  <luisgpm@br.ibm.com>

    * printcmd.c: (printf_command): Add support for new DFP 
    modifiers %H, %D and %DD.
    * configure.ac: Add check for DECFLOAT printf support.
    * configure: Regenerated.
    * doc/gdb.texinfo: Update printf command's description.
    * testsuite/gdb.base/printcmds.exp: New function 
    test_printf_with_dfp.

Index: git/gdb/printcmd.c
===================================================================
--- git.orig/gdb/printcmd.c	2007-10-31 15:17:33.000000000 -0700
+++ git/gdb/printcmd.c	2007-10-31 18:12:39.000000000 -0700
@@ -41,6 +41,7 @@
 #include "gdb_assert.h"
 #include "block.h"
 #include "disasm.h"
+#include "dfp.h"
 
 #ifdef TUI
 #include "tui/tui.h"		/* For tui_active et.al.   */
@@ -1819,7 +1820,7 @@
     enum argclass
       {
 	int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
-	double_arg, long_double_arg
+	double_arg, long_double_arg, decfloat_arg
       };
     enum argclass *argclass;
     enum argclass this_argclass;
@@ -1928,6 +1929,34 @@
 		bad = 1;
 	      break;
 
+	    /* DFP Decimal32 types.  */
+	    case 'H':
+	      this_argclass = decfloat_arg;
+
+#ifndef PRINTF_HAS_DECFLOAT
+              if (lcount || seen_h || seen_big_l)
+                bad = 1;
+              if (seen_prec || seen_zero || seen_space || seen_plus)
+                bad = 1;
+#endif
+	      break;
+
+	    /* DFP Decimal64 and Decimal128 types.  */
+	    case 'D':
+	      this_argclass = decfloat_arg;
+
+#ifndef PRINTF_HAS_DECFLOAT
+              if (lcount || seen_h || seen_big_l)
+                bad = 1;
+              if (seen_prec || seen_zero || seen_space || seen_plus)
+                bad = 1;
+#endif
+	      /* Check for a Decimal128.  */
+	      if(*(f + 1) == 'D')
+		f++;
+
+	      break;
+
 	    case 'c':
 	      this_argclass = int_arg;
 	      if (lcount || seen_h || seen_big_l)
@@ -2094,6 +2123,55 @@
 	      printf_filtered (current_substring, val);
 	      break;
 	    }
+
+	  /* Handles decimal floating point values.  */
+	  case decfloat_arg:
+	    {
+	      char *eos;
+	      char decstr[128];
+	      unsigned int dfp_len = TYPE_LENGTH (value_type (val_args[i]));
+	      unsigned char *dfp_value_ptr = (unsigned char *) value_contents_all (val_args[i])
+                                      + value_offset (val_args[i]);
+
+#if defined (PRINTF_HAS_DECFLOAT)
+	      printf_filtered(current_substring, dfp_value_ptr);
+#else
+	      if (TYPE_CODE (value_type (val_args[i])) != TYPE_CODE_DECFLOAT)
+		error (_("Cannot convert parameter to decfloat."));
+
+	      /* As a workaround until vasprintf has native support for DFP
+		 we convert the DFP values to string and print them using
+		 the %s format specifier.  */
+	      decimal_to_string (dfp_value_ptr, dfp_len, decstr);
+
+	      /* Points to the end of the string so that we can go back
+		 and check for DFP format specifiers.  */
+	      eos = current_substring + strlen(current_substring);
+
+	      /* Replace %H, %D and %DD with %s's.  */
+	      while(*--eos != '%')
+		if (*eos == 'D' && *(eos - 1) == 'D')
+		  {
+		    *(eos - 1) = 's';
+
+		    /* If we've found a %DD format specifier we need to go
+		       through the whole string pulling back one character
+		       since this format specifier has two chars.  */
+		    while (eos < last_arg)
+		      {
+			*eos = *(eos + 1);
+			eos++;
+		      }
+		  }
+		else if (*eos == 'D' || *eos == 'H')
+		  *eos = 's';
+
+	      /* Print the DFP value.  */
+	      printf_filtered(current_substring, decstr);
+	      break;
+#endif
+	    }
+
 	  case ptr_arg:
 	    {
 	      /* We avoid the host's %p because pointers are too
Index: git/gdb/configure.ac
===================================================================
--- git.orig/gdb/configure.ac	2007-10-31 15:17:33.000000000 -0700
+++ git/gdb/configure.ac	2007-10-31 15:17:37.000000000 -0700
@@ -928,6 +928,25 @@
             [Define to 1 if the "%ll" format works to print long longs.])
 fi
 
+# Check if the compiler and runtime support printing decfloats.
+
+AC_CACHE_CHECK([for decfloat support in printf],
+               gdb_cv_printf_has_decfloat,
+               [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
+[[char buf[64];
+  _Decimal32 d32 = 1.2345df;
+  _Decimal64 d64 = 1.2345dd;
+  _Decimal128 d128 = 1.2345dl;
+  sprintf (buf, "Decimal32: %H\nDecimal64: %D\nDecimal128: %DD", d32, d64, d128);
+  return (strcmp ("Decimal32: 1.2345\nDecimal64: 1.2345\nDecimal128: 1.2345", buf));]])],
+                              gdb_cv_printf_has_decfloat=yes,
+                              gdb_cv_printf_has_decfloat=no,
+                              gdb_cv_printf_has_decfloat=no)])
+if test $gdb_cv_printf_has_decfloat = yes; then
+  AC_DEFINE(PRINTF_HAS_DECFLOAT, 1,
+            [Define to 1 if the "%H, %D and %DD" formats work to print decfloats.])
+fi
+
 # Check if the compiler supports the `long double' type.  We can't use
 # AC_C_LONG_DOUBLE because that one does additional checks on the
 # constants defined in <float.h> that fail on some systems,
Index: git/gdb/configure
===================================================================
--- git.orig/gdb/configure	2007-10-31 15:17:33.000000000 -0700
+++ git/gdb/configure	2007-10-31 15:17:37.000000000 -0700
@@ -21362,6 +21362,69 @@
 
 fi
 
+# Check if the compiler and runtime support printing decfloats.
+
+echo "$as_me:$LINENO: checking for decfloat support in printf" >&5
+echo $ECHO_N "checking for decfloat support in printf... $ECHO_C" >&6
+if test "${gdb_cv_printf_has_decfloat+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  gdb_cv_printf_has_decfloat=no
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+char buf[64];
+  _Decimal32 d32 = 1.2345df;
+  _Decimal64 d64 = 1.2345dd;
+  _Decimal128 d128 = 1.2345dl;
+  sprintf (buf, "Decimal32: %H\nDecimal64: %D\nDecimal128: %DD", d32, d64, d128);
+  return (strcmp ("Decimal32: 1.2345\nDecimal64: 1.2345\nDecimal128: 1.2345", buf));
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  gdb_cv_printf_has_decfloat=yes
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+gdb_cv_printf_has_decfloat=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+echo "$as_me:$LINENO: result: $gdb_cv_printf_has_decfloat" >&5
+echo "${ECHO_T}$gdb_cv_printf_has_decfloat" >&6
+if test $gdb_cv_printf_has_decfloat = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define PRINTF_HAS_DECFLOAT 1
+_ACEOF
+
+fi
+
 # Check if the compiler supports the `long double' type.  We can't use
 # AC_C_LONG_DOUBLE because that one does additional checks on the
 # constants defined in <float.h> that fail on some systems,
Index: git/gdb/doc/gdb.texinfo
===================================================================
--- git.orig/gdb/doc/gdb.texinfo	2007-10-25 12:48:45.000000000 -0700
+++ git/gdb/doc/gdb.texinfo	2007-10-31 18:07:01.000000000 -0700
@@ -16539,6 +16539,35 @@
 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
 single character.  Octal and hexadecimal escape sequences are not
 supported.
+
+Printf also supports conversion specifications for DFP (Decimal Floating Point)
+types using the following conversion letters:
+
+@itemize @bullet
+@item
+@samp{H} for printing Decimal32 types.
+
+@item
+@samp{D} for printing Decimal64 types.
+
+@item
+@samp{DD} for printing Decimal128 types.
+@end itemize
+
+If the underlying @code{C} implementation used to build @value{GDBN} has
+support for the three conversion letters for DFP types, other modifiers
+such as width and precision will also be available for @value{GDB} to use.
+
+In case there is no such @code{C} support, no additional modifiers will be
+available and the value will be printed in the standard way.
+
+Printing DFP types with the conversion letters seen before works as
+the example:
+
+@smallexample
+printf "D32: %H - D64: %D - D128: %DD\n",1.2345df,1.2E10dd,1.2E1dl
+@end smallexample
+
 @end table
 
 @node Interpreters
Index: git/gdb/testsuite/gdb.base/printcmds.exp
===================================================================
--- git.orig/gdb/testsuite/gdb.base/printcmds.exp	2007-10-31 17:46:12.000000000 -0700
+++ git/gdb/testsuite/gdb.base/printcmds.exp	2007-10-31 18:08:39.000000000 -0700
@@ -668,6 +668,57 @@
 0xfeedface, 0xdeadbeef, 5.0" "bad -99.54\[0-9\]+, z feedface, deadbeef, 5.0+"
 }
 
+#Test printing DFP values with printf
+proc test_printf_with_dfp {} {
+
+    # Test various dfp values, covering 32-bit, 64-bit and 128-bit ones
+
+    # _Decimal32 constants, which can support up to 7 digits
+    gdb_test "printf \"%H\\n\",1.2df" "1.2"
+    gdb_test "printf \"%H\\n\",-1.2df" "-1.2"
+    gdb_test "printf \"%H\\n\",1.234567df" "1.234567"
+    gdb_test "printf \"%H\\n\",-1.234567df" "-1.234567"
+    gdb_test "printf \"%H\\n\",1234567.df" "1234567"
+    gdb_test "printf \"%H\\n\",-1234567.df" "-1234567"
+
+    gdb_test "printf \"%H\\n\",1.2E1df" "12"
+    gdb_test "printf \"%H\\n\",1.2E10df" "1.2E\\+10"
+    gdb_test "printf \"%H\\n\",1.2E-10df" "1.2E-10"
+
+    # The largest exponent for 32-bit dfp value is 96.
+    gdb_test "printf \"%H\\n\",1.2E96df" "1.200000E\\+96"
+
+    # _Decimal64 constants, which can support up to 16 digits
+    gdb_test "printf \"%D\\n\",1.2dd" "1.2"
+    gdb_test "printf \"%D\\n\",-1.2dd" "-1.2"
+    gdb_test "printf \"%D\\n\",1.234567890123456dd" "1.234567890123456"
+    gdb_test "printf \"%D\\n\",-1.234567890123456dd" "-1.234567890123456"
+    gdb_test "printf \"%D\\n\",1234567890123456.dd" "1234567890123456"
+    gdb_test "printf \"%D\\n\",-1234567890123456.dd" "-1234567890123456"
+
+    gdb_test "printf \"%D\\n\",1.2E1dd" "12"
+    gdb_test "printf \"%D\\n\",1.2E10dd" "1.2E\\+10"
+    gdb_test "printf \"%D\\n\",1.2E-10dd" "1.2E-10"
+
+    # The largest exponent for 64-bit dfp value is 384.
+    gdb_test "printf \"%D\\n\",1.2E384dd" "1.200000000000000E\\+384"
+
+    # _Decimal128 constants, which can support up to 34 digits
+    gdb_test "printf \"%DD\\n\",1.2dl" "1.2"
+    gdb_test "printf \"%DD\\n\",-1.2dl" "-1.2"
+    gdb_test "printf \"%DD\\n\",1.234567890123456789012345678901234dl" "1.234567890123456789012345678901234"
+    gdb_test "printf \"%DD\\n\",-1.234567890123456789012345678901234dl" "-1.234567890123456789012345678901234"
+    gdb_test "printf \"%DD\\n\",1234567890123456789012345678901234.dl" "1234567890123456789012345678901234"
+    gdb_test "printf \"%DD\\n\",-1234567890123456789012345678901234.dl" "-1234567890123456789012345678901234"
+
+    gdb_test "printf \"%DD\\n\",1.2E1dl" "12"
+    gdb_test "printf \"%DD\\n\",1.2E10dl" "1.2E\\+10"
+    gdb_test "printf \"%DD\\n\",1.2E-10dl" "1.2E-10"
+
+    # The largest exponent for 128-bit dfp value is 6144.
+    gdb_test "printf \"%DD\\n\",1.2E6144dl" "1.200000000000000000000000000000000E\\+6144"
+}
+
 # Escape a left curly brace to prevent it from being interpreted as 
 # the beginning of a bound
 proc gdb_test_escape_braces { args } {
@@ -711,6 +762,7 @@
 	test_print_string_constants
 	test_print_array_constants
 	test_printf
+	test_printf_with_dfp
     }
 } else {
     fail "C print command tests suppressed"

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-11-01  1:18                 ` Luis Machado
@ 2007-11-01  4:11                   ` Eli Zaretskii
  2007-11-01 10:21                     ` Andreas Schwab
  2007-11-01 15:34                   ` Daniel Jacobowitz
  1 sibling, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2007-11-01  4:11 UTC (permalink / raw)
  To: luisgpm; +Cc: gdb-patches

> From: Luis Machado <luisgpm@linux.vnet.ibm.com>
> Cc: gdb-patches@sourceware.org
> Date: Wed, 31 Oct 2007 22:18:39 -0300
> 
> How does this manual entry look? I tried to make it clear, but if i
> missed something please let me know.

It's okay, modulo the following problems:

> +Printf also supports conversion specifications for DFP (Decimal Floating Point)
> +types using the following conversion letters:

"Printf" is a name of a command, so please use @code{Printf}.

Also, when you first introduce a term, such as DFP, it is good to put
it in @dfn{}, as in @dfn{Decimal Floating Point}, so that it stands
out.

> +Printing DFP types with the conversion letters seen before works as
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +the example:

"with the above conversion letters" is better.

Also, I'd rephrase this:

 Here's an example of printing DFP types using the above conversion
 letters:

Other than that, the patch for the manual is fine.  Thanks.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-11-01  4:11                   ` Eli Zaretskii
@ 2007-11-01 10:21                     ` Andreas Schwab
  2007-11-01 12:02                       ` Luis Machado
  0 siblings, 1 reply; 18+ messages in thread
From: Andreas Schwab @ 2007-11-01 10:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: luisgpm, gdb-patches

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Luis Machado <luisgpm@linux.vnet.ibm.com>
>> Cc: gdb-patches@sourceware.org
>> Date: Wed, 31 Oct 2007 22:18:39 -0300
>> 
>> How does this manual entry look? I tried to make it clear, but if i
>> missed something please let me know.
>
> It's okay, modulo the following problems:
>
>> +Printf also supports conversion specifications for DFP (Decimal Floating Point)
>> +types using the following conversion letters:
>
> "Printf" is a name of a command, so please use @code{Printf}.

Also putting it at the start of the sentence should be avoided.
Commands are commonly spelled in lower case.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-11-01 10:21                     ` Andreas Schwab
@ 2007-11-01 12:02                       ` Luis Machado
  2007-11-02 12:05                         ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Luis Machado @ 2007-11-01 12:02 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Eli Zaretskii, gdb-patches

Thanks Eli, i've rephrased the example message and addressed the other
issues

Andreas, i've changed the sentence starting with the command's name and
now it reads as follows:

"Additionally, @code{printf} supports conversion specifications for DFP
(@dfn{Decimal Floating Point}) types using the following conversion
letters:"

Looks OK?

Regards,

-- 
Luis Machado
IBM Linux Technology Center
e-mail: luisgpm@linux.vnet.ibm.com


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-11-01  1:18                 ` Luis Machado
  2007-11-01  4:11                   ` Eli Zaretskii
@ 2007-11-01 15:34                   ` Daniel Jacobowitz
  2007-11-01 16:00                     ` Luis Machado
  1 sibling, 1 reply; 18+ messages in thread
From: Daniel Jacobowitz @ 2007-11-01 15:34 UTC (permalink / raw)
  To: Luis Machado; +Cc: Eli Zaretskii, gdb-patches

Your most recent message was missing the revised patch, so I'm
replying to an older one.  I was going to complain aobut some debug
printfs, but you seem to have fixed them already.

On Wed, Oct 31, 2007 at 10:18:39PM -0300, Luis Machado wrote:
> +#if defined (PRINTF_HAS_DECFLOAT)
> +	      printf_filtered(current_substring, dfp_value_ptr);
> +#else

Here and a couple of other places in the patch, please remember the
space before a left parenthesis.

> +AC_CACHE_CHECK([for decfloat support in printf],
> +               gdb_cv_printf_has_decfloat,
> +               [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],

Boo, more run checks in configure :-(  I cross-compile most of my
GDBs so run checks do not work.  Well, this is not a new problem.

Rest looks fine to me too.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-11-01 15:34                   ` Daniel Jacobowitz
@ 2007-11-01 16:00                     ` Luis Machado
  2007-11-02 12:07                       ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Luis Machado @ 2007-11-01 16:00 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Eli Zaretskii, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 172 bytes --]

Hi,

This should be the final version then.

> Here and a couple of other places in the patch, please remember the
> space before a left parenthesis.
Fixed.

Thanks.
Luis


[-- Attachment #2: printf-dfp.diff --]
[-- Type: text/x-patch, Size: 11842 bytes --]

2007-11-01  Luis Machado  <luisgpm@br.ibm.com>

    * printcmd.c: (printf_command): Add support for new DFP 
    modifiers %H, %D and %DD.
    * configure.ac: Add check for DECFLOAT printf support.
    * configure: Regenerated.
    * doc/gdb.texinfo: Update printf command's description.
    * testsuite/gdb.base/printcmds.exp: New function 
    test_printf_with_dfp.

Index: git/gdb/printcmd.c
===================================================================
--- git.orig/gdb/printcmd.c	2007-10-31 15:17:33.000000000 -0700
+++ git/gdb/printcmd.c	2007-11-01 08:50:44.000000000 -0700
@@ -41,6 +41,7 @@
 #include "gdb_assert.h"
 #include "block.h"
 #include "disasm.h"
+#include "dfp.h"
 
 #ifdef TUI
 #include "tui/tui.h"		/* For tui_active et.al.   */
@@ -1819,7 +1820,7 @@
     enum argclass
       {
 	int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
-	double_arg, long_double_arg
+	double_arg, long_double_arg, decfloat_arg
       };
     enum argclass *argclass;
     enum argclass this_argclass;
@@ -1928,6 +1929,34 @@
 		bad = 1;
 	      break;
 
+	    /* DFP Decimal32 types.  */
+	    case 'H':
+	      this_argclass = decfloat_arg;
+
+#ifndef PRINTF_HAS_DECFLOAT
+              if (lcount || seen_h || seen_big_l)
+                bad = 1;
+              if (seen_prec || seen_zero || seen_space || seen_plus)
+                bad = 1;
+#endif
+	      break;
+
+	    /* DFP Decimal64 and Decimal128 types.  */
+	    case 'D':
+	      this_argclass = decfloat_arg;
+
+#ifndef PRINTF_HAS_DECFLOAT
+              if (lcount || seen_h || seen_big_l)
+                bad = 1;
+              if (seen_prec || seen_zero || seen_space || seen_plus)
+                bad = 1;
+#endif
+	      /* Check for a Decimal128.  */
+	      if (*(f + 1) == 'D')
+		f++;
+
+	      break;
+
 	    case 'c':
 	      this_argclass = int_arg;
 	      if (lcount || seen_h || seen_big_l)
@@ -2094,6 +2123,55 @@
 	      printf_filtered (current_substring, val);
 	      break;
 	    }
+
+	  /* Handles decimal floating point values.  */
+	  case decfloat_arg:
+	    {
+	      char *eos;
+	      char decstr[128];
+	      unsigned int dfp_len = TYPE_LENGTH (value_type (val_args[i]));
+	      unsigned char *dfp_value_ptr = (unsigned char *) value_contents_all (val_args[i])
+                                      + value_offset (val_args[i]);
+
+#if defined (PRINTF_HAS_DECFLOAT)
+	      printf_filtered (current_substring, dfp_value_ptr);
+#else
+	      if (TYPE_CODE (value_type (val_args[i])) != TYPE_CODE_DECFLOAT)
+		error (_("Cannot convert parameter to decfloat."));
+
+	      /* As a workaround until vasprintf has native support for DFP
+		 we convert the DFP values to string and print them using
+		 the %s format specifier.  */
+	      decimal_to_string (dfp_value_ptr, dfp_len, decstr);
+
+	      /* Points to the end of the string so that we can go back
+		 and check for DFP format specifiers.  */
+	      eos = current_substring + strlen (current_substring);
+
+	      /* Replace %H, %D and %DD with %s's.  */
+	      while (*--eos != '%')
+		if (*eos == 'D' && *(eos - 1) == 'D')
+		  {
+		    *(eos - 1) = 's';
+
+		    /* If we've found a %DD format specifier we need to go
+		       through the whole string pulling back one character
+		       since this format specifier has two chars.  */
+		    while (eos < last_arg)
+		      {
+			*eos = *(eos + 1);
+			eos++;
+		      }
+		  }
+		else if (*eos == 'D' || *eos == 'H')
+		  *eos = 's';
+
+	      /* Print the DFP value.  */
+	      printf_filtered (current_substring, decstr);
+	      break;
+#endif
+	    }
+
 	  case ptr_arg:
 	    {
 	      /* We avoid the host's %p because pointers are too
Index: git/gdb/configure.ac
===================================================================
--- git.orig/gdb/configure.ac	2007-10-31 15:17:33.000000000 -0700
+++ git/gdb/configure.ac	2007-10-31 15:17:37.000000000 -0700
@@ -928,6 +928,25 @@
             [Define to 1 if the "%ll" format works to print long longs.])
 fi
 
+# Check if the compiler and runtime support printing decfloats.
+
+AC_CACHE_CHECK([for decfloat support in printf],
+               gdb_cv_printf_has_decfloat,
+               [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
+[[char buf[64];
+  _Decimal32 d32 = 1.2345df;
+  _Decimal64 d64 = 1.2345dd;
+  _Decimal128 d128 = 1.2345dl;
+  sprintf (buf, "Decimal32: %H\nDecimal64: %D\nDecimal128: %DD", d32, d64, d128);
+  return (strcmp ("Decimal32: 1.2345\nDecimal64: 1.2345\nDecimal128: 1.2345", buf));]])],
+                              gdb_cv_printf_has_decfloat=yes,
+                              gdb_cv_printf_has_decfloat=no,
+                              gdb_cv_printf_has_decfloat=no)])
+if test $gdb_cv_printf_has_decfloat = yes; then
+  AC_DEFINE(PRINTF_HAS_DECFLOAT, 1,
+            [Define to 1 if the "%H, %D and %DD" formats work to print decfloats.])
+fi
+
 # Check if the compiler supports the `long double' type.  We can't use
 # AC_C_LONG_DOUBLE because that one does additional checks on the
 # constants defined in <float.h> that fail on some systems,
Index: git/gdb/configure
===================================================================
--- git.orig/gdb/configure	2007-10-31 15:17:33.000000000 -0700
+++ git/gdb/configure	2007-10-31 15:17:37.000000000 -0700
@@ -21362,6 +21362,69 @@
 
 fi
 
+# Check if the compiler and runtime support printing decfloats.
+
+echo "$as_me:$LINENO: checking for decfloat support in printf" >&5
+echo $ECHO_N "checking for decfloat support in printf... $ECHO_C" >&6
+if test "${gdb_cv_printf_has_decfloat+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  gdb_cv_printf_has_decfloat=no
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+char buf[64];
+  _Decimal32 d32 = 1.2345df;
+  _Decimal64 d64 = 1.2345dd;
+  _Decimal128 d128 = 1.2345dl;
+  sprintf (buf, "Decimal32: %H\nDecimal64: %D\nDecimal128: %DD", d32, d64, d128);
+  return (strcmp ("Decimal32: 1.2345\nDecimal64: 1.2345\nDecimal128: 1.2345", buf));
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  gdb_cv_printf_has_decfloat=yes
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+gdb_cv_printf_has_decfloat=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+echo "$as_me:$LINENO: result: $gdb_cv_printf_has_decfloat" >&5
+echo "${ECHO_T}$gdb_cv_printf_has_decfloat" >&6
+if test $gdb_cv_printf_has_decfloat = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define PRINTF_HAS_DECFLOAT 1
+_ACEOF
+
+fi
+
 # Check if the compiler supports the `long double' type.  We can't use
 # AC_C_LONG_DOUBLE because that one does additional checks on the
 # constants defined in <float.h> that fail on some systems,
Index: git/gdb/doc/gdb.texinfo
===================================================================
--- git.orig/gdb/doc/gdb.texinfo	2007-10-25 12:48:45.000000000 -0700
+++ git/gdb/doc/gdb.texinfo	2007-11-01 04:50:27.000000000 -0700
@@ -16539,6 +16539,34 @@
 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
 single character.  Octal and hexadecimal escape sequences are not
 supported.
+
+Additionally, @code{printf} supports conversion specifications for DFP
+(@dfn{Decimal Floating Point}) types using the following conversion
+letters:
+
+@itemize @bullet
+@item
+@samp{H} for printing Decimal32 types.
+
+@item
+@samp{D} for printing Decimal64 types.
+
+@item
+@samp{DD} for printing Decimal128 types.
+@end itemize
+
+If the underlying @code{C} implementation used to build @value{GDBN} has
+support for the three conversion letters for DFP types, other modifiers
+such as width and precision will also be available for @value{GDB} to use.
+
+In case there is no such @code{C} support, no additional modifiers will be
+available and the value will be printed in the standard way.
+
+Here's an example of printing DFP types using the above conversion letters:
+@smallexample
+printf "D32: %H - D64: %D - D128: %DD\n",1.2345df,1.2E10dd,1.2E1dl
+@end smallexample
+
 @end table
 
 @node Interpreters
Index: git/gdb/testsuite/gdb.base/printcmds.exp
===================================================================
--- git.orig/gdb/testsuite/gdb.base/printcmds.exp	2007-10-31 17:46:12.000000000 -0700
+++ git/gdb/testsuite/gdb.base/printcmds.exp	2007-10-31 18:08:39.000000000 -0700
@@ -668,6 +668,57 @@
 0xfeedface, 0xdeadbeef, 5.0" "bad -99.54\[0-9\]+, z feedface, deadbeef, 5.0+"
 }
 
+#Test printing DFP values with printf
+proc test_printf_with_dfp {} {
+
+    # Test various dfp values, covering 32-bit, 64-bit and 128-bit ones
+
+    # _Decimal32 constants, which can support up to 7 digits
+    gdb_test "printf \"%H\\n\",1.2df" "1.2"
+    gdb_test "printf \"%H\\n\",-1.2df" "-1.2"
+    gdb_test "printf \"%H\\n\",1.234567df" "1.234567"
+    gdb_test "printf \"%H\\n\",-1.234567df" "-1.234567"
+    gdb_test "printf \"%H\\n\",1234567.df" "1234567"
+    gdb_test "printf \"%H\\n\",-1234567.df" "-1234567"
+
+    gdb_test "printf \"%H\\n\",1.2E1df" "12"
+    gdb_test "printf \"%H\\n\",1.2E10df" "1.2E\\+10"
+    gdb_test "printf \"%H\\n\",1.2E-10df" "1.2E-10"
+
+    # The largest exponent for 32-bit dfp value is 96.
+    gdb_test "printf \"%H\\n\",1.2E96df" "1.200000E\\+96"
+
+    # _Decimal64 constants, which can support up to 16 digits
+    gdb_test "printf \"%D\\n\",1.2dd" "1.2"
+    gdb_test "printf \"%D\\n\",-1.2dd" "-1.2"
+    gdb_test "printf \"%D\\n\",1.234567890123456dd" "1.234567890123456"
+    gdb_test "printf \"%D\\n\",-1.234567890123456dd" "-1.234567890123456"
+    gdb_test "printf \"%D\\n\",1234567890123456.dd" "1234567890123456"
+    gdb_test "printf \"%D\\n\",-1234567890123456.dd" "-1234567890123456"
+
+    gdb_test "printf \"%D\\n\",1.2E1dd" "12"
+    gdb_test "printf \"%D\\n\",1.2E10dd" "1.2E\\+10"
+    gdb_test "printf \"%D\\n\",1.2E-10dd" "1.2E-10"
+
+    # The largest exponent for 64-bit dfp value is 384.
+    gdb_test "printf \"%D\\n\",1.2E384dd" "1.200000000000000E\\+384"
+
+    # _Decimal128 constants, which can support up to 34 digits
+    gdb_test "printf \"%DD\\n\",1.2dl" "1.2"
+    gdb_test "printf \"%DD\\n\",-1.2dl" "-1.2"
+    gdb_test "printf \"%DD\\n\",1.234567890123456789012345678901234dl" "1.234567890123456789012345678901234"
+    gdb_test "printf \"%DD\\n\",-1.234567890123456789012345678901234dl" "-1.234567890123456789012345678901234"
+    gdb_test "printf \"%DD\\n\",1234567890123456789012345678901234.dl" "1234567890123456789012345678901234"
+    gdb_test "printf \"%DD\\n\",-1234567890123456789012345678901234.dl" "-1234567890123456789012345678901234"
+
+    gdb_test "printf \"%DD\\n\",1.2E1dl" "12"
+    gdb_test "printf \"%DD\\n\",1.2E10dl" "1.2E\\+10"
+    gdb_test "printf \"%DD\\n\",1.2E-10dl" "1.2E-10"
+
+    # The largest exponent for 128-bit dfp value is 6144.
+    gdb_test "printf \"%DD\\n\",1.2E6144dl" "1.200000000000000000000000000000000E\\+6144"
+}
+
 # Escape a left curly brace to prevent it from being interpreted as 
 # the beginning of a bound
 proc gdb_test_escape_braces { args } {
@@ -711,6 +762,7 @@
 	test_print_string_constants
 	test_print_array_constants
 	test_printf
+	test_printf_with_dfp
     }
 } else {
     fail "C print command tests suppressed"

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-11-01 12:02                       ` Luis Machado
@ 2007-11-02 12:05                         ` Eli Zaretskii
  0 siblings, 0 replies; 18+ messages in thread
From: Eli Zaretskii @ 2007-11-02 12:05 UTC (permalink / raw)
  To: luisgpm; +Cc: schwab, gdb-patches

> From: Luis Machado <luisgpm@linux.vnet.ibm.com>
> Cc: Eli Zaretskii <eliz@gnu.org>, gdb-patches@sourceware.org
> Date: Thu, 01 Nov 2007 09:01:49 -0300
> 
> "Additionally, @code{printf} supports conversion specifications for DFP
> (@dfn{Decimal Floating Point}) types using the following conversion
> letters:"
> 
> Looks OK?

Yes, thanks.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-11-01 16:00                     ` Luis Machado
@ 2007-11-02 12:07                       ` Eli Zaretskii
  2007-11-05 11:35                         ` Luis Machado
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2007-11-02 12:07 UTC (permalink / raw)
  To: luisgpm; +Cc: drow, gdb-patches

> From: Luis Machado <luisgpm@linux.vnet.ibm.com>
> Cc: Eli Zaretskii <eliz@gnu.org>, gdb-patches@sourceware.org
> Date: Thu, 01 Nov 2007 12:59:51 -0300
> 
> This should be the final version then.

It's okay, except for one tiny gotcha:

> +@itemize @bullet
> +@item
> +@samp{H} for printing Decimal32 types.
> +
> +@item
> +@samp{D} for printing Decimal64 types.
> +
> +@item
> +@samp{DD} for printing Decimal128 types.
> +@end itemize

I asked to give those Decimal* types the @code markup, since they are
C symbols.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] printf support for DFP values
  2007-11-02 12:07                       ` Eli Zaretskii
@ 2007-11-05 11:35                         ` Luis Machado
  0 siblings, 0 replies; 18+ messages in thread
From: Luis Machado @ 2007-11-05 11:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: drow, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 65 bytes --]

Thanks.

I've checked in the updated version now.

Regards,
Luis

[-- Attachment #2: printf-dfp.diff --]
[-- Type: text/x-patch, Size: 11863 bytes --]

2007-11-05  Luis Machado  <luisgpm@br.ibm.com>

    * printcmd.c: (printf_command): Add support for new DFP 
    modifiers %H, %D and %DD.
    * configure.ac: Add check for DECFLOAT printf support.
    * configure: Regenerated.
    * doc/gdb.texinfo: Update printf command's description.
    * testsuite/gdb.base/printcmds.exp: New function 
    test_printf_with_dfp.

Index: git/gdb/printcmd.c
===================================================================
--- git.orig/gdb/printcmd.c	2007-11-05 03:22:27.000000000 -0800
+++ git/gdb/printcmd.c	2007-11-05 03:22:55.000000000 -0800
@@ -41,6 +41,7 @@
 #include "gdb_assert.h"
 #include "block.h"
 #include "disasm.h"
+#include "dfp.h"
 
 #ifdef TUI
 #include "tui/tui.h"		/* For tui_active et.al.   */
@@ -1819,7 +1820,7 @@
     enum argclass
       {
 	int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
-	double_arg, long_double_arg
+	double_arg, long_double_arg, decfloat_arg
       };
     enum argclass *argclass;
     enum argclass this_argclass;
@@ -1928,6 +1929,34 @@
 		bad = 1;
 	      break;
 
+	    /* DFP Decimal32 types.  */
+	    case 'H':
+	      this_argclass = decfloat_arg;
+
+#ifndef PRINTF_HAS_DECFLOAT
+              if (lcount || seen_h || seen_big_l)
+                bad = 1;
+              if (seen_prec || seen_zero || seen_space || seen_plus)
+                bad = 1;
+#endif
+	      break;
+
+	    /* DFP Decimal64 and Decimal128 types.  */
+	    case 'D':
+	      this_argclass = decfloat_arg;
+
+#ifndef PRINTF_HAS_DECFLOAT
+              if (lcount || seen_h || seen_big_l)
+                bad = 1;
+              if (seen_prec || seen_zero || seen_space || seen_plus)
+                bad = 1;
+#endif
+	      /* Check for a Decimal128.  */
+	      if (*(f + 1) == 'D')
+		f++;
+
+	      break;
+
 	    case 'c':
 	      this_argclass = int_arg;
 	      if (lcount || seen_h || seen_big_l)
@@ -2094,6 +2123,55 @@
 	      printf_filtered (current_substring, val);
 	      break;
 	    }
+
+	  /* Handles decimal floating point values.  */
+	  case decfloat_arg:
+	    {
+	      char *eos;
+	      char decstr[128];
+	      unsigned int dfp_len = TYPE_LENGTH (value_type (val_args[i]));
+	      unsigned char *dfp_value_ptr = (unsigned char *) value_contents_all (val_args[i])
+                                      + value_offset (val_args[i]);
+
+#if defined (PRINTF_HAS_DECFLOAT)
+	      printf_filtered (current_substring, dfp_value_ptr);
+#else
+	      if (TYPE_CODE (value_type (val_args[i])) != TYPE_CODE_DECFLOAT)
+		error (_("Cannot convert parameter to decfloat."));
+
+	      /* As a workaround until vasprintf has native support for DFP
+		 we convert the DFP values to string and print them using
+		 the %s format specifier.  */
+	      decimal_to_string (dfp_value_ptr, dfp_len, decstr);
+
+	      /* Points to the end of the string so that we can go back
+		 and check for DFP format specifiers.  */
+	      eos = current_substring + strlen (current_substring);
+
+	      /* Replace %H, %D and %DD with %s's.  */
+	      while (*--eos != '%')
+		if (*eos == 'D' && *(eos - 1) == 'D')
+		  {
+		    *(eos - 1) = 's';
+
+		    /* If we've found a %DD format specifier we need to go
+		       through the whole string pulling back one character
+		       since this format specifier has two chars.  */
+		    while (eos < last_arg)
+		      {
+			*eos = *(eos + 1);
+			eos++;
+		      }
+		  }
+		else if (*eos == 'D' || *eos == 'H')
+		  *eos = 's';
+
+	      /* Print the DFP value.  */
+	      printf_filtered (current_substring, decstr);
+	      break;
+#endif
+	    }
+
 	  case ptr_arg:
 	    {
 	      /* We avoid the host's %p because pointers are too
Index: git/gdb/configure.ac
===================================================================
--- git.orig/gdb/configure.ac	2007-11-05 03:22:48.000000000 -0800
+++ git/gdb/configure.ac	2007-11-05 03:22:55.000000000 -0800
@@ -928,6 +928,25 @@
             [Define to 1 if the "%ll" format works to print long longs.])
 fi
 
+# Check if the compiler and runtime support printing decfloats.
+
+AC_CACHE_CHECK([for decfloat support in printf],
+               gdb_cv_printf_has_decfloat,
+               [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
+[[char buf[64];
+  _Decimal32 d32 = 1.2345df;
+  _Decimal64 d64 = 1.2345dd;
+  _Decimal128 d128 = 1.2345dl;
+  sprintf (buf, "Decimal32: %H\nDecimal64: %D\nDecimal128: %DD", d32, d64, d128);
+  return (strcmp ("Decimal32: 1.2345\nDecimal64: 1.2345\nDecimal128: 1.2345", buf));]])],
+                              gdb_cv_printf_has_decfloat=yes,
+                              gdb_cv_printf_has_decfloat=no,
+                              gdb_cv_printf_has_decfloat=no)])
+if test $gdb_cv_printf_has_decfloat = yes; then
+  AC_DEFINE(PRINTF_HAS_DECFLOAT, 1,
+            [Define to 1 if the "%H, %D and %DD" formats work to print decfloats.])
+fi
+
 # Check if the compiler supports the `long double' type.  We can't use
 # AC_C_LONG_DOUBLE because that one does additional checks on the
 # constants defined in <float.h> that fail on some systems,
Index: git/gdb/configure
===================================================================
--- git.orig/gdb/configure	2007-11-05 03:22:48.000000000 -0800
+++ git/gdb/configure	2007-11-05 03:22:55.000000000 -0800
@@ -21362,6 +21362,69 @@
 
 fi
 
+# Check if the compiler and runtime support printing decfloats.
+
+echo "$as_me:$LINENO: checking for decfloat support in printf" >&5
+echo $ECHO_N "checking for decfloat support in printf... $ECHO_C" >&6
+if test "${gdb_cv_printf_has_decfloat+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  gdb_cv_printf_has_decfloat=no
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+char buf[64];
+  _Decimal32 d32 = 1.2345df;
+  _Decimal64 d64 = 1.2345dd;
+  _Decimal128 d128 = 1.2345dl;
+  sprintf (buf, "Decimal32: %H\nDecimal64: %D\nDecimal128: %DD", d32, d64, d128);
+  return (strcmp ("Decimal32: 1.2345\nDecimal64: 1.2345\nDecimal128: 1.2345", buf));
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  gdb_cv_printf_has_decfloat=yes
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+gdb_cv_printf_has_decfloat=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+echo "$as_me:$LINENO: result: $gdb_cv_printf_has_decfloat" >&5
+echo "${ECHO_T}$gdb_cv_printf_has_decfloat" >&6
+if test $gdb_cv_printf_has_decfloat = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define PRINTF_HAS_DECFLOAT 1
+_ACEOF
+
+fi
+
 # Check if the compiler supports the `long double' type.  We can't use
 # AC_C_LONG_DOUBLE because that one does additional checks on the
 # constants defined in <float.h> that fail on some systems,
Index: git/gdb/doc/gdb.texinfo
===================================================================
--- git.orig/gdb/doc/gdb.texinfo	2007-11-05 03:22:48.000000000 -0800
+++ git/gdb/doc/gdb.texinfo	2007-11-05 03:22:55.000000000 -0800
@@ -16557,6 +16557,34 @@
 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
 single character.  Octal and hexadecimal escape sequences are not
 supported.
+
+Additionally, @code{printf} supports conversion specifications for DFP
+(@dfn{Decimal Floating Point}) types using the following conversion
+letters:
+
+@itemize @bullet
+@item
+@samp{H} for printing @code{Decimal32} types.
+
+@item
+@samp{D} for printing @code{Decimal64} types.
+
+@item
+@samp{DD} for printing @code{Decimal128} types.
+@end itemize
+
+If the underlying @code{C} implementation used to build @value{GDBN} has
+support for the three conversion letters for DFP types, other modifiers
+such as width and precision will also be available for @value{GDB} to use.
+
+In case there is no such @code{C} support, no additional modifiers will be
+available and the value will be printed in the standard way.
+
+Here's an example of printing DFP types using the above conversion letters:
+@smallexample
+printf "D32: %H - D64: %D - D128: %DD\n",1.2345df,1.2E10dd,1.2E1dl
+@end smallexample
+
 @end table
 
 @node Interpreters
Index: git/gdb/testsuite/gdb.base/printcmds.exp
===================================================================
--- git.orig/gdb/testsuite/gdb.base/printcmds.exp	2007-11-05 03:22:27.000000000 -0800
+++ git/gdb/testsuite/gdb.base/printcmds.exp	2007-11-05 03:22:55.000000000 -0800
@@ -668,6 +668,57 @@
 0xfeedface, 0xdeadbeef, 5.0" "bad -99.54\[0-9\]+, z feedface, deadbeef, 5.0+"
 }
 
+#Test printing DFP values with printf
+proc test_printf_with_dfp {} {
+
+    # Test various dfp values, covering 32-bit, 64-bit and 128-bit ones
+
+    # _Decimal32 constants, which can support up to 7 digits
+    gdb_test "printf \"%H\\n\",1.2df" "1.2"
+    gdb_test "printf \"%H\\n\",-1.2df" "-1.2"
+    gdb_test "printf \"%H\\n\",1.234567df" "1.234567"
+    gdb_test "printf \"%H\\n\",-1.234567df" "-1.234567"
+    gdb_test "printf \"%H\\n\",1234567.df" "1234567"
+    gdb_test "printf \"%H\\n\",-1234567.df" "-1234567"
+
+    gdb_test "printf \"%H\\n\",1.2E1df" "12"
+    gdb_test "printf \"%H\\n\",1.2E10df" "1.2E\\+10"
+    gdb_test "printf \"%H\\n\",1.2E-10df" "1.2E-10"
+
+    # The largest exponent for 32-bit dfp value is 96.
+    gdb_test "printf \"%H\\n\",1.2E96df" "1.200000E\\+96"
+
+    # _Decimal64 constants, which can support up to 16 digits
+    gdb_test "printf \"%D\\n\",1.2dd" "1.2"
+    gdb_test "printf \"%D\\n\",-1.2dd" "-1.2"
+    gdb_test "printf \"%D\\n\",1.234567890123456dd" "1.234567890123456"
+    gdb_test "printf \"%D\\n\",-1.234567890123456dd" "-1.234567890123456"
+    gdb_test "printf \"%D\\n\",1234567890123456.dd" "1234567890123456"
+    gdb_test "printf \"%D\\n\",-1234567890123456.dd" "-1234567890123456"
+
+    gdb_test "printf \"%D\\n\",1.2E1dd" "12"
+    gdb_test "printf \"%D\\n\",1.2E10dd" "1.2E\\+10"
+    gdb_test "printf \"%D\\n\",1.2E-10dd" "1.2E-10"
+
+    # The largest exponent for 64-bit dfp value is 384.
+    gdb_test "printf \"%D\\n\",1.2E384dd" "1.200000000000000E\\+384"
+
+    # _Decimal128 constants, which can support up to 34 digits
+    gdb_test "printf \"%DD\\n\",1.2dl" "1.2"
+    gdb_test "printf \"%DD\\n\",-1.2dl" "-1.2"
+    gdb_test "printf \"%DD\\n\",1.234567890123456789012345678901234dl" "1.234567890123456789012345678901234"
+    gdb_test "printf \"%DD\\n\",-1.234567890123456789012345678901234dl" "-1.234567890123456789012345678901234"
+    gdb_test "printf \"%DD\\n\",1234567890123456789012345678901234.dl" "1234567890123456789012345678901234"
+    gdb_test "printf \"%DD\\n\",-1234567890123456789012345678901234.dl" "-1234567890123456789012345678901234"
+
+    gdb_test "printf \"%DD\\n\",1.2E1dl" "12"
+    gdb_test "printf \"%DD\\n\",1.2E10dl" "1.2E\\+10"
+    gdb_test "printf \"%DD\\n\",1.2E-10dl" "1.2E-10"
+
+    # The largest exponent for 128-bit dfp value is 6144.
+    gdb_test "printf \"%DD\\n\",1.2E6144dl" "1.200000000000000000000000000000000E\\+6144"
+}
+
 # Escape a left curly brace to prevent it from being interpreted as 
 # the beginning of a bound
 proc gdb_test_escape_braces { args } {
@@ -711,6 +762,7 @@
 	test_print_string_constants
 	test_print_array_constants
 	test_printf
+	test_printf_with_dfp
     }
 } else {
     fail "C print command tests suppressed"

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2007-11-05 11:35 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-27  6:25 [PATCH] printf support for DFP values Luis Machado
2007-10-27 12:05 ` Eli Zaretskii
2007-10-29 15:03   ` Luis Machado
2007-10-29 20:12     ` Eli Zaretskii
2007-10-29 20:19       ` Daniel Jacobowitz
2007-10-30  4:20         ` Eli Zaretskii
2007-10-30  4:39           ` Eli Zaretskii
2007-10-30 18:19             ` Luis Machado
2007-10-30 20:58               ` Eli Zaretskii
2007-11-01  1:18                 ` Luis Machado
2007-11-01  4:11                   ` Eli Zaretskii
2007-11-01 10:21                     ` Andreas Schwab
2007-11-01 12:02                       ` Luis Machado
2007-11-02 12:05                         ` Eli Zaretskii
2007-11-01 15:34                   ` Daniel Jacobowitz
2007-11-01 16:00                     ` Luis Machado
2007-11-02 12:07                       ` Eli Zaretskii
2007-11-05 11:35                         ` Luis Machado

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox