49 PyObject *py_obj_type);
87 new_data->worker = worker_data->
worker;
88 new_data->this_type = worker_data->
this_type;
89 Py_INCREF (new_data->worker);
90 Py_INCREF (new_data->this_type);
102 const char *xmethod_name)
104 PyObject *py_xmethod_name;
105 PyObject *match_method, *enabled_field, *match_result;
112 if (enabled_field == NULL)
119 enabled = PyObject_IsTrue (enabled_field);
133 if (match_method == NULL)
140 py_xmethod_name = PyString_FromString (xmethod_name);
141 if (py_xmethod_name == NULL)
148 match_result = PyObject_CallMethodObjArgs (matcher,
149 py_match_method_name,
164 struct type *obj_type,
const char *method_name,
165 xmethod_worker_vec **dm_vec)
170 PyObject *py_type, *py_progspace;
171 PyObject *py_xmethod_matcher_list = NULL, *list_iter, *matcher;
173 gdb_assert (obj_type != NULL && method_name != NULL);
188 py_xmethod_matcher_list = PyList_New (0);
189 if (py_xmethod_matcher_list == NULL)
203 PyObject *objfile_matchers, *temp = py_xmethod_matcher_list;
205 if (py_objfile == NULL)
215 py_xmethod_matcher_list = PySequence_Concat (temp, objfile_matchers);
218 if (py_xmethod_matcher_list == NULL)
230 if (py_progspace != NULL)
232 PyObject *temp = py_xmethod_matcher_list;
235 py_xmethod_matcher_list = PySequence_Concat (temp, pspace_matchers);
238 if (py_xmethod_matcher_list == NULL)
259 PyObject *gdb_matchers;
260 PyObject *temp = py_xmethod_matcher_list;
264 if (gdb_matchers != NULL)
266 py_xmethod_matcher_list = PySequence_Concat (temp, gdb_matchers);
269 if (py_xmethod_matcher_list == NULL)
291 list_iter = PyObject_GetIter (py_xmethod_matcher_list);
292 if (list_iter == NULL)
299 while ((matcher = PyIter_Next (list_iter)) != NULL)
304 if (match_result == NULL)
312 if (match_result == Py_None)
314 else if (PySequence_Check (match_result))
316 PyObject *iter = PyObject_GetIter (match_result);
328 while ((py_worker = PyIter_Next (iter)) != NULL)
338 if (PyErr_Occurred ())
361 if (PyErr_Occurred ())
370 *dm_vec = worker_vec;
380 int *nargs,
struct type ***arg_types)
383 PyObject *py_worker = worker_data->
worker;
384 PyObject *get_arg_types_method;
385 PyObject *py_argtype_list, *list_iter = NULL, *item;
387 struct type **type_array, *obj_type;
388 int i = 1, arg_count;
397 get_arg_types_method_name);
398 if (get_arg_types_method == NULL)
407 py_argtype_list = PyObject_CallMethodObjArgs (py_worker,
408 py_get_arg_types_method_name,
410 if (py_argtype_list == NULL)
418 if (py_argtype_list == Py_None)
420 else if (PySequence_Check (py_argtype_list))
422 arg_count = PySequence_Size (py_argtype_list);
431 list_iter = PyObject_GetIter (py_argtype_list);
432 if (list_iter == NULL)
445 type_array = XCNEWVEC (
struct type *, arg_count + 1);
447 if (list_iter != NULL)
449 while ((item = PyIter_Next (list_iter)) != NULL)
454 if (arg_type == NULL)
456 PyErr_SetString (PyExc_TypeError,
457 _(
"Arg type returned by the get_arg_types "
458 "method of a debug method worker object is "
459 "not a gdb.Type object."));
463 type_array[i] = arg_type;
467 else if (arg_count == 1)
473 if (arg_type == NULL)
475 PyErr_SetString (PyExc_TypeError,
476 _(
"Arg type returned by the get_arg_types method "
477 "of an xmethod worker object is not a gdb.Type "
482 type_array[i] = arg_type;
486 if (PyErr_Occurred ())
501 *arg_types = type_array;
513 struct value **args,
int nargs,
514 struct type **result_type_ptr)
517 PyObject *py_worker = worker_data->
worker;
518 PyObject *py_value_obj, *py_arg_tuple, *py_result_type;
519 PyObject *get_result_type_method;
520 struct type *obj_type, *this_type;
528 get_result_type_method
530 if (get_result_type_method == NULL)
534 *result_type_ptr = NULL;
561 if (py_value_obj == NULL)
565 py_arg_tuple = PyTuple_New (nargs + 1);
566 if (py_arg_tuple == NULL)
572 Py_INCREF (py_value_obj);
573 PyTuple_SET_ITEM (py_arg_tuple, 0, py_value_obj);
575 for (i = 0; i < nargs; i++)
579 if (py_value_arg == NULL)
581 PyTuple_SET_ITEM (py_arg_tuple, i + 1, py_value_arg);
584 py_result_type = PyObject_CallObject (get_result_type_method, py_arg_tuple);
585 if (py_result_type == NULL)
590 if (*result_type_ptr == NULL)
592 PyErr_SetString (PyExc_TypeError,
593 _(
"Type returned by the get_result_type method of an"
594 " xmethod worker object is not a gdb.Type object."));
612 struct value *obj,
struct value **args,
int nargs)
616 PyObject *py_value_obj, *py_arg_tuple, *py_result;
617 struct type *obj_type, *this_type;
618 struct value *res = NULL;
646 if (py_value_obj == NULL)
649 error (
_(
"Error while executing Python code."));
653 py_arg_tuple = PyTuple_New (nargs + 1);
654 if (py_arg_tuple == NULL)
657 error (
_(
"Error while executing Python code."));
663 Py_INCREF (py_value_obj);
664 PyTuple_SET_ITEM (py_arg_tuple, 0, py_value_obj);
666 for (i = 0; i < nargs; i++)
670 if (py_value_arg == NULL)
673 error (
_(
"Error while executing Python code."));
676 PyTuple_SET_ITEM (py_arg_tuple, i + 1, py_value_arg);
679 py_result = PyObject_CallObject (xmethod_worker, py_arg_tuple);
680 if (py_result == NULL)
683 error (
_(
"Error while executing Python code."));
687 if (py_result != Py_None)
693 error (
_(
"Error while executing Python code."));
716 gdb_assert (py_worker != NULL && this_type != NULL);
721 Py_INCREF (py_worker);
722 Py_INCREF (this_type);
730 py_match_method_name = PyString_FromString (match_method_name);
731 if (py_match_method_name == NULL)
734 py_invoke_method_name = PyString_FromString (invoke_method_name);
735 if (py_invoke_method_name == NULL)
738 py_get_arg_types_method_name
739 = PyString_FromString (get_arg_types_method_name);
740 if (py_get_arg_types_method_name == NULL)
743 py_get_result_type_method_name
744 = PyString_FromString (get_result_type_method_name);
745 if (py_get_result_type_method_name == NULL)
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 * 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)
void null_cleanup(void *arg)
struct type * lookup_typename(const struct language_defn *language, struct gdbarch *gdbarch, const char *name, const struct block *block, int noerr)
#define ALL_OBJFILES(obj)
struct type * check_typedef(struct type *type)
static PyObject * py_get_arg_types_method_name
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
PyObject * objfile_to_objfile_object(struct objfile *objfile)
static const char invoke_method_name[]
static const char get_arg_types_method_name[]
struct gdbarch * get_current_arch(void)
struct gdbarch * python_gdbarch
struct cleanup * ensure_python_env(struct gdbarch *gdbarch, const struct language_defn *language)
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)
static PyObject * py_get_result_type_method_name
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[]
static PyObject * py_invoke_method_name
struct type * value_type(const struct value *value)
struct type * lookup_reference_type(struct type *type)
const struct language_defn * python_language
struct cleanup * make_cleanup_py_decref(PyObject *py)
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)
void do_cleanups(struct cleanup *old_chain)
PyObject * type_to_type_object(struct type *type)