/* 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.
#include "extension-priv.h"
#include "python.h"
#include "python-internal.h"
+#include "cli/cli-style.h"
/* Return type of print_string_repr. */
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 ();
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);
}
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)
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)
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)
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);
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 ()));