[PATCHv3] gdb/python: add gdb.format_address function

Andrew Burgess aburgess@redhat.com
Tue Mar 22 13:19:50 GMT 2022


Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

>> diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
>> index 0f273b344e4..53906ce506e 100644
>> --- a/gdb/python/py-arch.c
>> +++ b/gdb/python/py-arch.c
>> @@ -62,16 +62,25 @@ arch_object_data_init (struct gdbarch *gdbarch)
>>  }
>>
>>  /* Returns the struct gdbarch value corresponding to the given Python
>> -   architecture object OBJ.  */
>> +   architecture object OBJ, which must be a gdb.Architecture object.  */
>>
>>  struct gdbarch *
>>  arch_object_to_gdbarch (PyObject *obj)
>>  {
>> -  arch_object *py_arch = (arch_object *) obj;
>> +  gdb_assert (PyObject_TypeCheck (obj, &arch_object_type));
>
> Since we have a function for that, I'd do:
>
>   gdb_assert (gdbpy_is_architecture (obj));
>
>> diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
>> index 1e01068c59b..f9f2a969e2b 100644
>> --- a/gdb/python/py-progspace.c
>> +++ b/gdb/python/py-progspace.c
>> @@ -504,6 +504,23 @@ pspace_to_pspace_object (struct program_space *pspace)
>>    return gdbpy_ref<>::new_reference (result);
>>  }
>>
>> +/* See python-internal.h.  */
>> +
>> +struct program_space *
>> +progspace_object_to_program_space (PyObject *obj)
>> +{
>> +  gdb_assert (PyObject_TypeCheck (obj, &pspace_object_type));
>
> Same here, use gdbpy_is_progspace.
>
> Otherwise, LGTM.

Thanks, I made those changes and pushed this patch.

Andrew



More information about the Gdb-patches mailing list