gdb: remove some uses of LA_PRINT_STRING
[deliverable/binutils-gdb.git] / gdb / python / py-prettyprint.c
index 7760cab0ae07c4d42897e6345e30a640fec6535a..6300cb0bc5732b1cc09afb661bbe4724bafa62ee 100644 (file)
@@ -1,6 +1,6 @@
 /* Python pretty-printing
 
-   Copyright (C) 2008-2019 Free Software Foundation, Inc.
+   Copyright (C) 2008-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -25,6 +25,7 @@
 #include "extension-priv.h"
 #include "python.h"
 #include "python-internal.h"
+#include "cli/cli-style.h"
 
 /* Return type of print_string_repr.  */
 
@@ -259,10 +260,11 @@ print_stack_unless_memory_error (struct ui_file *stream)
       gdb::unique_xmalloc_ptr<char> msg = fetched_error.to_string ();
 
       if (msg == NULL || *msg == '\0')
-       fprintf_filtered (stream, _("<error reading variable>"));
+       fprintf_styled (stream, metadata_style.style (),
+                       _("<error reading variable>"));
       else
-       fprintf_filtered (stream, _("<error reading variable: %s>"),
-                         msg.get ());
+       fprintf_styled (stream, metadata_style.style (),
+                       _("<error reading variable: %s>"), msg.get ());
     }
   else
     gdbpy_print_stack ();
@@ -316,8 +318,8 @@ 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);
            }
@@ -436,10 +438,10 @@ print_children (PyObject *printer, const char *hint,
         3. Other.  Always print a ",".  */
       if (i == 0)
        {
-         if (is_py_none)
-           fputs_filtered ("{", stream);
-         else
-           fputs_filtered (" = {", stream);
+        if (is_py_none)
+          fputs_filtered ("{", stream);
+        else
+          fputs_filtered (" = {", stream);
        }
 
       else if (! is_map || i % 2 == 0)
@@ -517,7 +519,17 @@ print_children (PyObject *printer, const char *hint,
              error (_("Error while executing Python code."));
            }
          else
-           common_val_print (value, stream, recurse + 1, options, language);
+           {
+             /* When printing the key of a map we allow one additional
+                level of depth.  This means the key will print before the
+                value does.  */
+             struct value_print_options opt = *options;
+             if (is_map && i % 2 == 0
+                 && opt.max_depth != -1
+                 && opt.max_depth < INT_MAX)
+               ++opt.max_depth;
+             common_val_print (value, stream, recurse + 1, &opt, language);
+           }
        }
 
       if (is_map && i % 2 == 0)
@@ -546,22 +558,20 @@ print_children (PyObject *printer, const char *hint,
 
 enum ext_lang_rc
 gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
-                               struct type *type,
-                               LONGEST embedded_offset, CORE_ADDR address,
+                               struct value *value,
                                struct ui_file *stream, int recurse,
-                               struct value *val,
                                const struct value_print_options *options,
                                const struct language_defn *language)
 {
+  struct type *type = value_type (value);
   struct gdbarch *gdbarch = get_type_arch (type);
-  struct value *value;
   enum string_repr_result print_result;
 
-  if (value_lazy (val))
-    value_fetch_lazy (val);
+  if (value_lazy (value))
+    value_fetch_lazy (value);
 
   /* No pretty-printer support for unavailable values.  */
-  if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
+  if (!value_bytes_available (value, 0, TYPE_LENGTH (type)))
     return EXT_LANG_RC_NOP;
 
   if (!gdb_python_initialized)
@@ -569,10 +579,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
 
   gdbpy_enter enter_py (gdbarch, language);
 
-  /* Instantiate the printer.  */
-  value = value_from_component (val, type, embedded_offset);
-
-  gdbpy_ref<> val_obj (value_to_value_object (value));
+  gdbpy_ref<> val_obj (value_to_value_object_no_release (value));
   if (val_obj == NULL)
     {
       print_stack_unless_memory_error (stream);
@@ -590,6 +597,9 @@ 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 ()));
 
This page took 0.026484 seconds and 4 git commands to generate.