* [RFC][4/5] Continue and exit event sucblasses.
@ 2009-08-23 15:36 Oguz Kayral
0 siblings, 0 replies; only message in thread
From: Oguz Kayral @ 2009-08-23 15:36 UTC (permalink / raw)
To: archer
These to new files contain subclasses to event class adding
functionality for continue and exit events.
python-continueevent.c:
/* Python interface to inferior continue events.
Copyright (C) 2009 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 "command.h"
#include "python-internal.h"
#include "inferior.h"
static PyTypeObject continue_event_object_type;
typedef struct
{
event_object event;
} continue_event_object;
static void
continue_evpy_dealloc (PyObject *self)
{
self->ob_type->tp_free (self);
}
continue_event_object *
create_continue_event_object ()
{
continue_event_object *continue_event_obj;
continue_event_obj = PyObject_New (continue_event_object,
&continue_event_object_type);
if (!continue_event_obj)
return NULL;
continue_event_obj->event.inferior_thread = find_thread_object
(inferior_ptid);
Py_INCREF (continue_event_obj->event.inferior_thread);
continue_event_obj->event.event_type = (PyStringObject *)
PyString_FromString ("continue");
return continue_event_obj;
}
/* Initialize the Python continue event code. */
void
gdbpy_initialize_continue_event (void)
{
continue_event_object_type.tp_base = &event_object_type;
if (PyType_Ready (&continue_event_object_type) < 0)
return;
Py_INCREF (&continue_event_object_type);
PyModule_AddObject (gdb_module, "ContinueEvent", (PyObject *)
&continue_event_object_type);
}
/* Callback that is used when a continue event occurs. This function
will create a new Python continue event object. */
void
emit_continue_event (ptid_t ptid)
{
thread_object *inferior_thread;
PyObject *callback_list;
PyObject *args_tuple;
Py_ssize_t i;
continue_event_object *continue_event_obj;
inferior_thread = find_thread_object (inferior_ptid);
continue_event_obj = create_continue_event_object();
callback_list = (PyObject *)
(inferior_thread->continue_eventregistry->callbacks);
args_tuple = PyTuple_New ((Py_ssize_t) 1);
PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *) continue_event_obj);
for (i = 0; i < PyList_Size (callback_list); i++)
{
PyObject_CallObject (PyList_GET_ITEM (callback_list, i), args_tuple);
}
}
static PyTypeObject continue_event_object_type =
{
PyObject_HEAD_INIT (NULL)
0, /* ob_size */
"gdb.ContinueEvent", /* tp_name */
sizeof (continue_event_object), /* tp_basicsize */
0, /* tp_itemsize */
continue_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, /* tp_flags */
"GDB continue 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 */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0 /* tp_alloc */
};
python-exitedevent.c:
/* Python interface to inferior exit events.
Copyright (C) 2009 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 "command.h"
#include "python-internal.h"
#include "inferior.h"
static PyTypeObject exited_event_object_type;
typedef struct
{
event_object event;
PyLongObject *exit_code;
} exited_event_object;
static void
exit_evpy_dealloc (PyObject *self)
{
Py_DECREF (((exited_event_object *) self)->exit_code);
self->ob_type->tp_free (self);
}
/* Python function to get the exited event's exit code. */
static PyObject *
exit_evpy_get_exit_code (PyObject *self, void *closure)
{
exited_event_object *exited_event_obj = (exited_event_object *) self;
Py_INCREF (exited_event_obj->exit_code);
return (PyObject *) (exited_event_obj->exit_code);
}
exited_event_object *
create_exited_event_object (thread_object *inferior_thread, long long
int *exit_code)
{
exited_event_object *exited_event_obj;
exited_event_obj = PyObject_New (exited_event_object,
&exited_event_object_type);
if (!exited_event_obj)
return NULL;
exited_event_obj->event.inferior_thread = inferior_thread;
Py_INCREF (exited_event_obj->event.inferior_thread);
exited_event_obj->event.event_type = (PyStringObject *)
PyString_FromString ("exit");
exited_event_obj->exit_code = (PyLongObject *) PyLong_FromLongLong
(*exit_code);
return exited_event_obj;
}
/* Initialize the Python exited event code. */
void gdbpy_initialize_exited_event (void)
{
exited_event_object_type.tp_base = &event_object_type;
if (PyType_Ready (&exited_event_object_type) < 0)
return;
Py_INCREF (&exited_event_object_type);
PyModule_AddObject (gdb_module, "ExitedEvent", (PyObject *)
&exited_event_object_type);
}
/* Callback that is used when an exit event occurs. This function
will create a new Python exited event object. */
void
emit_exited_event (thread_object *inferior_thread, long long int *exit_code)
{
PyObject *callback_list;
PyObject *args_tuple;
Py_ssize_t i;
exited_event_object *exited_event_obj;
exited_event_obj = create_exited_event_object (inferior_thread, exit_code);
callback_list = (PyObject *)
(inferior_thread->exited_eventregistry->callbacks);
args_tuple = PyTuple_New ((Py_ssize_t) 1);
PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *) exited_event_obj);
for (i = 0; i < PyList_Size (callback_list); i++)
{
PyObject_CallObject (PyList_GET_ITEM (callback_list, i), args_tuple);
}
}
static PyGetSetDef exited_event_object_getset[] =
{
{ "exit_code", exit_evpy_get_exit_code, NULL, "Exit code.", NULL },
{ NULL } /* Sentinel. */
};
static PyTypeObject exited_event_object_type =
{
PyObject_HEAD_INIT (NULL)
0, /* ob_size */
"gdb.ExitedEvent", /* tp_name */
sizeof (exited_event_object), /* tp_basicsize */
0, /* tp_itemsize */
exit_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, /* tp_flags */
"GDB exited 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 */
exited_event_object_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0 /* tp_alloc */
};
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-08-23 15:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-23 15:36 [RFC][4/5] Continue and exit event sucblasses Oguz Kayral
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).