[PATCH v2] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs

Antonio Quartulli posted 1 patch 9 months, 3 weeks ago
scripts/gdb/linux/symbols.py | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
[PATCH v2] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs
Posted by Antonio Quartulli 9 months, 3 weeks ago
When loading symbols from kernel modules we used to iterate
from 0 to module_sect_attrs::nsections, in order to
retrieve their name and address.

However module_sect_attrs::nsections has been removed from
the struct by a previous commit.

Re-arrange the iteration by accessing all items in
module_sect_attrs::grp::bin_attrs[] until NULL is found
(it's a NULL terminated array).

At the same time the symbol address cannot be extracted
from module_sect_attrs::attrs[]::address anymore because
it has also been deleted. Fetch it from
module_sect_attrs::grp::bin_attrs[]::private as described
in 4b2c11e4aaf7.

Fixes: d8959b947a8d ("module: sysfs: Drop member 'module_sect_attrs::nsections'")
Fixes: 4b2c11e4aaf7 ("module: sysfs: Drop member 'module_sect_attr::address'")
Cc: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---

Changes in v2:
* changed attr['attr']['name'] to attr['attr']['name'].string() to
  ensure extracted value is a string, otherwise an exception is thrown


 scripts/gdb/linux/symbols.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
index f6c1b063775a..15d76f7d8ebc 100644
--- a/scripts/gdb/linux/symbols.py
+++ b/scripts/gdb/linux/symbols.py
@@ -15,6 +15,7 @@ import gdb
 import os
 import re
 
+from itertools import count
 from linux import modules, utils, constants
 
 
@@ -95,10 +96,14 @@ lx-symbols command."""
         except gdb.error:
             return str(module_addr)
 
-        attrs = sect_attrs['attrs']
-        section_name_to_address = {
-            attrs[n]['battr']['attr']['name'].string(): attrs[n]['address']
-            for n in range(int(sect_attrs['nsections']))}
+        section_name_to_address = {}
+        for i in count():
+            # this is a NULL terminated array
+            if sect_attrs['grp']['bin_attrs'][i] == 0x0:
+                break
+
+            attr = sect_attrs['grp']['bin_attrs'][i].dereference()
+            section_name_to_address[attr['attr']['name'].string()] = attr['private']
 
         textaddr = section_name_to_address.get(".text", module_addr)
         args = []
-- 
2.45.3

Re: [PATCH v2] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs
Posted by Jan Kiszka 9 months, 3 weeks ago
On 21.02.25 21:40, Antonio Quartulli wrote:
> When loading symbols from kernel modules we used to iterate
> from 0 to module_sect_attrs::nsections, in order to
> retrieve their name and address.
> 
> However module_sect_attrs::nsections has been removed from
> the struct by a previous commit.
> 
> Re-arrange the iteration by accessing all items in
> module_sect_attrs::grp::bin_attrs[] until NULL is found
> (it's a NULL terminated array).
> 
> At the same time the symbol address cannot be extracted
> from module_sect_attrs::attrs[]::address anymore because
> it has also been deleted. Fetch it from
> module_sect_attrs::grp::bin_attrs[]::private as described
> in 4b2c11e4aaf7.
> 
> Fixes: d8959b947a8d ("module: sysfs: Drop member 'module_sect_attrs::nsections'")
> Fixes: 4b2c11e4aaf7 ("module: sysfs: Drop member 'module_sect_attr::address'")
> Cc: Thomas Weißschuh <linux@weissschuh.net>
> Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
> ---
> 
> Changes in v2:
> * changed attr['attr']['name'] to attr['attr']['name'].string() to
>   ensure extracted value is a string, otherwise an exception is thrown
> 
> 
>  scripts/gdb/linux/symbols.py | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
> index f6c1b063775a..15d76f7d8ebc 100644
> --- a/scripts/gdb/linux/symbols.py
> +++ b/scripts/gdb/linux/symbols.py
> @@ -15,6 +15,7 @@ import gdb
>  import os
>  import re
>  
> +from itertools import count
>  from linux import modules, utils, constants
>  
>  
> @@ -95,10 +96,14 @@ lx-symbols command."""
>          except gdb.error:
>              return str(module_addr)
>  
> -        attrs = sect_attrs['attrs']
> -        section_name_to_address = {
> -            attrs[n]['battr']['attr']['name'].string(): attrs[n]['address']
> -            for n in range(int(sect_attrs['nsections']))}
> +        section_name_to_address = {}
> +        for i in count():
> +            # this is a NULL terminated array
> +            if sect_attrs['grp']['bin_attrs'][i] == 0x0:
> +                break
> +
> +            attr = sect_attrs['grp']['bin_attrs'][i].dereference()
> +            section_name_to_address[attr['attr']['name'].string()] = attr['private']
>  
>          textaddr = section_name_to_address.get(".text", module_addr)
>          args = []

Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com>

Thanks,
Jan

-- 
Siemens AG, Foundational Technologies
Linux Expert Center