Skip to contentSkip to conversation

scripts/gdb: fix 'lx-symbols' section parsing

PATCH New Julian Blaauboer 1 participant 1 message Feb 23, 2021 GDB kernel debugging helper scripts

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/gdb: fix 'lx-symbols' section parsing

Loading a module using 'lx-symbols' in GDB would result in a gdb.MemoryError when parsing the section names and addresses because of the way GDB handles flexible array members. This patch fixes that issue by converting the 'struct module_sect_attr[]' into a pointer before accessing it.

---
 scripts/gdb/linux/symbols.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/gdb/linux/symbols.py +2 -1
index 1be9763cf8bb..6d3a33a00189 100644
@@ -94,7 +94,8 @@ lx-symbols command."""
             sect_attrs = module['sect_attrs'].dereference()
         except gdb.error:
             return ""
-        attrs = sect_attrs['attrs']
+        # Convert from struct module_sect_attr[] to struct module_sect_attr*
+        attrs = sect_attrs['attrs'].dereference().address
         section_name_to_address = {
             attrs[n]['battr']['attr']['name'].string(): attrs[n]['address']
             for n in range(int(sect_attrs['nsections']))}
Signature · 1 line
2.30.1