+
+ /* Handles decimal floating values. */
+ case decfloat_arg:
+ {
+ const gdb_byte *param_ptr = value_contents (val_args[i]);
+#if defined (PRINTF_HAS_DECFLOAT)
+ /* If we have native support for Decimal floating
+ printing, handle it here. */
+ printf_filtered (current_substring, param_ptr);
+#else
+
+ /* 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. */
+
+ char *eos, *sos;
+ int nnull_chars = 0;
+
+ /* Parameter data. */
+ struct type *param_type = value_type (val_args[i]);
+ unsigned int param_len = TYPE_LENGTH (param_type);
+
+ /* DFP output data. */
+ struct value *dfp_value = NULL;
+ gdb_byte *dfp_ptr;
+ int dfp_len = 16;
+ gdb_byte dec[16];
+ struct type *dfp_type = NULL;
+ char decstr[MAX_DECIMAL_STRING];
+
+ /* Points to the end of the string so that we can go back
+ and check for DFP length modifiers. */
+ eos = current_substring + strlen (current_substring);
+
+ /* Look for the float/double format specifier. */
+ while (*eos != 'f' && *eos != 'e' && *eos != 'E'
+ && *eos != 'g' && *eos != 'G')
+ eos--;
+
+ sos = eos;
+
+ /* Search for the '%' char and extract the size and type of
+ the output decimal value based on its modifiers
+ (%Hf, %Df, %DDf). */
+ while (*--sos != '%')
+ {
+ if (*sos == 'H')
+ {
+ dfp_len = 4;
+ dfp_type = builtin_type (current_gdbarch)->builtin_decfloat;
+ }
+ else if (*sos == 'D' && *(sos - 1) == 'D')
+ {
+ dfp_len = 16;
+ dfp_type = builtin_type (current_gdbarch)->builtin_declong;
+ sos--;
+ }
+ else
+ {
+ dfp_len = 8;
+ dfp_type = builtin_type (current_gdbarch)->builtin_decdouble;
+ }
+ }
+
+ /* Replace %Hf, %Df and %DDf with %s's. */
+ *++sos = 's';
+
+ /* Go through the whole format string and pull the correct
+ number of chars back to compensate for the change in the
+ format specifier. */
+ while (nnull_chars < nargs - i)
+ {
+ if (*eos == '\0')
+ nnull_chars++;
+
+ *++sos = *++eos;
+ }
+
+ /* Conversion between different DFP types. */
+ if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
+ decimal_convert (param_ptr, param_len, dec, dfp_len);
+ else
+ /* If this is a non-trivial conversion, just output 0.
+ A correct converted value can be displayed by explicitly
+ casting to a DFP type. */
+ decimal_from_string (dec, dfp_len, "0");
+
+ dfp_value = value_from_decfloat (dfp_type, dec);
+
+ dfp_ptr = (gdb_byte *) value_contents (dfp_value);
+
+ decimal_to_string (dfp_ptr, dfp_len, decstr);
+
+ /* Print the DFP value. */
+ printf_filtered (current_substring, decstr);
+
+ break;
+#endif
+ }
+
+ case ptr_arg:
+ {
+ /* We avoid the host's %p because pointers are too
+ likely to be the wrong size. The only interesting
+ modifier for %p is a width; extract that, and then
+ handle %p as glibc would: %#x or a literal "(nil)". */
+
+ char *p, *fmt, *fmt_p;
+#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
+ long long val = value_as_long (val_args[i]);
+#else
+ long val = value_as_long (val_args[i]);
+#endif
+
+ fmt = alloca (strlen (current_substring) + 5);
+
+ /* Copy up to the leading %. */
+ p = current_substring;
+ fmt_p = fmt;
+ while (*p)
+ {
+ int is_percent = (*p == '%');
+ *fmt_p++ = *p++;
+ if (is_percent)
+ {
+ if (*p == '%')
+ *fmt_p++ = *p++;
+ else
+ break;
+ }
+ }
+
+ if (val != 0)
+ *fmt_p++ = '#';
+
+ /* Copy any width. */
+ while (*p >= '0' && *p < '9')
+ *fmt_p++ = *p++;
+
+ gdb_assert (*p == 'p' && *(p + 1) == '\0');
+ if (val != 0)
+ {
+#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
+ *fmt_p++ = 'l';
+#endif
+ *fmt_p++ = 'l';
+ *fmt_p++ = 'x';
+ *fmt_p++ = '\0';
+ printf_filtered (fmt, val);
+ }
+ else
+ {
+ *fmt_p++ = 's';
+ *fmt_p++ = '\0';
+ printf_filtered (fmt, "(nil)");
+ }
+
+ break;
+ }
+ default:
+ internal_error (__FILE__, __LINE__,
+ _("failed internal consistency check"));