This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v4 06/16] extension language API for GDB: pretty-printer changes
- From: Doug Evans <xdje42 at gmail dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 15 Jan 2014 11:25:23 -0800
- Subject: [PATCH v4 06/16] extension language API for GDB: pretty-printer changes
- Authentication-results: sourceware.org; auth=none
This patch updates the calls to the script-based pretty-printers.
I want to have something in the name of each extension language API entry point
that says "this is a extension languages API entry point". It makes the code
easier to understand. My first attempt had "slang_" as a prefix but that
was thought to cause too much confusion with the slang scripting language.
With the renaming to "extension" instead of "scripting" I've gone with
adding "ext_lang" to the name.
Plus for implementations of extension_language_ops methods I've made them
all have a consistent name: ${lang}_${method_name}.
And to follow convention for "ops" methods, they all take a "this"
parameter as the first argument.
Changes from v2:
- "method" gdbpy_apply_val_pretty_printer updated to return enum ext_lang_rc
- in cp-valprint.c, valprint.c, replace #include "python/python.h" with
"extension.h"
Changes from v1:
- updates for scripting -> extension renaming
2014-01-15 Doug Evans <xdje42@gmail.com>
* valprint.c (val_print, value_print): Update to call
apply_ext_lang_val_pretty_printer.
* cp-valprint.c (cp_print_value): Update call to
apply_ext_lang_val_pretty_printer.
* python/py-prettyprint.c: Remove #ifdef HAVE_PYTHON.
(gdbpy_apply_val_pretty_printer): Renamed from
apply_val_pretty_printer. New arg extlang.
(!HAVE_PYTHON, apply_val_pretty_printer): Delete.
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 01889c5..11e0120 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -32,7 +32,7 @@
#include "doublest.h"
#include "exceptions.h"
#include "dfp.h"
-#include "python/python.h"
+#include "extension.h"
#include "ada-lang.h"
#include "gdb_obstack.h"
#include "charset.h"
@@ -770,9 +770,9 @@ val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
if (!options->raw)
{
- ret = apply_val_pretty_printer (type, valaddr, embedded_offset,
- address, stream, recurse,
- val, options, language);
+ ret = apply_ext_lang_val_pretty_printer (type, valaddr, embedded_offset,
+ address, stream, recurse,
+ val, options, language);
if (ret)
return;
}
@@ -876,12 +876,13 @@ value_print (struct value *val, struct ui_file *stream,
if (!options->raw)
{
- int r = apply_val_pretty_printer (value_type (val),
- value_contents_for_printing (val),
- value_embedded_offset (val),
- value_address (val),
- stream, 0,
- val, options, current_language);
+ int r
+ = apply_ext_lang_val_pretty_printer (value_type (val),
+ value_contents_for_printing (val),
+ value_embedded_offset (val),
+ value_address (val),
+ stream, 0,
+ val, options, current_language);
if (r)
return;
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index abcc4fc..2d366b9 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -34,7 +34,7 @@
#include "valprint.h"
#include "cp-support.h"
#include "language.h"
-#include "python/python.h"
+#include "extension.h"
#include "exceptions.h"
#include "typeprint.h"
@@ -584,17 +584,17 @@ cp_print_value (struct type *type, struct type *real_type,
{
int result = 0;
- /* Attempt to run the Python pretty-printers on the
+ /* Attempt to run an extension language pretty-printer on the
baseclass if possible. */
if (!options->raw)
- result = apply_val_pretty_printer (baseclass, base_valaddr,
- thisoffset + boffset,
- value_address (base_val),
- stream, recurse, base_val,
- options, current_language);
+ result
+ = apply_ext_lang_val_pretty_printer (baseclass, base_valaddr,
+ thisoffset + boffset,
+ value_address (base_val),
+ stream, recurse,
+ base_val, options,
+ current_language);
-
-
if (!result)
cp_print_value_fields (baseclass, thistype, base_valaddr,
thisoffset + boffset,
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 879f0de..a7cd337 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -23,10 +23,8 @@
#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 */