Extension Language API
[deliverable/binutils-gdb.git] / gdb / python / py-prettyprint.c
index 879f0dee009a79bbccd5d33cd0429bf2f6c96ae6..a7cd337d00b4c9bb405b0f97f70ffc28c3b9aa75 100644 (file)
 #include "symtab.h"
 #include "language.h"
 #include "valprint.h"
-
+#include "extension-priv.h"
 #include "python.h"
-
-#ifdef HAVE_PYTHON
 #include "python-internal.h"
 
 /* Return type of print_string_repr.  */
@@ -300,7 +298,7 @@ print_stack_unless_memory_error (struct ui_file *stream)
     gdbpy_print_stack ();
 }
 
-/* Helper for apply_val_pretty_printer which calls to_string and
+/* Helper for gdbpy_apply_val_pretty_printer which calls to_string and
    formats the result.  */
 
 static enum string_repr_result
@@ -467,7 +465,7 @@ push_dummy_python_frame (void)
 }
 #endif
 
-/* Helper for apply_val_pretty_printer that formats children of the
+/* Helper for gdbpy_apply_val_pretty_printer that formats children of the
    printer, if any exist.  If is_py_none is true, then nothing has
    been printed by to_string, and format output accordingly. */
 static void
@@ -686,13 +684,14 @@ print_children (PyObject *printer, const char *hint,
   do_cleanups (cleanups);
 }
 
-int
-apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
-                         int embedded_offset, CORE_ADDR address,
-                         struct ui_file *stream, int recurse,
-                         const struct value *val,
-                         const struct value_print_options *options,
-                         const struct language_defn *language)
+enum ext_lang_rc
+gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
+                               struct type *type, const gdb_byte *valaddr,
+                               int embedded_offset, CORE_ADDR address,
+                               struct ui_file *stream, int recurse,
+                               const struct value *val,
+                               const struct value_print_options *options,
+                               const struct language_defn *language)
 {
   struct gdbarch *gdbarch = get_type_arch (type);
   PyObject *printer = NULL;
@@ -700,15 +699,15 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
   struct value *value;
   char *hint = NULL;
   struct cleanup *cleanups;
-  int result = 0;
+  enum ext_lang_rc result = EXT_LANG_RC_NOP;
   enum string_repr_result print_result;
 
   /* No pretty-printer support for unavailable values.  */
   if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
-    return 0;
+    return EXT_LANG_RC_NOP;
 
   if (!gdb_python_initialized)
-    return 0;
+    return EXT_LANG_RC_NOP;
 
   cleanups = ensure_python_env (gdbarch, language);
 
@@ -728,18 +727,27 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
 
   val_obj = value_to_value_object (value);
   if (! val_obj)
-    goto done;
+    {
+      result = EXT_LANG_RC_ERROR;
+      goto done;
+    }
 
   /* Find the constructor.  */
   printer = find_pretty_printer (val_obj);
   Py_DECREF (val_obj);
 
   if (printer == NULL)
-    goto done;
+    {
+      result = EXT_LANG_RC_ERROR;
+      goto done;
+    }
 
   make_cleanup_py_decref (printer);
   if (printer == Py_None)
-    goto done;
+    {
+      result = EXT_LANG_RC_NOP;
+      goto done;
+    }
 
   /* If we are printing a map, we want some special formatting.  */
   hint = gdbpy_get_display_hint (printer);
@@ -752,8 +760,7 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
     print_children (printer, hint, stream, recurse, options, language,
                    print_result == string_repr_none);
 
-  result = 1;
-
+  result = EXT_LANG_RC_OK;
 
  done:
   if (PyErr_Occurred ())
@@ -838,18 +845,3 @@ gdbpy_default_visualizer (PyObject *self, PyObject *args)
   cons = find_pretty_printer (val_obj);
   return cons;
 }
-
-#else /* HAVE_PYTHON */
-
-int
-apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
-                         int embedded_offset, CORE_ADDR address,
-                         struct ui_file *stream, int recurse,
-                         const struct value *val,
-                         const struct value_print_options *options,
-                         const struct language_defn *language)
-{
-  return 0;
-}
-
-#endif /* HAVE_PYTHON */
This page took 0.02806 seconds and 4 git commands to generate.