61 type **result_type_ptr)
override;
83 const char *xmethod_name)
87 gdbpy_ref<> enabled_field (PyObject_GetAttrString (matcher,
89 if (enabled_field == NULL)
92 enabled = PyObject_IsTrue (enabled_field.get ());
101 gdbpy_ref<> match_method (PyObject_GetAttrString (matcher,
103 if (match_method == NULL)
106 gdbpy_ref<> py_xmethod_name (PyUnicode_FromString (xmethod_name));
107 if (py_xmethod_name == NULL)
111 py_obj_type, py_xmethod_name.get (),
120 struct type *obj_type,
const char *method_name,
121 std::vector<xmethod_worker_up> *dm_vec)
123 gdb_assert (obj_type != NULL && method_name != NULL);
135 gdbpy_ref<> py_xmethod_matcher_list (PyList_New (0));
136 if (py_xmethod_matcher_list == NULL)
149 if (py_objfile == NULL)
157 gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
158 objfile_matchers.get ()));
165 py_xmethod_matcher_list = std::move (temp);
171 if (py_progspace != NULL)
176 gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
177 pspace_matchers.get ()));
184 py_xmethod_matcher_list = std::move (temp);
198 if (gdb_matchers != NULL)
200 gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
201 gdb_matchers.get ()));
208 py_xmethod_matcher_list = std::move (temp);
217 gdbpy_ref<> list_iter (PyObject_GetIter (py_xmethod_matcher_list.get ()));
218 if (list_iter == NULL)
225 gdbpy_ref<> matcher (PyIter_Next (list_iter.get ()));
228 if (PyErr_Occurred ())
240 if (match_result == NULL)
245 if (match_result == Py_None)
247 else if (PySequence_Check (match_result.get ()))
249 gdbpy_ref<> iter (PyObject_GetIter (match_result.get ()));
261 if (py_worker == NULL)
263 if (PyErr_Occurred ())
274 dm_vec->emplace_back (worker);
283 dm_vec->emplace_back (worker);
298 struct type *obj_type;
299 int i = 1, arg_count;
304 if (get_arg_types_method == NULL)
313 if (py_argtype_list == NULL)
319 if (py_argtype_list == Py_None)
321 else if (PySequence_Check (py_argtype_list.get ()))
323 arg_count = PySequence_Size (py_argtype_list.get ());
330 list_iter.reset (PyObject_GetIter (py_argtype_list.get ()));
331 if (list_iter == NULL)
341 arg_types->resize (arg_count + 1);
343 if (list_iter != NULL)
350 if (PyErr_Occurred ())
359 if (arg_type == NULL)
361 PyErr_SetString (PyExc_TypeError,
362 _(
"Arg type returned by the get_arg_types "
363 "method of a debug method worker object is "
364 "not a gdb.Type object."));
368 (*arg_types)[i] = arg_type;
372 else if (arg_count == 1)
378 if (arg_type == NULL)
380 PyErr_SetString (PyExc_TypeError,
381 _(
"Arg type returned by the get_arg_types method "
382 "of an xmethod worker object is not a gdb.Type "
388 (*arg_types)[i] = arg_type;
407 gdb::array_view<value *> args,
408 type **result_type_ptr)
410 struct type *obj_type, *this_type;
419 if (get_result_type_method == NULL)
422 *result_type_ptr = NULL;
429 if (obj_type->
code () == TYPE_CODE_PTR)
438 struct type *this_ref
450 if (py_value_obj == NULL)
456 gdbpy_ref<> py_arg_tuple (PyTuple_New (args.size () + 1));
457 if (py_arg_tuple == NULL)
465 PyTuple_SET_ITEM (py_arg_tuple.get (), 0, py_value_obj.release ());
467 for (i = 0; i < args.size (); i++)
471 if (py_value_arg == NULL)
476 PyTuple_SET_ITEM (py_arg_tuple.get (), i + 1, py_value_arg);
480 (PyObject_CallObject (get_result_type_method.get (), py_arg_tuple.get ()));
481 if (py_result_type == NULL)
488 if (*result_type_ptr == NULL)
490 PyErr_SetString (PyExc_TypeError,
491 _(
"Type returned by the get_result_type method of an"
492 " xmethod worker object is not a gdb.Type object."));
504 gdb::array_view<value *> args)
509 struct type *obj_type, *this_type;
510 struct value *res = NULL;
514 if (obj_type->
code () == TYPE_CODE_PTR)
523 struct type *this_ref
535 if (py_value_obj == NULL)
538 error (_(
"Error while executing Python code."));
541 gdbpy_ref<> py_arg_tuple (PyTuple_New (args.size () + 1));
542 if (py_arg_tuple == NULL)
545 error (_(
"Error while executing Python code."));
550 PyTuple_SET_ITEM (py_arg_tuple.get (), 0, py_value_obj.release ());
552 for (i = 0; i < args.size (); i++)
556 if (py_value_arg == NULL)
559 error (_(
"Error while executing Python code."));
562 PyTuple_SET_ITEM (py_arg_tuple.get (), i + 1, py_value_arg);
566 py_arg_tuple.get ()));
567 if (py_result == NULL)
570 error (_(
"Error while executing Python code."));
573 if (py_result != Py_None)
579 error (_(
"Error while executing Python code."));
594 m_py_worker (py_worker), m_this_type (this_type)
598 Py_INCREF (py_worker);
599 Py_INCREF (this_type);
struct type * lookup_pointer_type(struct type *type)
struct type * lookup_typename(const struct language_defn *language, const char *name, const struct block *block, int noerr)
struct type * make_cv_type(int cnst, int voltl, struct type *type, struct type **typeptr)
struct type * lookup_reference_type(struct type *type, enum type_code refcode)
bool types_equal(struct type *a, struct type *b)
struct type * check_typedef(struct type *type)
#define TYPE_IS_REFERENCE(t)
const struct language_defn * current_language
struct program_space * current_program_space
gdbpy_ref objfile_to_objfile_object(struct objfile *objfile)
PyObject * objfpy_get_xmethods(PyObject *o, void *ignore)
PyObject * pspy_get_xmethods(PyObject *o, void *ignore)
gdbpy_ref pspace_to_pspace_object(struct program_space *pspace)
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
PyObject * type_to_type_object(struct type *type)
struct type * type_object_to_type(PyObject *obj)
struct value * convert_value_from_python(PyObject *obj)
PyObject * value_to_value_object(struct value *val)
static PyObject * invoke_match_method(PyObject *matcher, PyObject *py_obj_type, const char *xmethod_name)
static const char get_result_type_method_name[]
static const char matchers_attr_str[]
enum ext_lang_rc gdbpy_get_matching_xmethod_workers(const struct extension_language_defn *extlang, struct type *obj_type, const char *method_name, std::vector< xmethod_worker_up > *dm_vec)
static const char match_method_name[]
static PyObject * py_match_method_name
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_xmethods(void)
static const char enabled_field_name[]
static PyObject * py_get_arg_types_method_name
static const char get_arg_types_method_name[]
void gdbpy_print_stack(void)
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#define GDBPY_INITIALIZE_FILE(INIT,...)
PyObject * gdb_python_module
const struct extension_language_defn extension_language_python
objfiles_range objfiles()
DISABLE_COPY_AND_ASSIGN(python_xmethod_worker)
python_xmethod_worker(PyObject *worker, PyObject *this_type)
ext_lang_rc do_get_arg_types(std::vector< type * > *type_args) override
ext_lang_rc do_get_result_type(value *obj, gdb::array_view< value * > args, type **result_type_ptr) override
value * invoke(value *obj, gdb::array_view< value * > args) override
static struct value * allocate(struct type *type)
struct type * type() const
struct value * value_cast(struct type *type, struct value *arg2)