mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-26 11:33:45 +08:00
9a27f2c60d
* NEWS: Mention Python 3 support. * varobj.c (value_get_print_value): Use python_string_to_target_string. * python/py-block.c: Use PyVarObject_HEAD_INIT in initialization of type objects. * python/py-breakpoint.c: Ditto. * python/py-cmd.c: Ditto. * python/py-event.c: Ditto. * python/py-event.h: Ditto. * python/py-evtregistry.c: Ditto. * python/py-finishbreakpoint.c: Ditto. * python/py-frame.c: Ditto. * python/py-function.c: Ditto. * python/py-infthread.c: Ditto. * python/py-lazy-string.c: Ditto. * python/py-progspace.c: Ditto. * /python/py-symbol.c: Ditto. * python/py-evts.c: (gdbpy_initialize_py_events): Add module initialization for Python 3. * python/py-inferior.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (infpy_read_memory): Return memoryview object if Python 3. (infpy_write_memory): Use "s*" operand parsing code for Python 3. (infpy_search_memory): Ditto. (get_buffer): New function for Python 3. * python/py-objfile.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (objfpy_dealloc): Use Py_TYPE to call tp_free. * python/py-param.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (get_attr): Use PyUnicode_CompareWithASCIIString if Python 3. (set_attr): Ditto. * python/py-prettyprint.c (print_string_repr): use PyBytes methods instead of PyString methods if Python 3. (print_children): Skip push_dummy_python_frame call if Python 3. * python/py-symtab.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (salpy_dealloc): Use Py_TYPE to call tp_free. * python/py-type.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (field_dealloc): Use Py_TYPE to call tp_free. (typy_dealloc): Ditto. (type_object_as_number): Adjust struct initializations for differences in layout for Python 2 vs. Python 3. * python/py-utils.c (python_string_to_unicode): Omit non-Unicode string case for Python 3. (unicode_to_encoded_python_string): Shorten code (no functional change). (python_string_to_target_python_string): Comment that in Python 3 returned value is a Python "bytes" type. (gdbpy_is_string): Omit non-Unicode string check in Python 3. (gdb_py_object_from_longest): Omit non-long integer case in Python 3. (gdb_py_object_from_ulongest): Ditto. * python/py-value.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (valpy_dealloc): Use Py_TYPE to call tp_free. (valpy_int): Omit function if Python 3. (convert_value_from_python): Use "%S" format (Python object as a string) if Python 3. (value_object_as_number): Adjust struct initializations for differences in layout for Python 2 vs. Python 3. * python/python-config.py: Adjust syntax for Python 3 compatibility. Include "sys.abiflags" string as part of python library name, if that attribute exists (Python 3). * python/python-internal.h (IS_PY3): Define if Python 3. (Py_TPFLAGS_HAVE_ITER, Py_TPFLAGS_CHECKTYPES): Define with placeholder value if Python 3. (PyInt_Check, PyInt_FromLong, PyInt_AsLong, PyString_FromString, PyString_Decode, PyString_FromFormat, PyString_Check): Define as analogous Python 3 API function if Python 3. (PyVarObject_HEAD_INIT): Define if not already defined. (Py_TYPE): Ditto. * python/python.c (eval_python_command): Omit Py_FlushLine call if Python 3. Check return values of all Python API calls for error. Supply dummy "python" and "python-interactive" commands if Python initialization failed. (_initialize_python): Convert argc to wchar_t** if Python 3. Add module initialization for Python 3. (finish_python_initialization): Pass wchar_t * argument to PySys_SetPath if Python 3. * python/lib/gdb/__init__.py: Define "reload" if Python 3. (_GdbFile): New class for common output file behavior. (GdbOutFile): Subclass from _GdbFile. (GdbOutputErrorFile): Ditto. (auto_load_packages): Adjust syntax for Python 3 compatibility. * python/lib/gdb/printing.py: Define basestr and int if Python 3. * python/lib/gdb/prompt.py: Use sorted() function rather than sort() method. * python/lib/gdb/command/explore.py: Define raw_input if Python 3. Adjust syntax for Python 3 compatibility. * python/lib/gdb/command/pretty_printers.py: Use sorted() function rather than sort() method. Adjust syntax for Python 3 compatibility. * python/lib/gdb/command/type_printers.py: Ditto. * doc/gdb.texinfo (Inferior.read_memory): Mention that the return value is a memoryview object if Python 3.
184 lines
5.7 KiB
C
184 lines
5.7 KiB
C
/* Python interface to inferior events.
|
|
|
|
Copyright (C) 2009-2012 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "defs.h"
|
|
#include "py-event.h"
|
|
|
|
void
|
|
evpy_dealloc (PyObject *self)
|
|
{
|
|
Py_XDECREF (((event_object *) self)->dict);
|
|
Py_TYPE (self)->tp_free (self);
|
|
}
|
|
|
|
PyObject *
|
|
create_event_object (PyTypeObject *py_type)
|
|
{
|
|
event_object *event_obj;
|
|
|
|
event_obj = PyObject_New (event_object, py_type);
|
|
if (!event_obj)
|
|
goto fail;
|
|
|
|
event_obj->dict = PyDict_New ();
|
|
if (!event_obj->dict)
|
|
goto fail;
|
|
|
|
return (PyObject*) event_obj;
|
|
|
|
fail:
|
|
Py_XDECREF (event_obj);
|
|
return NULL;
|
|
}
|
|
|
|
/* Add the attribute ATTR to the event object EVENT. In
|
|
python this attribute will be accessible by the name NAME.
|
|
returns 0 if the operation succeeds and -1 otherwise. This
|
|
function acquires a new reference to ATTR. */
|
|
|
|
int
|
|
evpy_add_attribute (PyObject *event, char *name, PyObject *attr)
|
|
{
|
|
return PyObject_SetAttrString (event, name, attr);
|
|
}
|
|
|
|
/* Initialize the Python event code. */
|
|
|
|
void
|
|
gdbpy_initialize_event (void)
|
|
{
|
|
gdbpy_initialize_event_generic (&event_object_type,
|
|
"Event");
|
|
}
|
|
|
|
/* Initialize the given event type. If BASE is not NULL it will
|
|
be set as the types base.
|
|
Returns 0 if initialization was successful -1 otherwise. */
|
|
|
|
int
|
|
gdbpy_initialize_event_generic (PyTypeObject *type,
|
|
char *name)
|
|
{
|
|
if (PyType_Ready (type) < 0)
|
|
goto fail;
|
|
|
|
Py_INCREF (type);
|
|
if (PyModule_AddObject (gdb_module, name, (PyObject *) type) < 0)
|
|
goto fail;
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
Py_XDECREF (type);
|
|
return -1;
|
|
}
|
|
|
|
|
|
/* Notify the list of listens that the given EVENT has occurred.
|
|
returns 0 if emit is successful -1 otherwise. */
|
|
|
|
int
|
|
evpy_emit_event (PyObject *event,
|
|
eventregistry_object *registry)
|
|
{
|
|
PyObject *callback_list_copy = NULL;
|
|
Py_ssize_t i;
|
|
|
|
/* Create a copy of call back list and use that for
|
|
notifying listeners to avoid skipping callbacks
|
|
in the case of a callback being disconnected during
|
|
a notification. */
|
|
callback_list_copy = PySequence_List (registry->callbacks);
|
|
if (!callback_list_copy)
|
|
goto fail;
|
|
|
|
for (i = 0; i < PyList_Size (callback_list_copy); i++)
|
|
{
|
|
PyObject *func = PyList_GetItem (callback_list_copy, i);
|
|
|
|
if (func == NULL)
|
|
goto fail;
|
|
|
|
if (!PyObject_CallFunctionObjArgs (func, event, NULL))
|
|
{
|
|
/* Print the trace here, but keep going -- we want to try to
|
|
call all of the callbacks even if one is broken. */
|
|
gdbpy_print_stack ();
|
|
}
|
|
}
|
|
|
|
Py_XDECREF (callback_list_copy);
|
|
Py_XDECREF (event);
|
|
return 0;
|
|
|
|
fail:
|
|
gdbpy_print_stack ();
|
|
Py_XDECREF (callback_list_copy);
|
|
Py_XDECREF (event);
|
|
return -1;
|
|
}
|
|
|
|
static PyGetSetDef event_object_getset[] =
|
|
{
|
|
{ "__dict__", gdb_py_generic_dict, NULL,
|
|
"The __dict__ for this event.", &event_object_type },
|
|
{ NULL }
|
|
};
|
|
|
|
PyTypeObject event_object_type =
|
|
{
|
|
PyVarObject_HEAD_INIT (NULL, 0)
|
|
"gdb.Event", /* tp_name */
|
|
sizeof (event_object), /* tp_basicsize */
|
|
0, /* tp_itemsize */
|
|
evpy_dealloc, /* tp_dealloc */
|
|
0, /* tp_print */
|
|
0, /* tp_getattr */
|
|
0, /* tp_setattr */
|
|
0, /* tp_compare */
|
|
0, /* tp_repr */
|
|
0, /* tp_as_number */
|
|
0, /* tp_as_sequence */
|
|
0, /* tp_as_mapping */
|
|
0, /* tp_hash */
|
|
0, /* tp_call */
|
|
0, /* tp_str */
|
|
0, /* tp_getattro */
|
|
0, /* tp_setattro */
|
|
0, /* tp_as_buffer */
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
|
"GDB event object", /* tp_doc */
|
|
0, /* tp_traverse */
|
|
0, /* tp_clear */
|
|
0, /* tp_richcompare */
|
|
0, /* tp_weaklistoffset */
|
|
0, /* tp_iter */
|
|
0, /* tp_iternext */
|
|
0, /* tp_methods */
|
|
0, /* tp_members */
|
|
event_object_getset, /* tp_getset */
|
|
0, /* tp_base */
|
|
0, /* tp_dict */
|
|
0, /* tp_descr_get */
|
|
0, /* tp_descr_set */
|
|
offsetof (event_object, dict), /* tp_dictoffset */
|
|
0, /* tp_init */
|
|
0 /* tp_alloc */
|
|
};
|