diff options
author | Phil Muldoon <pmuldoon@redhat.com> | 2010-04-14 12:02:46 +0000 |
---|---|---|
committer | Phil Muldoon <pmuldoon@redhat.com> | 2010-04-14 12:02:46 +0000 |
commit | 79f283fe85c2bc28eb97695c591e3c95423a32c8 (patch) | |
tree | 6c049ff109642b7f44397fd3977465e7193c02af /gdb/python | |
parent | d594eacc9ee9f3135b25e86834ef271d68ed0bd2 (diff) | |
download | gdb-79f283fe85c2bc28eb97695c591e3c95423a32c8.zip gdb-79f283fe85c2bc28eb97695c591e3c95423a32c8.tar.gz gdb-79f283fe85c2bc28eb97695c591e3c95423a32c8.tar.bz2 |
2010-04-14 Phil Muldoon <pmuldoon@redhat.com>
PR python/11381
* python/py-prettyprint.c (pretty_print_one_value): Test for
Py_None.
(print_string_repr): Test for Py_None. Set flags accordingly.
Return value depending on return type.
(print_children): Take a value indicating whether data was printed
before this function was called. Alter output accordingly.
(apply_val_pretty_printer): Capture return value from
print_string_repr and pass to print_children.
2010-04-14 Phil Muldoon <pmuldoon@redhat.com>
* gdb.python/py-prettyprint.py (NoStringContainerPrinter): New printer.
* gdb.python/py-prettyprint.c: Add justchildren struct, typedefs.
* gdb.python/py-prettyprint.exp: New test for to_string returning None.
* gdb.python/py-mi.exp: New test for to_string returning None.
2010-04-14 Phil Muldoon <pmuldoon@redhat.com>
* gdb.texinfo (Pretty Printing): Document behaviour when to_string
returns None.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-prettyprint.c | 117 |
1 files changed, 71 insertions, 46 deletions
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index 454aa5a..5c3757c 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -125,9 +125,12 @@ find_pretty_printer (PyObject *value) /* Pretty-print a single value, via the printer object PRINTER. If the function returns a string, a PyObject containing the string - is returned. Otherwise, if the function returns a value, - *OUT_VALUE is set to the value, and NULL is returned. On error, - *OUT_VALUE is set to NULL, and NULL is returned. */ + is returned. If the function returns Py_NONE that means the pretty + printer returned the Python None as a value. Otherwise, if the + function returns a value, *OUT_VALUE is set to the value, and NULL + is returned. On error, *OUT_VALUE is set to NULL, and NULL is + returned. */ + static PyObject * pretty_print_one_value (PyObject *printer, struct value **out_value) { @@ -140,7 +143,8 @@ pretty_print_one_value (PyObject *printer, struct value **out_value) result = PyObject_CallMethodObjArgs (printer, gdbpy_to_string_cst, NULL); if (result) { - if (! gdbpy_is_string (result) && ! gdbpy_is_lazy_string (result)) + if (! gdbpy_is_string (result) && ! gdbpy_is_lazy_string (result) + && result != Py_None) { *out_value = convert_value_from_python (result); if (PyErr_Occurred ()) @@ -179,8 +183,11 @@ gdbpy_get_display_hint (PyObject *printer) } /* Helper for apply_val_pretty_printer which calls to_string and - formats the result. */ -static void + formats the result. If the value returnd is Py_None, nothing is + printed and the function returns a 1; in all other cases data is + printed as given by the pretty printer and the function returns 0. +*/ +static int print_string_repr (PyObject *printer, const char *hint, struct ui_file *stream, int recurse, const struct value_print_options *options, @@ -189,52 +196,58 @@ print_string_repr (PyObject *printer, const char *hint, { struct value *replacement = NULL; PyObject *py_str = NULL; + int is_py_none = 0; py_str = pretty_print_one_value (printer, &replacement); if (py_str) { - gdb_byte *output = NULL; - long length; - struct type *type; - char *encoding = NULL; - PyObject *string = NULL; - int is_lazy; - - is_lazy = gdbpy_is_lazy_string (py_str); - if (is_lazy) - output = gdbpy_extract_lazy_string (py_str, &type, &length, &encoding); + if (py_str == Py_None) + is_py_none = 1; else { - string = python_string_to_target_python_string (py_str); - if (string) + gdb_byte *output = NULL; + long length; + struct type *type; + char *encoding = NULL; + PyObject *string = NULL; + int is_lazy; + + is_lazy = gdbpy_is_lazy_string (py_str); + if (is_lazy) + output = gdbpy_extract_lazy_string (py_str, &type, &length, &encoding); + else { - output = PyString_AsString (string); - length = PyString_Size (string); - type = builtin_type (gdbarch)->builtin_char; + string = python_string_to_target_python_string (py_str); + if (string) + { + output = PyString_AsString (string); + length = PyString_Size (string); + type = builtin_type (gdbarch)->builtin_char; + } + else + gdbpy_print_stack (); + + } + + if (output) + { + if (is_lazy || (hint && !strcmp (hint, "string"))) + LA_PRINT_STRING (stream, type, output, length, encoding, + 0, options); + else + fputs_filtered (output, stream); } else gdbpy_print_stack (); - } - - if (output) - { - if (is_lazy || (hint && !strcmp (hint, "string"))) - LA_PRINT_STRING (stream, type, output, length, encoding, - 0, options); + if (string) + Py_DECREF (string); else - fputs_filtered (output, stream); - } - else - gdbpy_print_stack (); + xfree (output); - if (string) - Py_DECREF (string); - else - xfree (output); - - xfree (encoding); - Py_DECREF (py_str); + xfree (encoding); + Py_DECREF (py_str); + } } else if (replacement) { @@ -245,6 +258,8 @@ print_string_repr (PyObject *printer, const char *hint, } else gdbpy_print_stack (); + + return is_py_none; } static void @@ -323,12 +338,14 @@ push_dummy_python_frame () } /* Helper for apply_val_pretty_printer that formats children of the - printer, if any exist. */ + printer, if any exist. If is_py_none is true, then nothing has + been printed by to_string, and format output accordingly. */ static void print_children (PyObject *printer, const char *hint, struct ui_file *stream, int recurse, const struct value_print_options *options, - const struct language_defn *language) + const struct language_defn *language, + int is_py_none) { int is_map, is_array, done_flag, pretty; unsigned int i; @@ -408,7 +425,13 @@ print_children (PyObject *printer, const char *hint, 2. Arrays. Always print a ",". 3. Other. Always print a ",". */ if (i == 0) - fputs_filtered (" = {", stream); + { + if (is_py_none) + fputs_filtered ("{", stream); + else + fputs_filtered (" = {", stream); + } + else if (! is_map || i % 2 == 0) fputs_filtered (pretty ? "," : ", ", stream); @@ -532,7 +555,7 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr, char *hint = NULL; struct cleanup *cleanups; int result = 0; - + int is_py_none = 0; cleanups = ensure_python_env (gdbarch, language); /* Instantiate the printer. */ @@ -557,9 +580,11 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr, make_cleanup (free_current_contents, &hint); /* Print the section */ - print_string_repr (printer, hint, stream, recurse, options, language, - gdbarch); - print_children (printer, hint, stream, recurse, options, language); + is_py_none = print_string_repr (printer, hint, stream, recurse, + options, language, gdbarch); + print_children (printer, hint, stream, recurse, options, language, + is_py_none); + result = 1; |