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

Simon Marchi simon.marchi@polymtl.ca
Wed Mar 23 12:14:59 GMT 2022



On 2022-03-22 09:19, Andrew Burgess wrote:
> 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
> 

Hmm, I see these failures:

145 python print("Got: " + gdb.format_address(0x1129))^M
146 Got: 0x1129 <bar>^M
147 (gdb) FAIL: gdb.python/py-format-address.exp: gdb.format_address for bar, while inferior 2 is selected
148 python print("Got: " + gdb.format_address(0x1129, inf2.progspace, inf2.architecture()))^M
149 Got: 0x1129 <bar>^M
150 (gdb) FAIL: gdb.python/py-format-address.exp: gdb.format_address for bar, while inferior 2 is selected, pass progspace and architecture
151 inferior 1^M
152 [Switching to inferior 1 [process 1874961] (/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.python/py-format-address/py-format-address-foo)]^M
153 [Switching to thread 1.1 (process 1874961)]^M
154 #0  main () at /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.python/py-format-address.c:31^M
155 31        return FUNCTION_NAME ();^M
156 (gdb) PASS: gdb.python/py-format-address.exp: inferior 1
157 python print("Got: " + gdb.format_address(0x1129, inf2.progspace, inf2.architecture()))^M
158 Got: 0x1129 <bar>^M
159 (gdb) FAIL: gdb.python/py-format-address.exp: gdb.format_address for bar, while inferior 1 is selected, pass progspace and architecture

Simon


More information about the Gdb-patches mailing list