diff options
Diffstat (limited to 'gdb/python/py-tui.c')
-rw-r--r-- | gdb/python/py-tui.c | 186 |
1 files changed, 83 insertions, 103 deletions
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c index e9c9101..6df0cdd 100644 --- a/gdb/python/py-tui.c +++ b/gdb/python/py-tui.c @@ -17,7 +17,6 @@ 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 "arch-utils.h" #include "python-internal.h" @@ -45,15 +44,15 @@ struct gdbpy_tui_window { PyObject_HEAD - /* The TUI window, or nullptr if the window has been deleted. */ - tui_py_window *window; + /* The TUI window, or nullptr if the window has been deleted. */ + tui_py_window *window; /* Return true if this object is valid. */ bool is_valid () const; }; extern PyTypeObject gdbpy_tui_window_object_type - CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("gdbpy_tui_window"); + CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("gdbpy_tui_window"); /* A TUI window written in Python. */ @@ -80,10 +79,7 @@ public: m_window = std::move (user_window); } - const char *name () const override - { - return m_name.c_str (); - } + const char *name () const override { return m_name.c_str (); } void rerender () override; void do_scroll_vertical (int num_to_scroll) override; @@ -118,16 +114,10 @@ public: void output (const char *str, bool full_window); /* A helper function to compute the viewport width. */ - int viewport_width () const - { - return std::max (0, width - 2); - } + int viewport_width () const { return std::max (0, width - 2); } /* A helper function to compute the viewport height. */ - int viewport_height () const - { - return std::max (0, height - 2); - } + int viewport_height () const { return std::max (0, height - 2); } private: @@ -159,8 +149,7 @@ tui_py_window::~tui_py_window () /* This can be null if the user-provided Python construction function failed. */ - if (m_window != nullptr - && PyObject_HasAttrString (m_window.get (), "close")) + if (m_window != nullptr && PyObject_HasAttrString (m_window.get (), "close")) { gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "close", nullptr)); @@ -210,8 +199,8 @@ tui_py_window::do_scroll_horizontal (int num_to_scroll) if (PyObject_HasAttrString (m_window.get (), "hscroll")) { - gdbpy_ref<> result (PyObject_CallMethod (m_window.get(), "hscroll", - "i", num_to_scroll, nullptr)); + gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "hscroll", "i", + num_to_scroll, nullptr)); if (result == nullptr) gdbpy_print_stack (); } @@ -224,8 +213,8 @@ tui_py_window::do_scroll_vertical (int num_to_scroll) if (PyObject_HasAttrString (m_window.get (), "vscroll")) { - gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "vscroll", - "i", num_to_scroll, nullptr)); + gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "vscroll", "i", + num_to_scroll, nullptr)); if (result == nullptr) gdbpy_print_stack (); } @@ -238,8 +227,8 @@ tui_py_window::click (int mouse_x, int mouse_y, int mouse_button) if (PyObject_HasAttrString (m_window.get (), "click")) { - gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "click", - "iii", mouse_x, mouse_y, + gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "click", "iii", + mouse_x, mouse_y, mouse_button)); if (result == nullptr) gdbpy_print_stack (); @@ -262,8 +251,6 @@ tui_py_window::output (const char *text, bool full_window) } } - - /* A callable that is used to create a TUI window. It wraps the user-supplied window constructor. */ @@ -321,21 +308,19 @@ gdbpy_tui_window_maker::operator() (const char *win_name) { gdbpy_enter enter_py; - gdbpy_ref<gdbpy_tui_window> wrapper - (PyObject_New (gdbpy_tui_window, &gdbpy_tui_window_object_type)); + gdbpy_ref<gdbpy_tui_window> wrapper ( + PyObject_New (gdbpy_tui_window, &gdbpy_tui_window_object_type)); if (wrapper == nullptr) { gdbpy_print_stack (); return nullptr; } - std::unique_ptr<tui_py_window> window - (new tui_py_window (win_name, wrapper)); + std::unique_ptr<tui_py_window> window (new tui_py_window (win_name, + wrapper)); - gdbpy_ref<> user_window - (PyObject_CallFunctionObjArgs (m_constr.get (), - (PyObject *) wrapper.get (), - nullptr)); + gdbpy_ref<> user_window (PyObject_CallFunctionObjArgs ( + m_constr.get (), (PyObject *) wrapper.get (), nullptr)); if (user_window == nullptr) { gdbpy_print_stack (); @@ -357,8 +342,8 @@ gdbpy_register_tui_window (PyObject *self, PyObject *args, PyObject *kw) const char *name; PyObject *cons_obj; - if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "sO", keywords, - &name, &cons_obj)) + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "sO", keywords, &name, + &cons_obj)) return nullptr; try @@ -375,28 +360,29 @@ gdbpy_register_tui_window (PyObject *self, PyObject *args, PyObject *kw) Py_RETURN_NONE; } - - /* Require that "Window" be a valid window. */ -#define REQUIRE_WINDOW(Window) \ - do { \ - if (!(Window)->is_valid ()) \ - return PyErr_Format (PyExc_RuntimeError, \ - _("TUI window is invalid.")); \ - } while (0) +#define REQUIRE_WINDOW(Window) \ + do \ + { \ + if (!(Window)->is_valid ()) \ + return PyErr_Format (PyExc_RuntimeError, \ + _ ("TUI window is invalid.")); \ + } \ + while (0) /* Require that "Window" be a valid window. */ -#define REQUIRE_WINDOW_FOR_SETTER(Window) \ - do { \ - if (!(Window)->is_valid ()) \ - { \ - PyErr_Format (PyExc_RuntimeError, \ - _("TUI window is invalid.")); \ - return -1; \ - } \ - } while (0) +#define REQUIRE_WINDOW_FOR_SETTER(Window) \ + do \ + { \ + if (!(Window)->is_valid ()) \ + { \ + PyErr_Format (PyExc_RuntimeError, _ ("TUI window is invalid.")); \ + return -1; \ + } \ + } \ + while (0) /* Python function which checks the validity of a TUI window object. */ @@ -482,7 +468,7 @@ gdbpy_tui_set_title (PyObject *self, PyObject *newvalue, void *closure) if (newvalue == nullptr) { - PyErr_Format (PyExc_TypeError, _("Cannot delete \"title\" attribute.")); + PyErr_Format (PyExc_TypeError, _ ("Cannot delete \"title\" attribute.")); return -1; } @@ -495,66 +481,60 @@ gdbpy_tui_set_title (PyObject *self, PyObject *newvalue, void *closure) return 0; } -static gdb_PyGetSetDef tui_object_getset[] = -{ +static gdb_PyGetSetDef tui_object_getset[] = { { "width", gdbpy_tui_width, NULL, "Width of the window.", NULL }, { "height", gdbpy_tui_height, NULL, "Height of the window.", NULL }, { "title", gdbpy_tui_title, gdbpy_tui_set_title, "Title of the window.", NULL }, - { NULL } /* Sentinel */ + { NULL } /* Sentinel */ }; -static PyMethodDef tui_object_methods[] = -{ - { "is_valid", gdbpy_tui_is_valid, METH_NOARGS, - "is_valid () -> Boolean\n\ +static PyMethodDef tui_object_methods[] = { + { "is_valid", gdbpy_tui_is_valid, METH_NOARGS, "is_valid () -> Boolean\n\ Return true if this TUI window is valid, false if not." }, - { "erase", gdbpy_tui_erase, METH_NOARGS, - "Erase the TUI window." }, + { "erase", gdbpy_tui_erase, METH_NOARGS, "Erase the TUI window." }, { "write", (PyCFunction) gdbpy_tui_write, METH_VARARGS, "Append a string to the TUI window." }, { NULL } /* Sentinel. */ }; -PyTypeObject gdbpy_tui_window_object_type = -{ - PyVarObject_HEAD_INIT (NULL, 0) - "gdb.TuiWindow", /*tp_name*/ - sizeof (gdbpy_tui_window), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - 0, /*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 TUI window object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - tui_object_methods, /* tp_methods */ - 0, /* tp_members */ - tui_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 */ +PyTypeObject gdbpy_tui_window_object_type = { + PyVarObject_HEAD_INIT (NULL, 0) "gdb.TuiWindow", /*tp_name*/ + sizeof (gdbpy_tui_window), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + 0, /*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 TUI window object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + tui_object_methods, /* tp_methods */ + 0, /* tp_members */ + tui_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 */ }; #endif /* TUI */ @@ -568,7 +548,7 @@ gdbpy_initialize_tui () gdbpy_tui_window_object_type.tp_new = PyType_GenericNew; if (PyType_Ready (&gdbpy_tui_window_object_type) < 0) return -1; -#endif /* TUI */ +#endif /* TUI */ return 0; } |