aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2020-09-15 11:08:56 -0600
committerTom Tromey <tromey@adacore.com>2020-09-15 11:08:56 -0600
commitd1cab9876d72d867b2de82688f5f5a2a4b655edb (patch)
treee427c640bc2fe1ebd2e57fd16408901df0161516 /gdb/python
parent4bde49dc81c5c16189af70b9a144dbb5651994f1 (diff)
downloadfsf-binutils-gdb-d1cab9876d72d867b2de82688f5f5a2a4b655edb.zip
fsf-binutils-gdb-d1cab9876d72d867b2de82688f5f5a2a4b655edb.tar.gz
fsf-binutils-gdb-d1cab9876d72d867b2de82688f5f5a2a4b655edb.tar.bz2
Don't use gdb_py_long_from_ulongest
Remove the gdb_py_long_from_ulongest defines and change the Python layer to prefer gdb_py_object_from_ulongest. While writing this I noticed that the error handling in archpy_disassemble was incorrect -- it could call PyDict_SetItemString with a NULL value. This patch also fixes this bug. gdb/ChangeLog 2020-09-15 Tom Tromey <tromey@adacore.com> * python/python-internal.h (gdb_py_long_from_ulongest): Remove defines. * python/py-value.c (valpy_long): Use gdb_py_object_from_ulongest. * python/py-symtab.c (salpy_get_pc): Use gdb_py_object_from_ulongest. (salpy_get_last): Likewise. * python/py-record-btrace.c (recpy_bt_insn_pc): Use gdb_py_object_from_ulongest. * python/py-lazy-string.c (stpy_get_address): Use gdb_py_object_from_ulongest. * python/py-frame.c (frapy_pc): Use gdb_py_object_from_ulongest. * python/py-arch.c (archpy_disassemble): Use gdb_py_object_from_ulongest and gdb_py_object_from_longest. Fix error handling.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-arch.c25
-rw-r--r--gdb/python/py-frame.c2
-rw-r--r--gdb/python/py-lazy-string.c2
-rw-r--r--gdb/python/py-record-btrace.c2
-rw-r--r--gdb/python/py-symtab.c4
-rw-r--r--gdb/python/py-value.c2
-rw-r--r--gdb/python/python-internal.h2
7 files changed, 23 insertions, 16 deletions
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index d9eaf81..3f8e769 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -209,14 +209,23 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- if (PyDict_SetItemString (insn_dict.get (), "addr",
- gdb_py_long_from_ulongest (pc))
- || PyDict_SetItemString (insn_dict.get (), "asm",
- PyString_FromString (!stb.empty ()
- ? stb.c_str ()
- : "<unknown>"))
- || PyDict_SetItemString (insn_dict.get (), "length",
- PyInt_FromLong (insn_len)))
+ gdbpy_ref<> pc_obj = gdb_py_object_from_ulongest (pc);
+ if (pc_obj == nullptr)
+ return nullptr;
+
+ gdbpy_ref<> asm_obj (PyString_FromString (!stb.empty ()
+ ? stb.c_str ()
+ : "<unknown>"));
+ if (asm_obj == nullptr)
+ return nullptr;
+
+ gdbpy_ref<> len_obj = gdb_py_object_from_longest (insn_len);
+ if (len_obj == nullptr)
+ return nullptr;
+
+ if (PyDict_SetItemString (insn_dict.get (), "addr", pc_obj.get ())
+ || PyDict_SetItemString (insn_dict.get (), "asm", asm_obj.get ())
+ || PyDict_SetItemString (insn_dict.get (), "length", len_obj.get ()))
return NULL;
pc += insn_len;
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index e121afb..0907055 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -232,7 +232,7 @@ frapy_pc (PyObject *self, PyObject *args)
GDB_PY_HANDLE_EXCEPTION (except);
}
- return gdb_py_long_from_ulongest (pc);
+ return gdb_py_object_from_ulongest (pc).release ();
}
/* Implementation of gdb.Frame.read_register (self, register) -> gdb.Value.
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index f71bb1d..401c0a6 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -61,7 +61,7 @@ stpy_get_address (PyObject *self, void *closure)
{
lazy_string_object *self_string = (lazy_string_object *) self;
- return gdb_py_long_from_ulongest (self_string->address);
+ return gdb_py_object_from_ulongest (self_string->address).release ();
}
static PyObject *
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 84a3d9e..762c0bc 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -232,7 +232,7 @@ recpy_bt_insn_pc (PyObject *self, void *closure)
if (insn == NULL)
return NULL;
- return gdb_py_long_from_ulongest (insn->pc);
+ return gdb_py_object_from_ulongest (insn->pc).release ();
}
/* Implementation of RecordInstruction.size [int] for btrace.
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 6229bc5..b0e7618 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -264,7 +264,7 @@ salpy_get_pc (PyObject *self, void *closure)
SALPY_REQUIRE_VALID (self, sal);
- return gdb_py_long_from_ulongest (sal->pc);
+ return gdb_py_object_from_ulongest (sal->pc).release ();
}
/* Implementation of the get method for the 'last' attribute of
@@ -278,7 +278,7 @@ salpy_get_last (PyObject *self, void *closure)
SALPY_REQUIRE_VALID (self, sal);
if (sal->end > 0)
- return gdb_py_long_from_ulongest (sal->end - 1);
+ return gdb_py_object_from_ulongest (sal->end - 1).release ();
else
Py_RETURN_NONE;
}
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 504a9de..bb88bf3 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1731,7 +1731,7 @@ valpy_long (PyObject *self)
}
if (type->is_unsigned ())
- return gdb_py_long_from_ulongest (l);
+ return gdb_py_object_from_ulongest (l).release ();
else
return gdb_py_object_from_longest (l).release ();
}
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index b93c78f..2c4195f 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -126,7 +126,6 @@
#define GDB_PY_LLU_ARG "K"
typedef PY_LONG_LONG gdb_py_longest;
typedef unsigned PY_LONG_LONG gdb_py_ulongest;
-#define gdb_py_long_from_ulongest PyLong_FromUnsignedLongLong
#define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong
#else /* HAVE_LONG_LONG */
@@ -135,7 +134,6 @@ typedef unsigned PY_LONG_LONG gdb_py_ulongest;
#define GDB_PY_LLU_ARG "K"
typedef long gdb_py_longest;
typedef unsigned long gdb_py_ulongest;
-#define gdb_py_long_from_ulongest PyLong_FromUnsignedLong
#define gdb_py_long_as_ulongest PyLong_AsUnsignedLong
#endif /* HAVE_LONG_LONG */