aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-arch.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-06-05 07:42:12 -0600
committerTom Tromey <tom@tromey.com>2022-07-08 14:14:58 -0600
commitd19ca0b35c9536210c5e8bd30504489b7439f51f (patch)
treea488182e25b0d0a16eea68ab816c986988c28cfd /gdb/python/py-arch.c
parentfa17a6814113ac22d8059d61514aa2c6e29b0aae (diff)
downloadbinutils-d19ca0b35c9536210c5e8bd30504489b7439f51f.zip
binutils-d19ca0b35c9536210c5e8bd30504489b7439f51f.tar.gz
binutils-d19ca0b35c9536210c5e8bd30504489b7439f51f.tar.bz2
Accept gdb.Value in more Python APIs
PR python/27000 points out that gdb.block_for_pc will accept a Python integer, but not a gdb.Value. This patch corrects this oversight. I looked at all uses of GDB_PY_LLU_ARG and fixed these up to use get_addr_from_python instead. I also looked at uses of GDB_PY_LL_ARG, but those seemed relatively unlikely to be useful with a gdb.Value, so I didn't change them. My thinking here is that a Value will typically come from inferior memory, and something like a line number is not too likely to be found this way. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27000
Diffstat (limited to 'gdb/python/py-arch.c')
-rw-r--r--gdb/python/py-arch.c33
1 files changed, 10 insertions, 23 deletions
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index d8098a2..594e4ed 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -122,39 +122,26 @@ static PyObject *
archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
{
static const char *keywords[] = { "start_pc", "end_pc", "count", NULL };
- CORE_ADDR start, end = 0;
+ CORE_ADDR start = 0, end = 0;
CORE_ADDR pc;
- gdb_py_ulongest start_temp;
long count = 0, i;
- PyObject *end_obj = NULL, *count_obj = NULL;
+ PyObject *start_obj = nullptr, *end_obj = nullptr, *count_obj = nullptr;
struct gdbarch *gdbarch = NULL;
ARCHPY_REQUIRE_VALID (self, gdbarch);
- if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, GDB_PY_LLU_ARG "|OO",
- keywords, &start_temp, &end_obj,
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O|OO",
+ keywords, &start_obj, &end_obj,
&count_obj))
return NULL;
- start = start_temp;
- if (end_obj)
- {
- /* Make a long logic check first. In Python 3.x, internally,
- all integers are represented as longs. In Python 2.x, there
- is still a differentiation internally between a PyInt and a
- PyLong. Explicitly do this long check conversion first. In
- GDB, for Python 3.x, we #ifdef PyInt = PyLong. This check has
- to be done first to ensure we do not lose information in the
- conversion process. */
- if (PyLong_Check (end_obj))
- end = PyLong_AsUnsignedLongLong (end_obj);
- else
- {
- PyErr_SetString (PyExc_TypeError,
- _("Argument 'end_pc' should be a (long) integer."));
+ if (get_addr_from_python (start_obj, &start) < 0)
+ return nullptr;
- return NULL;
- }
+ if (end_obj != nullptr)
+ {
+ if (get_addr_from_python (end_obj, &end) < 0)
+ return nullptr;
if (end < start)
{