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 ui_file *stream, int recurse, struct value *val, const struct value_print_options *options, const struct language_defn *language) { struct gdbarch *gdbarch = get_type_arch (type); struct value *value; enum string_repr_result print_result; if (value_lazy (val)) value_fetch_lazy (val); /* No pretty-printer support for unavailable values. */ if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type))) return EXT_LANG_RC_NOP; if (!gdb_python_initialized) return EXT_LANG_RC_NOP; 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)); if (val_obj == NULL) { print_stack_unless_memory_error (stream); return EXT_LANG_RC_ERROR; } /* Find the constructor. */ gdbpy_ref<> printer (find_pretty_printer (val_obj.get ())); if (printer == NULL) { print_stack_unless_memory_error (stream); return EXT_LANG_RC_ERROR; } if (printer == Py_None) return EXT_LANG_RC_NOP; /* If we are printing a map, we want some special formatting. */ gdb::unique_xmalloc_ptr<char> hint (gdbpy_get_display_hint (printer.get ())); /* Print the section */ print_result = print_string_repr (printer.get (), hint.get (), stream, recurse, options, language, gdbarch); if (print_result != string_repr_error) print_children (printer.get (), hint.get (), stream, recurse, options, language, print_result == string_repr_none); if (PyErr_Occurred ()) print_stack_unless_memory_error (stream); return EXT_LANG_RC_OK; }
static PyObject * convert_values_to_python (int argc, struct value **argv) { int i; gdbpy_ref<> result (PyTuple_New (argc)); if (result == NULL) return NULL; for (i = 0; i < argc; ++i) { gdbpy_ref<> elt (value_to_value_object (argv[i])); if (elt == NULL) return NULL; PyTuple_SetItem (result.get (), i, elt.release ()); } return result.release (); }
/* Given a value of a pointer type, apply the C unary * operator to it. */ static PyObject * valpy_dereference (PyObject *self, PyObject *args) { PyObject *result = NULL; TRY { struct value *res_val; struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ()); res_val = value_ind (((value_object *) self)->value); result = value_to_value_object (res_val); do_cleanups (cleanup); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); }
static PyObject * convert_values_to_python (int argc, struct value **argv) { int i; PyObject *result = PyTuple_New (argc); for (i = 0; i < argc; ++i) { PyObject *elt = value_to_value_object (argv[i]); if (! elt) { Py_DECREF (result); error (_("Could not convert value to Python object.")); } PyTuple_SetItem (result, i, elt); } return result; }
static PyObject * convert_values_to_python (int argc, struct value **argv) { int i; PyObject *result = PyTuple_New (argc); if (! result) return NULL; for (i = 0; i < argc; ++i) { PyObject *elt = value_to_value_object (argv[i]); if (! elt) { Py_DECREF (result); return NULL; } PyTuple_SetItem (result, i, elt); } return result; }
void bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj) { struct finish_breakpoint_object *self_finishbp = (struct finish_breakpoint_object *) bp_obj; /* Can compute return_value only once. */ gdb_assert (!self_finishbp->return_value); if (!self_finishbp->return_type) return; TRY { struct value *function = value_object_to_value (self_finishbp->function_value); struct type *value_type = type_object_to_type (self_finishbp->return_type); /* bpfinishpy_init cannot finish into DUMMY_FRAME (throws an error in such case) so it is OK to always pass CTX_SAVER as NULL. */ struct value *ret = get_return_value (function, value_type, NULL); if (ret) { self_finishbp->return_value = value_to_value_object (ret); if (!self_finishbp->return_value) gdbpy_print_stack (); } else { Py_INCREF (Py_None); self_finishbp->return_value = Py_None; } } CATCH (except, RETURN_MASK_ALL) { gdbpy_convert_exception (except); gdbpy_print_stack (); }
void bpfinishpy_pre_stop_hook (struct breakpoint_object *bp_obj) { struct finish_breakpoint_object *self_finishbp = (struct finish_breakpoint_object *) bp_obj; volatile struct gdb_exception except; /* Can compute return_value only once. */ gdb_assert (!self_finishbp->return_value); if (!self_finishbp->return_type) return; TRY_CATCH (except, RETURN_MASK_ALL) { struct value *function = value_object_to_value (self_finishbp->function_value); struct type *value_type = type_object_to_type (self_finishbp->return_type); struct value *ret = get_return_value (function, value_type); if (ret) { self_finishbp->return_value = value_to_value_object (ret); if (!self_finishbp->return_value) gdbpy_print_stack (); } else { Py_INCREF (Py_None); self_finishbp->return_value = Py_None; } } if (except.reason < 0) { gdbpy_convert_exception (except); gdbpy_print_stack (); } }
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; PyObject *val_obj = NULL; struct value *value; char *hint = NULL; struct cleanup *cleanups; 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 EXT_LANG_RC_NOP; if (!gdb_python_initialized) return EXT_LANG_RC_NOP; cleanups = ensure_python_env (gdbarch, language); /* Instantiate the printer. */ if (valaddr) valaddr += embedded_offset; value = value_from_contents_and_address (type, valaddr, address + embedded_offset); 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) { result = EXT_LANG_RC_ERROR; goto done; } /* Find the constructor. */ printer = find_pretty_printer (val_obj); Py_DECREF (val_obj); if (printer == NULL) { result = EXT_LANG_RC_ERROR; goto done; } make_cleanup_py_decref (printer); if (printer == Py_None) { result = EXT_LANG_RC_NOP; goto done; } /* If we are printing a map, we want some special formatting. */ hint = gdbpy_get_display_hint (printer); make_cleanup (free_current_contents, &hint); /* Print the section */ print_result = print_string_repr (printer, hint, stream, recurse, options, language, gdbarch); if (print_result != string_repr_error) print_children (printer, hint, stream, recurse, options, language, print_result == string_repr_none); result = EXT_LANG_RC_OK; done: if (PyErr_Occurred ()) print_stack_unless_memory_error (stream); do_cleanups (cleanups); return result; }
gdbpy_get_varobj_pretty_printer (struct value *value) { PyObject *val_obj; PyObject *pretty_printer = NULL; TRY { value = value_copy (value); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); } END_CATCH val_obj = value_to_value_object (value); if (! val_obj) return NULL; pretty_printer = find_pretty_printer (val_obj); Py_DECREF (val_obj); return pretty_printer; } /* A Python function which wraps find_pretty_printer and instantiates the resulting class. This accepts a Value argument and returns a pretty printer instance, or None. This function is useful as an argument to the MI command -var-set-visualizer. */ PyObject * gdbpy_default_visualizer (PyObject *self, PyObject *args) {