aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-arch.c
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/py-arch.c
parent4bde49dc81c5c16189af70b9a144dbb5651994f1 (diff)
downloadbinutils-d1cab9876d72d867b2de82688f5f5a2a4b655edb.zip
binutils-d1cab9876d72d867b2de82688f5f5a2a4b655edb.tar.gz
binutils-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/py-arch.c')
-rw-r--r--gdb/python/py-arch.c25
1 files changed, 17 insertions, 8 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;