47 PyObject *py_obj_type);
82 new_data->worker = worker_data->
worker;
83 new_data->this_type = worker_data->
this_type;
84 Py_INCREF (new_data->worker);
85 Py_INCREF (new_data->this_type);
95 const char *xmethod_name)
101 if (enabled_field == NULL)
104 enabled = PyObject_IsTrue (enabled_field.
get ());
115 if (match_method == NULL)
118 gdbpy_ref<> py_xmethod_name (PyString_FromString (xmethod_name));
119 if (py_xmethod_name == NULL)
123 py_obj_type, py_xmethod_name.
get (),
132 struct type *obj_type,
const char *method_name,
133 xmethod_worker_vec **dm_vec)
137 PyObject *py_progspace;
139 gdb_assert (obj_type != NULL && method_name != NULL);
151 gdbpy_ref<> py_xmethod_matcher_list (PyList_New (0));
152 if (py_xmethod_matcher_list == NULL)
165 if (py_objfile == NULL)
172 gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.
get (),
173 objfile_matchers.
get ()));
180 py_xmethod_matcher_list = std::move (temp);
186 if (py_progspace != NULL)
190 gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.
get (),
191 pspace_matchers.
get ()));
198 py_xmethod_matcher_list = std::move (temp);
212 if (gdb_matchers != NULL)
214 gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.
get (),
215 gdb_matchers.
get ()));
222 py_xmethod_matcher_list = std::move (temp);
231 gdbpy_ref<> list_iter (PyObject_GetIter (py_xmethod_matcher_list.
get ()));
232 if (list_iter == NULL)
242 if (PyErr_Occurred ())
254 if (match_result == NULL)
259 if (match_result == Py_None)
261 else if (PySequence_Check (match_result.
get ()))
275 if (py_worker == NULL)
277 if (PyErr_Occurred ())
300 *dm_vec = worker_vec;
310 int *nargs,
struct type ***arg_types)
317 PyObject *py_worker = worker_data->
worker;
318 struct type *obj_type;
319 int i = 1, arg_count;
328 if (get_arg_types_method == NULL)
337 if (py_argtype_list == NULL)
343 if (py_argtype_list == Py_None)
345 else if (PySequence_Check (py_argtype_list.
get ()))
347 arg_count = PySequence_Size (py_argtype_list.
get ());
354 list_iter.reset (PyObject_GetIter (py_argtype_list.
get ()));
355 if (list_iter == NULL)
368 if (list_iter != NULL)
375 if (PyErr_Occurred ())
384 if (arg_type == NULL)
386 PyErr_SetString (PyExc_TypeError,
387 _(
"Arg type returned by the get_arg_types " 388 "method of a debug method worker object is " 389 "not a gdb.Type object."));
393 (type_array.get ())[i] = arg_type;
397 else if (arg_count == 1)
403 if (arg_type == NULL)
405 PyErr_SetString (PyExc_TypeError,
406 _(
"Arg type returned by the get_arg_types method " 407 "of an xmethod worker object is not a gdb.Type " 413 (type_array.get ())[i] = arg_type;
425 *arg_types = type_array.release ();
436 struct value **args,
int nargs,
437 struct type **result_type_ptr)
441 PyObject *py_worker = worker_data->
worker;
451 if (get_result_type_method == NULL)
454 *result_type_ptr = NULL;
469 struct type *this_ref
481 if (py_value_obj == NULL)
487 gdbpy_ref<> py_arg_tuple (PyTuple_New (nargs + 1));
488 if (py_arg_tuple == NULL)
496 PyTuple_SET_ITEM (py_arg_tuple.
get (), 0, py_value_obj.
release ());
498 for (i = 0; i < nargs; i++)
502 if (py_value_arg == NULL)
507 PyTuple_SET_ITEM (py_arg_tuple.
get (), i + 1, py_value_arg);
511 (PyObject_CallObject (get_result_type_method.
get (), py_arg_tuple.
get ()));
512 if (py_result_type == NULL)
519 if (*result_type_ptr == NULL)
521 PyErr_SetString (PyExc_TypeError,
522 _(
"Type returned by the get_result_type method of an" 523 " xmethod worker object is not a gdb.Type object."));
536 struct value *obj,
struct value **args,
int nargs)
539 struct type *obj_type, *this_type;
540 struct value *res = NULL;
558 struct type *this_ref
570 if (py_value_obj == NULL)
573 error (
_(
"Error while executing Python code."));
576 gdbpy_ref<> py_arg_tuple (PyTuple_New (nargs + 1));
577 if (py_arg_tuple == NULL)
580 error (
_(
"Error while executing Python code."));
585 PyTuple_SET_ITEM (py_arg_tuple.
get (), 0, py_value_obj.
release ());
587 for (i = 0; i < nargs; i++)
591 if (py_value_arg == NULL)
594 error (
_(
"Error while executing Python code."));
597 PyTuple_SET_ITEM (py_arg_tuple.
get (), i + 1, py_value_arg);
601 py_arg_tuple.
get ()));
602 if (py_result == NULL)
605 error (
_(
"Error while executing Python code."));
608 if (py_result != Py_None)
614 error (
_(
"Error while executing Python code."));
640 Py_INCREF (py_worker);
int gdbpy_initialize_xmethods(void)
void * gdbpy_clone_xmethod_worker_data(const struct extension_language_defn *extlang, void *data)
#define PyObject_GetAttrString(obj, attr)
PyObject * gdb_python_module
struct type * lookup_reference_type(struct type *type, enum type_code refcode)
const struct extension_language_defn * extlang
struct type * type_object_to_type(PyObject *obj)
PyObject * pspy_get_xmethods(PyObject *o, void *ignore)
enum ext_lang_rc gdbpy_get_xmethod_arg_types(const struct extension_language_defn *extlang, struct xmethod_worker *worker, int *nargs, struct type ***arg_types)
enum ext_lang_rc gdbpy_get_matching_xmethod_workers(const struct extension_language_defn *extlang, struct type *obj_type, const char *method_name, xmethod_worker_vec **dm_vec)
static const char enabled_field_name[]
#define VEC_safe_push(T, V, O)
static PyObject * py_match_method_name
const struct extension_language_defn extension_language_python
struct value * gdbpy_invoke_xmethod(const struct extension_language_defn *extlang, struct xmethod_worker *worker, struct value *obj, struct value **args, int nargs)
struct value * allocate_value(struct type *type)
#define TYPE_IS_REFERENCE(t)
struct type * lookup_typename(const struct language_defn *language, struct gdbarch *gdbarch, const char *name, const struct block *block, int noerr)
struct type * check_typedef(struct type *type)
static PyObject * py_get_arg_types_method_name
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
objfile(bfd *, const char *, objfile_flags)
PyObject * objfile_to_objfile_object(struct objfile *objfile)
static const char get_arg_types_method_name[]
struct gdbarch * get_current_arch(void)
struct gdbarch * python_gdbarch
PyObject * objfpy_get_xmethods(PyObject *o, void *ignore)
PyObject * value_to_value_object(struct value *val)
enum ext_lang_rc gdbpy_get_xmethod_result_type(const struct extension_language_defn *extlang, struct xmethod_worker *worker, struct value *obj, struct value **args, int nargs, struct type **result_type_ptr)
struct xmethod_worker * new_xmethod_worker(const struct extension_language_defn *extlang, void *data)
struct value * value_cast(struct type *type, struct value *arg2)
static struct xmethod_worker * new_python_xmethod_worker(PyObject *item, PyObject *py_obj_type)
static PyObject * invoke_match_method(PyObject *matcher, PyObject *py_obj_type, const char *xmethod_name)
int types_equal(struct type *a, struct type *b)
struct type * make_cv_type(int cnst, int voltl, struct type *type, struct type **typeptr)
const struct language_defn * current_language
#define TYPE_CODE(thistype)
void gdbpy_print_stack(void)
static const char matchers_attr_str[]
static const char match_method_name[]
struct value * convert_value_from_python(PyObject *obj)
void gdbpy_free_xmethod_worker_data(const struct extension_language_defn *extlang, void *data)
struct program_space * current_program_space
static const char get_result_type_method_name[]
struct type * value_type(const struct value *value)
const struct language_defn * python_language
#define ALL_OBJFILES(obj)
void error(const char *fmt,...)
struct type * lookup_pointer_type(struct type *type)
PyObject * pspace_to_pspace_object(struct program_space *pspace)
#define PyObject_HasAttrString(obj, attr)
PyObject * type_to_type_object(struct type *type)