Re: [PATCH 1/5] gdb/python: handle saving user registers in a frame unwinder

Simon Marchi via Gdb-patches
2021-06-07T17:22:03Z

On 2021-06-07 1:07 p.m., Lancelot SIX via Gdb-patches wrote:
> Hi,
>
> I just have a minor stylistic remark in the python code in the test:
>
>> […]
>> +
>> + def __call__(self, pending_frame):
>> + pc_desc = pending_frame.architecture().registers().find("pc")
>> + pc = pending_frame.read_register(pc_desc)
>> +
>> + sp_desc = pending_frame.architecture().registers().find("sp")
>> + sp = pending_frame.read_register(sp_desc)
>> +
>> + block = gdb.block_for_pc(int(pc))
>> + if block == None:
>
> When looking for None, it is usually prefered to use 'is None' instead
> of '== None'. The result is the same unless there is a strange overload
> of __eq__.
>
> This pattern can also be seen in patch 3 and 4 of your series (patch 4
> using both '==' and 'is' to check for None).

I agree, that's the convention in Python. It is not in our coding
standards, but I suggest using flake8 to check the Python code, it
reports this (and much more):

$ flake8 testsuite/gdb.python/py-unwind-user-regs.py
testsuite/gdb.python/py-unwind-user-regs.py:52:18: E711 comparison to None should be 'if cond is None:'
testsuite/gdb.python/py-unwind-user-regs.py:55:17: E711 comparison to None should be 'if cond is None:'

Simon