From 7e678b60610358efe6eb4f01cca2b1b0d423f1db Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Sun, 26 Feb 2017 15:05:02 +0200 Subject: [PATCH 1/3] python: Fix compilation failure --- gdb/python/py-block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index 280dbad8b04..e1d44fe5647 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -174,8 +174,7 @@ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ DictIter_iter, /* tp_iter: __iter__() method */ -DictIter_iternext /* tp_iternext: next() method */, -.tp_new = PyType_GenericNew +DictIter_iternext /* tp_iternext: next() method */ }; static PyObject * @@ -538,6 +537,7 @@ gdbpy_initialize_blocks (void) if (PyType_Ready (&block_syms_iterator_object_type) < 0) return -1; + DictIterType.tp_new = PyType_GenericNew; if (PyType_Ready(&DictIterType) < 0) return -1; /* Register an objfile "free" callback so we can properly invalidate blocks when an object file is about to be From df02ecb5141adffb72d717b73019b9b15b210f4f Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Tue, 21 Feb 2017 18:45:58 +0200 Subject: [PATCH 2/3] py-target: Change unsigned long -> uintptr_t --- gdb/python/py-target.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/python/py-target.c b/gdb/python/py-target.c index d0cd109dcf4..fae872b2777 100644 --- a/gdb/python/py-target.c +++ b/gdb/python/py-target.c @@ -748,10 +748,11 @@ enum target_names { static PyObject * tgt_py_get_name (PyObject *self, void * arg) { - enum target_names target_string = (enum target_names) (unsigned long)arg; + enum target_names target_string = (enum target_names) (intptr_t)arg; pytarget_object *target_obj = (pytarget_object *) self; struct target_ops *ops = target_obj->ops; + PyObject *name; const char *shortname; @@ -789,7 +790,7 @@ tgt_py_get_name (PyObject *self, void * arg) static int tgt_py_set_name (PyObject *self, PyObject *newvalue, void * arg) { - enum target_names target_string = (enum target_names)(unsigned long) arg; + enum target_names target_string = (enum target_names) (intptr_t)arg; pytarget_object *target_obj = (pytarget_object *) self; struct target_ops *ops = target_obj->ops; char *name = NULL; From 0f11186f9b3888814ff235cdd0fb6500ca610575 Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Tue, 21 Feb 2017 18:55:10 +0200 Subject: [PATCH 3/3] gdb/py-target: Make the code compile against python3 * This is a first step in supporting python3 version. Most of the changes cope with the fact that there is no longer a PyString_* object. Instead there is either PyUnicode or PyBytes. In order to obtain a char* one must first convert the PyUnicode object to PyBytes, representing a byte array. And then get a pointer to the byte array. * Another thing is that there is no longer a PyInt. Everything is PyLong, so comment out a PyInt check in register_set_value. (cherry picked from commit 6c1337293ad98d6178b3d6c2f21edbe74e967e22) --- gdb/python/py-block.c | 3 +-- gdb/python/py-minsymbol.c | 34 +++++++++++++++++++++++++++++----- gdb/python/py-register.c | 2 ++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index e1d44fe5647..50f1ab3fb83 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -147,8 +147,7 @@ PyObject* DictIter_iternext(PyObject *self) } static PyTypeObject DictIterType = { -PyObject_HEAD_INIT(NULL) -0, /*ob_size*/ +PyVarObject_HEAD_INIT (NULL, 0) "gdb._DictIter", /*tp_name*/ sizeof(DictIter), /*tp_basicsize*/ 0, /*tp_itemsize*/ diff --git a/gdb/python/py-minsymbol.c b/gdb/python/py-minsymbol.c index d98c9933e38..ac4f06cf485 100644 --- a/gdb/python/py-minsymbol.c +++ b/gdb/python/py-minsymbol.c @@ -319,6 +319,9 @@ gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, PyObject *kw) static char *keywords[] = { "name", "sfile", "objfile", NULL }; struct bound_minimal_symbol bound_minsym = {}; PyObject *msym_obj = NULL, *sfile_obj = NULL, *objfile_obj = NULL; +#if PY_MAJOR_VERSION >= 3 + PyObject *temp = NULL; +#endif if (!PyArg_ParseTupleAndKeywords (args, kw, "s|OO", keywords, &name, &sfile_obj, &objfile_obj)) @@ -326,16 +329,33 @@ gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, PyObject *kw) if (sfile_obj && sfile_obj != Py_None) { - sfile = PyString_AsString (sfile_obj); - if (!sfile) - return NULL; +#if PY_MAJOR_VERSION >= 3 + temp = PyUnicode_AsASCIIString(sfile_obj); + if (!temp) + return NULL; + + sfile = PyBytes_AsString(temp); +#else + sfile = PyString_AsString(sfile_obj); +#endif + + if (!sfile) { +#if PY_MAJOR_VERSION >= 3 + Py_DECREF(temp); +#endif + return NULL; + } } if (objfile_obj && objfile_obj != Py_None) { objfile = objfpy_object_to_objfile (objfile_obj); - if (!objfile) - return NULL; + if (!objfile) { +#if PY_MAJOR_VERSION >= 3 + Py_DECREF(temp); +#endif + return NULL; + } } TRY @@ -348,6 +368,10 @@ gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, PyObject *kw) } END_CATCH +#if PY_MAJOR_VERSION >= 3 + Py_XDECREF(temp); +#endif + if (bound_minsym.minsym) msym_obj = bound_minsym_to_minsym_object (&bound_minsym); diff --git a/gdb/python/py-register.c b/gdb/python/py-register.c index c2dc62418cf..8281fd7bf0d 100644 --- a/gdb/python/py-register.c +++ b/gdb/python/py-register.c @@ -205,6 +205,7 @@ register_set_value(PyObject *self, PyObject *value_obj, void *closure) ret = write_register (regcache, obj->regnum, &ul_value); } } +#if PY_MAJOR_VERSION < 3 else if (PyInt_Check (value_obj)) { ul_value = PyInt_AsUnsignedLongMask (value_obj); @@ -216,6 +217,7 @@ register_set_value(PyObject *self, PyObject *value_obj, void *closure) ret = write_register (regcache, obj->regnum, &ul_value); } } +#endif else { value = value_object_to_value(value_obj);