aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-progspace.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-progspace.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-progspace.c')
-rw-r--r--gdb/python/py-progspace.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index a9abfb4..5ec5986 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -351,13 +351,17 @@ pspy_get_objfiles (PyObject *self_, PyObject *args)
static PyObject *
pspy_solib_name (PyObject *o, PyObject *args)
{
- gdb_py_ulongest pc;
+ CORE_ADDR pc;
+ PyObject *pc_obj;
+
pspace_object *self = (pspace_object *) o;
PSPY_REQUIRE_VALID (self);
- if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc))
+ if (!PyArg_ParseTuple (args, "O", &pc_obj))
return NULL;
+ if (get_addr_from_python (pc_obj, &pc) < 0)
+ return nullptr;
const char *soname = solib_name_from_address (self->pspace, pc);
if (soname == nullptr)
@@ -371,14 +375,17 @@ static PyObject *
pspy_block_for_pc (PyObject *o, PyObject *args)
{
pspace_object *self = (pspace_object *) o;
- gdb_py_ulongest pc;
+ CORE_ADDR pc;
+ PyObject *pc_obj;
const struct block *block = NULL;
struct compunit_symtab *cust = NULL;
PSPY_REQUIRE_VALID (self);
- if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc))
+ if (!PyArg_ParseTuple (args, "O", &pc_obj))
return NULL;
+ if (get_addr_from_python (pc_obj, &pc) < 0)
+ return nullptr;
try
{
@@ -410,24 +417,25 @@ pspy_block_for_pc (PyObject *o, PyObject *args)
static PyObject *
pspy_find_pc_line (PyObject *o, PyObject *args)
{
- gdb_py_ulongest pc_llu;
+ CORE_ADDR pc;
PyObject *result = NULL; /* init for gcc -Wall */
+ PyObject *pc_obj;
pspace_object *self = (pspace_object *) o;
PSPY_REQUIRE_VALID (self);
- if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc_llu))
+ if (!PyArg_ParseTuple (args, "O", &pc_obj))
return NULL;
+ if (get_addr_from_python (pc_obj, &pc) < 0)
+ return nullptr;
try
{
struct symtab_and_line sal;
- CORE_ADDR pc;
scoped_restore_current_program_space saver;
set_current_program_space (self->pspace);
- pc = (CORE_ADDR) pc_llu;
sal = find_pc_line (pc, 0);
result = symtab_and_line_to_sal_object (sal);
}