50 Py_ssize_t pp_list_size, list_index;
51 PyObject *
function, *printer = NULL;
53 pp_list_size = PyList_Size (list);
54 for (list_index = 0; list_index < pp_list_size; list_index++)
56 function = PyList_GetItem (list, list_index);
68 cmp = PyObject_IsTrue (attr);
77 printer = PyObject_CallFunctionObjArgs (
function, value, NULL);
80 else if (printer != Py_None)
114 Py_XDECREF (pp_list);
120 if (
function != Py_None)
146 Py_XDECREF (pp_list);
167 if (pp_list == NULL || ! PyList_Check (pp_list))
169 Py_XDECREF (pp_list);
174 Py_XDECREF (pp_list);
190 if (
function == NULL ||
function != Py_None)
196 if (
function == NULL ||
function != Py_None)
216 PyObject *result = NULL;
225 && result != Py_None)
228 if (PyErr_Occurred ())
284 PyErr_Fetch (&type, &value, &trace);
292 if (msg == NULL || *msg ==
'\0')
308 struct ui_file *stream,
int recurse,
313 struct value *replacement = NULL;
314 PyObject *py_str = NULL;
322 if (py_str == Py_None)
338 stream, &local_opts);
353 output = PyBytes_AS_STRING (
string);
354 length = PyBytes_GET_SIZE (
string);
356 output = PyString_AsString (
string);
357 length = PyString_Size (
string);
361 if (hint && !strcmp (hint,
"string"))
363 length, NULL, 0, options);
376 else if (replacement)
396 PyFrameObject *frame = p;
397 PyThreadState *tstate = PyThreadState_GET ();
399 tstate->frame = frame;
407 PyObject *empty_string, *null_tuple, *globals;
409 PyFrameObject *frame;
410 PyThreadState *tstate;
412 empty_string = PyString_FromString (
"");
416 null_tuple = PyTuple_New (0);
423 code = PyCode_New (0,
431 #
if PYTHON_API_VERSION >= 1010
447 globals = PyDict_New ();
454 tstate = PyThreadState_GET ();
456 frame = PyFrame_New (tstate, code, globals, NULL);
464 tstate->frame = frame;
466 return (PyObject *) frame;
475 struct ui_file *stream,
int recurse,
480 int is_map, is_array, done_flag, pretty;
482 PyObject *children, *iter;
493 is_map = hint && ! strcmp (hint,
"map");
494 is_array = hint && ! strcmp (hint,
"array");
506 iter = PyObject_GetIter (children);
542 PyObject *py_v, *item = PyIter_Next (iter);
548 if (PyErr_Occurred ())
557 if (! PyTuple_Check (item) || PyTuple_Size (item) != 2)
559 PyErr_SetString (PyExc_TypeError,
560 _(
"Result of children iterator not a tuple"
561 " of two elements."));
566 if (! PyArg_ParseTuple (item,
"sO", &name, &py_v))
572 _(
"Bad result from children iterator.\n"));
592 else if (! is_map || i % 2 == 0)
607 if (! is_map || i % 2 == 0)
618 if (is_map && i % 2 == 0)
668 error (
_(
"Error while executing Python code."));
674 if (is_map && i % 2 == 0)
707 struct ui_file *stream,
int recurse,
708 const struct value *val,
713 PyObject *printer = NULL;
714 PyObject *val_obj = NULL;
732 valaddr += embedded_offset;
734 address + embedded_offset);
762 if (printer == Py_None)
774 options, language, gdbarch);
776 print_children (printer, hint, stream, recurse, options, language,
782 if (PyErr_Occurred ())
800 struct value **replacement,
803 PyObject *py_str = NULL;
808 if (*replacement == NULL && py_str == NULL)
822 PyObject *pretty_printer = NULL;
840 return pretty_printer;
854 if (! PyArg_ParseTuple (args,
"O", &val_obj))
859 PyErr_SetString (PyExc_TypeError,
860 _(
"Argument must be a gdb.Value."));
static PyObject * find_pretty_printer_from_gdb(PyObject *value)
char * gdbpy_get_display_hint(PyObject *printer)
#define PyObject_GetAttrString(obj, attr)
PyObject * gdb_python_module
static void print_stack_unless_memory_error(struct ui_file *stream)
struct value * value_from_contents_and_address(struct type *type, const gdb_byte *valaddr, CORE_ADDR address)
static PyObject * find_pretty_printer_from_progspace(PyObject *value)
int gdbpy_is_string(PyObject *obj)
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
void common_val_print(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
PyObject * gdbpy_to_string_cst
PyObject * apply_varobj_pretty_printer(PyObject *printer_obj, struct value **replacement, struct ui_file *stream)
PyObject * python_string_to_target_python_string(PyObject *obj)
struct value * value_copy(struct value *arg)
PyObject * gdbpy_display_hint_cst
enum val_prettyformat prettyformat
void set_value_address(struct value *value, CORE_ADDR addr)
#define GDB_PY_HANDLE_EXCEPTION(Exception)
#define ALL_OBJFILES(obj)
#define CATCH(EXCEPTION, MASK)
static PyObject * push_dummy_python_frame(void)
PyObject * gdbpy_enabled_cst
void fprintf_filtered(struct ui_file *stream, const char *format,...)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
void fputs_filtered(const char *linebuffer, struct ui_file *stream)
int gdbpy_print_python_errors_p(void)
void free_current_contents(void *ptr)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
char * python_string_to_host_string(PyObject *obj)
PyObject * objfile_to_objfile_object(struct objfile *objfile)
struct gdbarch * get_type_arch(const struct type *type)
struct cleanup * ensure_python_env(struct gdbarch *gdbarch, const struct language_defn *language)
PyObject * value_to_value_object(struct value *val)
int gdb_python_initialized
static void py_restore_tstate(void *p)
void wrap_here(char *indent)
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)
void print_spaces_filtered(int n, struct ui_file *stream)
struct type * builtin_char
PyObject * gdbpy_children_cst
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, int is_py_none)
static PyObject * find_pretty_printer(PyObject *value)
PyObject * gdbpy_default_visualizer(PyObject *self, PyObject *args)
struct ui_file * gdb_stderr
static PyObject * pretty_print_one_value(PyObject *printer, struct value **out_value)
PyObject * objfpy_get_printers(PyObject *o, void *ignore)
void gdbpy_print_stack(void)
struct value * convert_value_from_python(PyObject *obj)
int value_bytes_available(const struct value *value, int offset, int length)
int gdbpy_is_lazy_string(PyObject *result)
PyObject * gdbpy_gdb_memory_error
struct program_space * current_program_space
static enum string_repr_result print_string_repr(PyObject *printer, const char *hint, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language, struct gdbarch *gdbarch)
#define LA_PRINT_STRING(stream, elttype, string, length, encoding, force_ellipses, options)
struct value * value_object_to_value(PyObject *self)
static PyObject * search_pp_list(PyObject *list, PyObject *value)
#define TYPE_LENGTH(thistype)
int val_print_string(struct type *elttype, const char *encoding, CORE_ADDR addr, int len, struct ui_file *stream, const struct value_print_options *options)
struct cleanup * make_cleanup_py_decref(PyObject *py)
void gdbpy_extract_lazy_string(PyObject *string, CORE_ADDR *addr, struct type **str_type, long *length, char **encoding)
PyObject * gdbpy_get_varobj_pretty_printer(struct value *value)
static PyObject * find_pretty_printer_from_objfiles(PyObject *value)
void error(const char *fmt,...)
PyObject * pspace_to_pspace_object(struct program_space *pspace)
#define PyObject_HasAttrString(obj, attr)
char * gdbpy_exception_to_string(PyObject *ptype, PyObject *pvalue)
PyObject * pspy_get_printers(PyObject *o, void *ignore)
void do_cleanups(struct cleanup *old_chain)
void set_value_component_location(struct value *component, const struct value *whole)