/* Support for debug methods in Python.
- Copyright (C) 2013-2018 Free Software Foundation, Inc.
+ Copyright (C) 2013-2019 Free Software Foundation, Inc.
This file is part of GDB.
#include "python.h"
#include "python-internal.h"
-#include "py-ref.h"
static const char enabled_field_name[] = "enabled";
static const char match_method_name[] = "match";
/* Implementation of xmethod_worker::invoke for Python. */
- value *invoke (value *obj, value **args, int nargs) override;
-
- /* Implementation of xmethod_worker::clone for Python. */
-
- xmethod_worker_up clone () override;
+ value *invoke (value *obj, gdb::array_view<value *> args) override;
/* Implementation of xmethod_worker::do_get_arg_types for Python. */
- ext_lang_rc do_get_arg_types (int *nargs, type ***arg_types) override;
+ ext_lang_rc do_get_arg_types (std::vector<type *> *type_args) override;
/* Implementation of xmethod_worker::do_get_result_type for Python.
result type, if the get_result_type operation is not provided by WORKER
then EXT_LANG_RC_OK is returned and NULL is returned in *RESULT_TYPE. */
- ext_lang_rc do_get_result_type (value *obj, value **args, int nargs,
+ ext_lang_rc do_get_result_type (value *obj, gdb::array_view<value *> args,
type **result_type_ptr) override;
private:
Py_DECREF (m_this_type);
}
-/* See declaration. */
-
-xmethod_worker_up
-python_xmethod_worker::clone ()
-{
- /* We don't do much here, but we still need the GIL. */
- gdbpy_enter enter_py (get_current_arch (), current_language);
-
- xmethod_worker *worker = new python_xmethod_worker (m_py_worker, m_this_type);
-
- return xmethod_worker_up (worker);
-}
-
/* Invoke the "match" method of the MATCHER and return a new reference
to the result. Returns NULL on error. */
struct type *obj_type, const char *method_name,
std::vector<xmethod_worker_up> *dm_vec)
{
- struct objfile *objfile;
- PyObject *py_progspace;
-
gdb_assert (obj_type != NULL && method_name != NULL);
gdbpy_enter enter_py (get_current_arch (), current_language);
/* Gather debug method matchers registered with the object files.
This could be done differently by iterating over each objfile's matcher
list individually, but there's no data yet to show it's needed. */
- ALL_OBJFILES (objfile)
+ for (objfile *objfile : current_program_space->objfiles ())
{
- PyObject *py_objfile = objfile_to_objfile_object (objfile);
+ gdbpy_ref<> py_objfile = objfile_to_objfile_object (objfile);
if (py_objfile == NULL)
{
return EXT_LANG_RC_ERROR;
}
- gdbpy_ref<> objfile_matchers (objfpy_get_xmethods (py_objfile, NULL));
+ gdbpy_ref<> objfile_matchers (objfpy_get_xmethods (py_objfile.get (),
+ NULL));
gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
objfile_matchers.get ()));
if (temp == NULL)
/* Gather debug methods matchers registered with the current program
space. */
- py_progspace = pspace_to_pspace_object (current_program_space);
+ gdbpy_ref<> py_progspace = pspace_to_pspace_object (current_program_space);
if (py_progspace != NULL)
{
- gdbpy_ref<> pspace_matchers (pspy_get_xmethods (py_progspace, NULL));
+ gdbpy_ref<> pspace_matchers (pspy_get_xmethods (py_progspace.get (),
+ NULL));
gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
pspace_matchers.get ()));
/* See declaration. */
ext_lang_rc
-python_xmethod_worker::do_get_arg_types (int *nargs, type ***arg_types)
+python_xmethod_worker::do_get_arg_types (std::vector<type *> *arg_types)
{
/* The gdbpy_enter object needs to be placed first, so that it's the last to
be destroyed. */
int i = 1, arg_count;
gdbpy_ref<> list_iter;
- /* Set nargs to -1 so that any premature return from this function returns
- an invalid/unusable number of arg types. */
- *nargs = -1;
-
gdbpy_ref<> get_arg_types_method
(PyObject_GetAttrString (m_py_worker, get_arg_types_method_name));
if (get_arg_types_method == NULL)
arg_count = 1;
/* Include the 'this' argument in the size. */
- gdb::unique_xmalloc_ptr<struct type *> type_array
- (XCNEWVEC (struct type *, arg_count + 1));
+ arg_types->resize (arg_count + 1);
i = 1;
if (list_iter != NULL)
{
return EXT_LANG_RC_ERROR;
}
- (type_array.get ())[i] = arg_type;
+ (*arg_types)[i] = arg_type;
i++;
}
}
}
else
{
- (type_array.get ())[i] = arg_type;
+ (*arg_types)[i] = arg_type;
i++;
}
}
be a 'const' value. Hence, create a 'const' variant of the 'this' pointer
type. */
obj_type = type_object_to_type (m_this_type);
- (type_array.get ())[0] = make_cv_type (1, 0, lookup_pointer_type (obj_type),
- NULL);
- *nargs = i;
- *arg_types = type_array.release ();
+ (*arg_types)[0] = make_cv_type (1, 0, lookup_pointer_type (obj_type),
+ NULL);
return EXT_LANG_RC_OK;
}
/* See declaration. */
ext_lang_rc
-python_xmethod_worker::do_get_result_type (value *obj, value **args, int nargs,
+python_xmethod_worker::do_get_result_type (value *obj,
+ gdb::array_view<value *> args,
type **result_type_ptr)
{
struct type *obj_type, *this_type;
return EXT_LANG_RC_ERROR;
}
- gdbpy_ref<> py_arg_tuple (PyTuple_New (nargs + 1));
+ gdbpy_ref<> py_arg_tuple (PyTuple_New (args.size () + 1));
if (py_arg_tuple == NULL)
{
gdbpy_print_stack ();
release. */
PyTuple_SET_ITEM (py_arg_tuple.get (), 0, py_value_obj.release ());
- for (i = 0; i < nargs; i++)
+ for (i = 0; i < args.size (); i++)
{
PyObject *py_value_arg = value_to_value_object (args[i]);
/* See declaration. */
struct value *
-python_xmethod_worker::invoke (struct value *obj, struct value **args,
- int nargs)
+python_xmethod_worker::invoke (struct value *obj,
+ gdb::array_view<value *> args)
{
gdbpy_enter enter_py (get_current_arch (), current_language);
error (_("Error while executing Python code."));
}
- gdbpy_ref<> py_arg_tuple (PyTuple_New (nargs + 1));
+ gdbpy_ref<> py_arg_tuple (PyTuple_New (args.size () + 1));
if (py_arg_tuple == NULL)
{
gdbpy_print_stack ();
release. */
PyTuple_SET_ITEM (py_arg_tuple.get (), 0, py_value_obj.release ());
- for (i = 0; i < nargs; i++)
+ for (i = 0; i < args.size (); i++)
{
PyObject *py_value_arg = value_to_value_object (args[i]);