Re: [PATCH] scripts/gdb: fix list_for_each

From: Prekas, George
Date: Tue Sep 22 2020 - 13:17:38 EST



On 9/22/2020 9:32 AM, Jan Kiszka wrote:
>
> On 22.09.20 16:28, George Prekas wrote:
>> If the next pointer is NULL, list_for_each gets stuck in an infinite
>> loop.
>>
>> Signed-off-by: George Prekas <prekageo@xxxxxxxxxx>
>> ---
>>   scripts/gdb/linux/lists.py | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py
>> index c487ddf09d38..424a91c1aa8b 100644
>> --- a/scripts/gdb/linux/lists.py
>> +++ b/scripts/gdb/linux/lists.py
>> @@ -27,6 +27,8 @@ def list_for_each(head):
>>           raise TypeError("Must be struct list_head not {}"
>>                              .format(head.type))
>>
>> +    if head['next'] == 0:
>> +        return
>>       node = head['next'].dereference()
>>       while node.address != head.address:
>>           yield node.address
>
> Obviously, infinite loops are bad and should be avoided. But NULL is
> bug, isn't it? Shouldn't we report such a corruption?
>

Hi Jan,

Is it a bug? Or does it mean that the list is empty?

Let me give some background. If you do the following:

$ qemu-system-x86_64 -nographic -m 1024 -kernel build/arch/x86/boot/bzImage -s -S < /dev/null > /dev/null &
$ gdb -q build/vmlinux -ex 'target remote localhost:1234' -iex 'set auto-load safe-path /' -ex 'lx-symbols'

You will see:

loading vmlinux
scanning for modules in /home/ubuntu/linux-5.8.10
no module object found for ''

And the last line repeats forever. This happens because modules.next == NULL. This is the Python stack trace:

  File ".../symbols.py", line 174, in invoke
    self.load_all_symbols()
  File ".../symbols.py", line 161, in load_all_symbols
    [self.load_module_symbols(module) for module in module_list]
  File ".../symbols.py", line 161, in <listcomp>
    [self.load_module_symbols(module) for module in module_list]
  File ".../modules.py", line 30, in module_list
    for module in lists.list_for_each_entry(modules, module_ptr_type, "list"):
  File ".../lists.py", line 41, in list_for_each_entry
    for node in list_for_each(head):
  File ".../lists.py", line 31, in list_for_each
    traceback.print_stack()

This patch tries to fix the above problem.

George