py-event.h revision 1.7
1/* Python interface to inferior events. 2 3 Copyright (C) 2009-2017 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20#ifndef GDB_PY_EVENT_H 21#define GDB_PY_EVENT_H 22 23#include "py-events.h" 24#include "command.h" 25#include "python-internal.h" 26#include "inferior.h" 27#include "py-ref.h" 28 29/* This macro creates the following functions: 30 31 gdbpy_initialize_{NAME}_event 32 Used to add the newly created event type to the gdb module. 33 34 and the python type data structure for the event: 35 36 struct PyTypeObject {NAME}_event_object_type 37 38 NAME is the name of the event. 39 PY_PATH is a string representing the module and python name of 40 the event. 41 PY_NAME a string representing what the event should be called in 42 python. 43 DOC Python documentation for the new event type 44 BASE the base event for this event usually just event_object_type. 45*/ 46 47#define GDBPY_NEW_EVENT_TYPE(name, py_path, py_name, doc, base) \ 48\ 49 PyTypeObject name##_event_object_type \ 50 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object") \ 51 = { \ 52 PyVarObject_HEAD_INIT (NULL, 0) \ 53 py_path, /* tp_name */ \ 54 sizeof (event_object), /* tp_basicsize */ \ 55 0, /* tp_itemsize */ \ 56 evpy_dealloc, /* tp_dealloc */ \ 57 0, /* tp_print */ \ 58 0, /* tp_getattr */ \ 59 0, /* tp_setattr */ \ 60 0, /* tp_compare */ \ 61 0, /* tp_repr */ \ 62 0, /* tp_as_number */ \ 63 0, /* tp_as_sequence */ \ 64 0, /* tp_as_mapping */ \ 65 0, /* tp_hash */ \ 66 0, /* tp_call */ \ 67 0, /* tp_str */ \ 68 0, /* tp_getattro */ \ 69 0, /* tp_setattro */ \ 70 0, /* tp_as_buffer */ \ 71 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ \ 72 doc, /* tp_doc */ \ 73 0, /* tp_traverse */ \ 74 0, /* tp_clear */ \ 75 0, /* tp_richcompare */ \ 76 0, /* tp_weaklistoffset */ \ 77 0, /* tp_iter */ \ 78 0, /* tp_iternext */ \ 79 0, /* tp_methods */ \ 80 0, /* tp_members */ \ 81 0, /* tp_getset */ \ 82 &base, /* tp_base */ \ 83 0, /* tp_dict */ \ 84 0, /* tp_descr_get */ \ 85 0, /* tp_descr_set */ \ 86 0, /* tp_dictoffset */ \ 87 0, /* tp_init */ \ 88 0 /* tp_alloc */ \ 89 }; \ 90\ 91int \ 92gdbpy_initialize_##name##_event (void) \ 93{ \ 94 return gdbpy_initialize_event_generic (&name##_event_object_type, \ 95 py_name); \ 96} 97 98typedef struct 99{ 100 PyObject_HEAD 101 102 PyObject *dict; 103} event_object; 104 105extern int emit_continue_event (ptid_t ptid); 106extern int emit_exited_event (const LONGEST *exit_code, struct inferior *inf); 107 108/* For inferior function call events, discriminate whether event is 109 before or after the call. */ 110 111typedef enum 112{ 113 /* Before the call */ 114 INFERIOR_CALL_PRE, 115 /* after the call */ 116 INFERIOR_CALL_POST, 117} inferior_call_kind; 118 119extern int emit_inferior_call_event (inferior_call_kind kind, 120 ptid_t thread, CORE_ADDR addr); 121extern int emit_register_changed_event (struct frame_info *frame, 122 int regnum); 123extern int emit_memory_changed_event (CORE_ADDR addr, ssize_t len); 124extern int evpy_emit_event (PyObject *event, 125 eventregistry_object *registry); 126 127extern PyObject *create_event_object (PyTypeObject *py_type); 128extern PyObject *create_thread_event_object (PyTypeObject *py_type); 129extern int emit_new_objfile_event (struct objfile *objfile); 130extern int emit_clear_objfiles_event (void); 131 132extern void evpy_dealloc (PyObject *self); 133extern int evpy_add_attribute (PyObject *event, 134 const char *name, PyObject *attr) 135 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; 136int gdbpy_initialize_event_generic (PyTypeObject *type, const char *name) 137 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; 138 139#endif /* GDB_PY_EVENT_H */ 140