/* 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.
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
{
/* 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. */
{
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))
if (!output)
gdbpy_print_stack ();
else
- fputs_filtered (output.get (), stream);
+ gdb_puts (output.get (), stream);
}
else
{
}
if (is_map && i % 2 == 0)
- fputs_filtered ("] = ", stream);
+ gdb_puts ("] = ", stream);
}
if (i)
{
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);
}
}
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))
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 ()));