if (! function)
return NULL;
+ /* Skip if disabled. */
+ if (PyObject_HasAttr (function, gdbpy_enabled_cst))
+ {
+ PyObject *attr = PyObject_GetAttr (function, gdbpy_enabled_cst);
+ int cmp;
+
+ if (!attr)
+ return NULL;
+ cmp = PyObject_IsTrue (attr);
+ if (cmp == -1)
+ return NULL;
+
+ if (!cmp)
+ continue;
+ }
+
printer = PyObject_CallFunctionObjArgs (function, value, NULL);
if (! printer)
return NULL;
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. */
+ is returned. On error, *OUT_VALUE is set to NULL, NULL is
+ returned, with a python exception set. */
static PyObject *
pretty_print_one_value (PyObject *printer, struct value **out_value)
return NULL;
hint = PyObject_CallMethodObjArgs (printer, gdbpy_display_hint_cst, NULL);
- if (gdbpy_is_string (hint))
- result = python_string_to_host_string (hint);
if (hint)
- Py_DECREF (hint);
+ {
+ if (gdbpy_is_string (hint))
+ {
+ result = python_string_to_host_string (hint);
+ if (result == NULL)
+ gdbpy_print_stack ();
+ }
+ Py_DECREF (hint);
+ }
else
gdbpy_print_stack ();
py_str = pretty_print_one_value (printer, &replacement);
if (py_str)
{
+ struct cleanup *cleanup = make_cleanup_py_decref (py_str);
+
if (py_str == Py_None)
is_py_none = 1;
- else
+ else if (gdbpy_is_lazy_string (py_str))
{
- gdb_byte *output = NULL;
+ CORE_ADDR addr;
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
- {
- 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)
+ make_cleanup (free_current_contents, &encoding);
+ gdbpy_extract_lazy_string (py_str, &addr, &type,
+ &length, &encoding);
+
+ val_print_string (type, encoding, addr, (int) length,
+ stream, options);
+ }
+ else
+ {
+ PyObject *string;
+
+ string = python_string_to_target_python_string (py_str);
+ if (string)
{
- if (is_lazy || (hint && !strcmp (hint, "string")))
- LA_PRINT_STRING (stream, type, output, length, encoding,
+ gdb_byte *output;
+ long length;
+ struct type *type;
+
+ make_cleanup_py_decref (string);
+ output = PyString_AsString (string);
+ length = PyString_Size (string);
+ type = builtin_type (gdbarch)->builtin_char;
+
+ if (hint && !strcmp (hint, "string"))
+ LA_PRINT_STRING (stream, type, output, length, NULL,
0, options);
else
fputs_filtered (output, stream);
}
else
gdbpy_print_stack ();
-
- if (string)
- Py_DECREF (string);
- else
- xfree (output);
-
- xfree (encoding);
- Py_DECREF (py_str);
}
+
+ do_cleanups (cleanup);
}
else if (replacement)
{
fputs_filtered (" = ", stream);
}
- if (gdbpy_is_lazy_string (py_v) || gdbpy_is_string (py_v))
+ if (gdbpy_is_lazy_string (py_v))
{
- gdb_byte *output = NULL;
+ CORE_ADDR addr;
+ struct type *type;
+ long length;
+ char *encoding = NULL;
- if (gdbpy_is_lazy_string (py_v))
- {
- struct type *type;
- long length;
- char *encoding = NULL;
-
- output = gdbpy_extract_lazy_string (py_v, &type,
- &length, &encoding);
- if (!output)
- gdbpy_print_stack ();
- LA_PRINT_STRING (stream, type, output, length, encoding,
- 0, options);
- xfree (encoding);
- xfree (output);
- }
+ make_cleanup (free_current_contents, &encoding);
+ gdbpy_extract_lazy_string (py_v, &addr, &type, &length, &encoding);
+
+ val_print_string (type, encoding, addr, (int) length, stream,
+ options);
+
+ do_cleanups (inner_cleanup);
+ }
+ else if (gdbpy_is_string (py_v))
+ {
+ gdb_byte *output;
+
+ output = python_string_to_host_string (py_v);
+ if (!output)
+ gdbpy_print_stack ();
else
{
- output = python_string_to_host_string (py_v);
fputs_filtered (output, stream);
xfree (output);
}
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)
{
valaddr += embedded_offset;
value = value_from_contents_and_address (type, valaddr,
address + embedded_offset);
+ if (val != NULL)
+ {
+ set_value_component_location (value, val);
+ /* set_value_component_location resets the address, so we may
+ need to set it again. */
+ if (VALUE_LVAL (value) != lval_internalvar
+ && VALUE_LVAL (value) != lval_internalvar_component
+ && VALUE_LVAL (value) != lval_computed)
+ set_value_address (value, address + embedded_offset);
+ }
val_obj = value_to_value_object (value);
if (! val_obj)
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)
{