[arm] Add support for FPU registers in prologue unwinder
[binutils-gdb.git] / gdb / python / py-prettyprint.c
index 7cb20df7f26729b137d1499f9c8ce1ff61cf728a..c9bbd726412b1332c30a0c2aa7c7534711a87631 100644 (file)
@@ -1,6 +1,6 @@
 /* Python pretty-printing
 
-   Copyright (C) 2008-2020 Free Software Foundation, Inc.
+   Copyright (C) 2008-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -318,10 +318,10 @@ print_string_repr (PyObject *printer, const char *hint,
              type = builtin_type (gdbarch)->builtin_char;
 
              if (hint && !strcmp (hint, "string"))
-               LA_PRINT_STRING (stream, type, (gdb_byte *) output,
-                                length, NULL, 0, options);
+               language->printstr (stream, type, (gdb_byte *) output,
+                                   length, NULL, 0, options);
              else
-               fputs_filtered (output, stream);
+               gdb_puts (output, stream);
            }
          else
            {
@@ -425,27 +425,34 @@ print_children (PyObject *printer, const char *hint,
          /* The user won't necessarily get a stack trace here, so provide
             more context.  */
          if (gdbpy_print_python_errors_p ())
-           fprintf_unfiltered (gdb_stderr,
-                               _("Bad result from children iterator.\n"));
+           gdb_printf (gdb_stderr,
+                       _("Bad result from children iterator.\n"));
          gdbpy_print_stack ();
          continue;
        }
 
-      /* Print initial "{".  For other elements, there are three
-        cases:
+      /* Print initial "=" to separate print_string_repr output and
+        children.  For other elements, there are three cases:
         1. Maps.  Print a "," after each value element.
         2. Arrays.  Always print a ",".
         3. Other.  Always print a ",".  */
       if (i == 0)
        {
-         if (is_py_none)
-           fputs_filtered ("{", stream);
-         else
-           fputs_filtered (" = {", stream);
-       }
-
+         if (!is_py_none)
+           gdb_puts (" = ", stream);
+       }
       else if (! is_map || i % 2 == 0)
-       fputs_filtered (pretty ? "," : ", ", stream);
+       gdb_puts (pretty ? "," : ", ", stream);
+
+      /* Skip printing children if max_depth has been reached.  This check
+        is performed after print_string_repr and the "=" separator so that
+        these steps are not skipped if the variable is located within the
+        permitted depth.  */
+      if (val_print_check_max_depth (stream, recurse, options, language))
+       return;
+      else if (i == 0)
+       /* Print initial "{" to bookend children.  */
+       gdb_puts ("{", stream);
 
       /* In summary mode, we just want to print "= {...}" if there is
         a value.  */
@@ -463,26 +470,26 @@ print_children (PyObject *printer, const char *hint,
        {
          if (pretty)
            {
-             fputs_filtered ("\n", stream);
-             print_spaces_filtered (2 + 2 * recurse, stream);
+             gdb_puts ("\n", stream);
+             print_spaces (2 + 2 * recurse, stream);
            }
          else
-           wrap_here (n_spaces (2 + 2 *recurse));
+           stream->wrap_here (2 + 2 *recurse);
        }
 
       if (is_map && i % 2 == 0)
-       fputs_filtered ("[", stream);
+       gdb_puts ("[", stream);
       else if (is_array)
        {
          /* We print the index, not whatever the child method
             returned as the name.  */
          if (options->print_array_indexes)
-           fprintf_filtered (stream, "[%d] = ", i);
+           gdb_printf (stream, "[%d] = ", i);
        }
       else if (! is_map)
        {
-         fputs_filtered (name, stream);
-         fputs_filtered (" = ", stream);
+         gdb_puts (name, stream);
+         gdb_puts (" = ", stream);
        }
 
       if (gdbpy_is_lazy_string (py_v))
@@ -507,7 +514,7 @@ print_children (PyObject *printer, const char *hint,
          if (!output)
            gdbpy_print_stack ();
          else
-           fputs_filtered (output.get (), stream);
+           gdb_puts (output.get (), stream);
        }
       else
        {
@@ -533,7 +540,7 @@ print_children (PyObject *printer, const char *hint,
        }
 
       if (is_map && i % 2 == 0)
-       fputs_filtered ("] = ", stream);
+       gdb_puts ("] = ", stream);
     }
 
   if (i)
@@ -542,17 +549,17 @@ print_children (PyObject *printer, const char *hint,
        {
          if (pretty)
            {
-             fputs_filtered ("\n", stream);
-             print_spaces_filtered (2 + 2 * recurse, stream);
+             gdb_puts ("\n", stream);
+             print_spaces (2 + 2 * recurse, stream);
            }
-         fputs_filtered ("...", stream);
+         gdb_puts ("...", stream);
        }
       if (pretty)
        {
-         fputs_filtered ("\n", stream);
-         print_spaces_filtered (2 * recurse, stream);
+         gdb_puts ("\n", stream);
+         print_spaces (2 * recurse, stream);
        }
-      fputs_filtered ("}", stream);
+      gdb_puts ("}", stream);
     }
 }
 
@@ -564,7 +571,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
                                const struct language_defn *language)
 {
   struct type *type = value_type (value);
-  struct gdbarch *gdbarch = get_type_arch (type);
+  struct gdbarch *gdbarch = type->arch ();
   enum string_repr_result print_result;
 
   if (value_lazy (value))
@@ -597,9 +604,6 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
   if (printer == Py_None)
     return EXT_LANG_RC_NOP;
 
-  if (val_print_check_max_depth (stream, recurse, options, language))
-    return EXT_LANG_RC_OK;
-
   /* If we are printing a map, we want some special formatting.  */
   gdb::unique_xmalloc_ptr<char> hint (gdbpy_get_display_hint (printer.get ()));