* [PATCH] scripts/gdb/symbols: follow up on refactoring for const struct bin_attribute
@ 2025-01-12 12:21 Koichiro Den
2025-02-13 4:38 ` Mohamed Khalfella
0 siblings, 1 reply; 5+ messages in thread
From: Koichiro Den @ 2025-01-12 12:21 UTC (permalink / raw)
To: linux-next; +Cc: jan.kiszka, kbingham, linux-kernel
The work for 'const struct bin_attribute' [1] was merged into linux-next
but did not include updates to the lx-symbols code. So it now fails with
the following error:
Python Exception <class 'gdb.error'>: There is no member named nsections.
Error occurred in Python: There is no member named nsections.
Restore its functionality by aligning it with those changes on
kernel/module/sysfs.c.
[1] https://lore.kernel.org/all/20241227-sysfs-const-bin_attr-module-v2-0-e267275f0f37@weissschuh.net/
Signed-off-by: Koichiro Den <koichiro.den@canonical•com>
---
scripts/gdb/linux/symbols.py | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
index f6c1b063775a..8efefd30df49 100644
--- a/scripts/gdb/linux/symbols.py
+++ b/scripts/gdb/linux/symbols.py
@@ -89,16 +89,26 @@ lx-symbols command."""
return name
return None
+ def _iter_bin_attrs(self, bin_attrs):
+ while True:
+ try:
+ bin_attr = bin_attrs.dereference()
+ except gdb.MemoryError:
+ break
+ if bin_attr == 0:
+ break
+ yield bin_attr
+ bin_attrs += 1
+
def _section_arguments(self, module, module_addr):
try:
sect_attrs = module['sect_attrs'].dereference()
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']))}
+ bin_attr['attr']['name'].string(): bin_attr['private']
+ for bin_attr in self._iter_bin_attrs(sect_attrs['grp']['bin_attrs'])}
textaddr = section_name_to_address.get(".text", module_addr)
args = []
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] scripts/gdb/symbols: follow up on refactoring for const struct bin_attribute
2025-01-12 12:21 [PATCH] scripts/gdb/symbols: follow up on refactoring for const struct bin_attribute Koichiro Den
@ 2025-02-13 4:38 ` Mohamed Khalfella
2025-02-27 0:17 ` Mohamed Khalfella
0 siblings, 1 reply; 5+ messages in thread
From: Mohamed Khalfella @ 2025-02-13 4:38 UTC (permalink / raw)
To: Koichiro Den
Cc: linux-next, jan.kiszka, kbingham, linux-kernel,
Thomas Weißschuh
On 2025-01-12 21:21:49 +0900, Koichiro Den wrote:
> The work for 'const struct bin_attribute' [1] was merged into linux-next
> but did not include updates to the lx-symbols code. So it now fails with
> the following error:
> Python Exception <class 'gdb.error'>: There is no member named nsections.
> Error occurred in Python: There is no member named nsections.
>
> Restore its functionality by aligning it with those changes on
> kernel/module/sysfs.c.
>
> [1] https://lore.kernel.org/all/20241227-sysfs-const-bin_attr-module-v2-0-e267275f0f37@weissschuh.net/
>
> Signed-off-by: Koichiro Den <koichiro.den@canonical•com>
> ---
> scripts/gdb/linux/symbols.py | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
> index f6c1b063775a..8efefd30df49 100644
> --- a/scripts/gdb/linux/symbols.py
> +++ b/scripts/gdb/linux/symbols.py
> @@ -89,16 +89,26 @@ lx-symbols command."""
> return name
> return None
>
> + def _iter_bin_attrs(self, bin_attrs):
> + while True:
> + try:
> + bin_attr = bin_attrs.dereference()
> + except gdb.MemoryError:
This should not result in an exception. The array should at least have
one element on it, that is the NULL terminator.
> + break
> + if bin_attr == 0:
> + break
> + yield bin_attr
> + bin_attrs += 1
> +
> def _section_arguments(self, module, module_addr):
> try:
> sect_attrs = module['sect_attrs'].dereference()
> 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']))}
> + bin_attr['attr']['name'].string(): bin_attr['private']
> + for bin_attr in self._iter_bin_attrs(sect_attrs['grp']['bin_attrs'])}
>
> textaddr = section_name_to_address.get(".text", module_addr)
> args = []
> --
> 2.45.2
>
Hello Koichiro,
I hit the same problem came up with similar fix below. Of course I am
biased and I think my change is more concise. Feel free to take from it.
Looks like many commits changed this code and any of them would break
python code. Can you please add Fixes tag at least to the top commit.
34f5ec0f8252 ("module: sysfs: Drop 'struct module_sect_attr'")
4b2c11e4aaf7 ("module: sysfs: Drop member 'module_sect_attr::address'")
d8959b947a8d ("module: sysfs: Drop member 'module_sect_attrs::nsections'")
diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
index f6c1b063775a..e4865ec5aebe 100644
--- a/scripts/gdb/linux/symbols.py
+++ b/scripts/gdb/linux/symbols.py
@@ -95,10 +95,15 @@ 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 = {}
+ gattr = sect_attrs['grp']['bin_attrs']
+ battr = gattr.dereference()
+ while battr:
+ sec_name = battr['attr']['name'].string()
+ sec_addr = battr['private']
+ section_name_to_address[sec_name] = sec_addr
+ gattr = gattr + 1
+ battr = gattr.dereference()
textaddr = section_name_to_address.get(".text", module_addr)
args = []
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] scripts/gdb/symbols: follow up on refactoring for const struct bin_attribute
2025-02-13 4:38 ` Mohamed Khalfella
@ 2025-02-27 0:17 ` Mohamed Khalfella
2025-02-27 0:59 ` Koichiro Den
0 siblings, 1 reply; 5+ messages in thread
From: Mohamed Khalfella @ 2025-02-27 0:17 UTC (permalink / raw)
To: Koichiro Den, Jan Kiszka, Kieran Bingham, Andrew Morton,
Etienne Buira, Andrew Ballance
Cc: linux-next, linux-kernel, Thomas Weißschuh
On 2025-02-12 20:38:06 -0800, Mohamed Khalfella wrote:
> On 2025-01-12 21:21:49 +0900, Koichiro Den wrote:
> > The work for 'const struct bin_attribute' [1] was merged into linux-next
> > but did not include updates to the lx-symbols code. So it now fails with
> > the following error:
> > Python Exception <class 'gdb.error'>: There is no member named nsections.
> > Error occurred in Python: There is no member named nsections.
> >
> > Restore its functionality by aligning it with those changes on
> > kernel/module/sysfs.c.
> >
> > [1] https://lore.kernel.org/all/20241227-sysfs-const-bin_attr-module-v2-0-e267275f0f37@weissschuh.net/
> >
> > Signed-off-by: Koichiro Den <koichiro.den@canonical•com>
> > ---
> > scripts/gdb/linux/symbols.py | 16 +++++++++++++---
> > 1 file changed, 13 insertions(+), 3 deletions(-)
> >
> > diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
> > index f6c1b063775a..8efefd30df49 100644
> > --- a/scripts/gdb/linux/symbols.py
> > +++ b/scripts/gdb/linux/symbols.py
> > @@ -89,16 +89,26 @@ lx-symbols command."""
> > return name
> > return None
> >
> > + def _iter_bin_attrs(self, bin_attrs):
> > + while True:
> > + try:
> > + bin_attr = bin_attrs.dereference()
> > + except gdb.MemoryError:
>
> This should not result in an exception. The array should at least have
> one element on it, that is the NULL terminator.
>
> > + break
> > + if bin_attr == 0:
> > + break
> > + yield bin_attr
> > + bin_attrs += 1
> > +
> > def _section_arguments(self, module, module_addr):
> > try:
> > sect_attrs = module['sect_attrs'].dereference()
> > 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']))}
> > + bin_attr['attr']['name'].string(): bin_attr['private']
> > + for bin_attr in self._iter_bin_attrs(sect_attrs['grp']['bin_attrs'])}
> >
> > textaddr = section_name_to_address.get(".text", module_addr)
> > args = []
> > --
> > 2.45.2
> >
>
> Hello Koichiro,
>
> I hit the same problem came up with similar fix below. Of course I am
> biased and I think my change is more concise. Feel free to take from it.
> Looks like many commits changed this code and any of them would break
> python code. Can you please add Fixes tag at least to the top commit.
>
> 34f5ec0f8252 ("module: sysfs: Drop 'struct module_sect_attr'")
> 4b2c11e4aaf7 ("module: sysfs: Drop member 'module_sect_attr::address'")
> d8959b947a8d ("module: sysfs: Drop member 'module_sect_attrs::nsections'")
>
> diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
> index f6c1b063775a..e4865ec5aebe 100644
> --- a/scripts/gdb/linux/symbols.py
> +++ b/scripts/gdb/linux/symbols.py
> @@ -95,10 +95,15 @@ 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 = {}
> + gattr = sect_attrs['grp']['bin_attrs']
> + battr = gattr.dereference()
> + while battr:
> + sec_name = battr['attr']['name'].string()
> + sec_addr = battr['private']
> + section_name_to_address[sec_name] = sec_addr
> + gattr = gattr + 1
> + battr = gattr.dereference()
>
> textaddr = section_name_to_address.get(".text", module_addr)
> args = []
ping
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scripts/gdb/symbols: follow up on refactoring for const struct bin_attribute
2025-02-27 0:17 ` Mohamed Khalfella
@ 2025-02-27 0:59 ` Koichiro Den
2025-02-27 1:05 ` Mohamed Khalfella
0 siblings, 1 reply; 5+ messages in thread
From: Koichiro Den @ 2025-02-27 0:59 UTC (permalink / raw)
To: Mohamed Khalfella
Cc: Jan Kiszka, Kieran Bingham, Andrew Morton, Etienne Buira,
Andrew Ballance, linux-next, linux-kernel, Thomas Weißschuh
On Wed, Feb 26, 2025 at 04:17:59PM GMT, Mohamed Khalfella wrote:
> On 2025-02-12 20:38:06 -0800, Mohamed Khalfella wrote:
> > On 2025-01-12 21:21:49 +0900, Koichiro Den wrote:
> > > The work for 'const struct bin_attribute' [1] was merged into linux-next
> > > but did not include updates to the lx-symbols code. So it now fails with
> > > the following error:
> > > Python Exception <class 'gdb.error'>: There is no member named nsections.
> > > Error occurred in Python: There is no member named nsections.
> > >
> > > Restore its functionality by aligning it with those changes on
> > > kernel/module/sysfs.c.
> > >
> > > [1] https://lore.kernel.org/all/20241227-sysfs-const-bin_attr-module-v2-0-e267275f0f37@weissschuh.net/
> > >
> > > Signed-off-by: Koichiro Den <koichiro.den@canonical•com>
> > > ---
> > > scripts/gdb/linux/symbols.py | 16 +++++++++++++---
> > > 1 file changed, 13 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
> > > index f6c1b063775a..8efefd30df49 100644
> > > --- a/scripts/gdb/linux/symbols.py
> > > +++ b/scripts/gdb/linux/symbols.py
> > > @@ -89,16 +89,26 @@ lx-symbols command."""
> > > return name
> > > return None
> > >
> > > + def _iter_bin_attrs(self, bin_attrs):
> > > + while True:
> > > + try:
> > > + bin_attr = bin_attrs.dereference()
> > > + except gdb.MemoryError:
> >
> > This should not result in an exception. The array should at least have
> > one element on it, that is the NULL terminator.
> >
> > > + break
> > > + if bin_attr == 0:
> > > + break
> > > + yield bin_attr
> > > + bin_attrs += 1
> > > +
> > > def _section_arguments(self, module, module_addr):
> > > try:
> > > sect_attrs = module['sect_attrs'].dereference()
> > > 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']))}
> > > + bin_attr['attr']['name'].string(): bin_attr['private']
> > > + for bin_attr in self._iter_bin_attrs(sect_attrs['grp']['bin_attrs'])}
> > >
> > > textaddr = section_name_to_address.get(".text", module_addr)
> > > args = []
> > > --
> > > 2.45.2
> > >
> >
> > Hello Koichiro,
> >
> > I hit the same problem came up with similar fix below. Of course I am
> > biased and I think my change is more concise. Feel free to take from it.
> > Looks like many commits changed this code and any of them would break
> > python code. Can you please add Fixes tag at least to the top commit.
> >
> > 34f5ec0f8252 ("module: sysfs: Drop 'struct module_sect_attr'")
> > 4b2c11e4aaf7 ("module: sysfs: Drop member 'module_sect_attr::address'")
> > d8959b947a8d ("module: sysfs: Drop member 'module_sect_attrs::nsections'")
> >
> > diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
> > index f6c1b063775a..e4865ec5aebe 100644
> > --- a/scripts/gdb/linux/symbols.py
> > +++ b/scripts/gdb/linux/symbols.py
> > @@ -95,10 +95,15 @@ 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 = {}
> > + gattr = sect_attrs['grp']['bin_attrs']
> > + battr = gattr.dereference()
> > + while battr:
> > + sec_name = battr['attr']['name'].string()
> > + sec_addr = battr['private']
> > + section_name_to_address[sec_name] = sec_addr
> > + gattr = gattr + 1
> > + battr = gattr.dereference()
> >
> > textaddr = section_name_to_address.get(".text", module_addr)
> > args = []
>
> ping
>
Sorry for the delayed response.
I have no objections. Please go ahead and submit your patch. There is no
need to mention this original submission, nor CC me.
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scripts/gdb/symbols: follow up on refactoring for const struct bin_attribute
2025-02-27 0:59 ` Koichiro Den
@ 2025-02-27 1:05 ` Mohamed Khalfella
0 siblings, 0 replies; 5+ messages in thread
From: Mohamed Khalfella @ 2025-02-27 1:05 UTC (permalink / raw)
To: Koichiro Den
Cc: Jan Kiszka, Kieran Bingham, Andrew Morton, Etienne Buira,
Andrew Ballance, linux-next, linux-kernel, Thomas Weißschuh
On 2025-02-27 09:59:23 +0900, Koichiro Den wrote:
>
> Sorry for the delayed response.
> I have no objections. Please go ahead and submit your patch. There is no
> need to mention this original submission, nor CC me.
>
> Thanks!
Koichiro - You reported this issue first and came up with a fix for it.
Unless you do not want to, I think you should the one who fixes this
bug. How about you re-submit a patch with combination of your original
patch and the diff I posted?
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-27 1:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-12 12:21 [PATCH] scripts/gdb/symbols: follow up on refactoring for const struct bin_attribute Koichiro Den
2025-02-13 4:38 ` Mohamed Khalfella
2025-02-27 0:17 ` Mohamed Khalfella
2025-02-27 0:59 ` Koichiro Den
2025-02-27 1:05 ` Mohamed Khalfella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox