summaryrefslogtreecommitdiff
path: root/scripts/gdb/linux/utils.py
diff options
context:
space:
mode:
authorAntonio Borneo <antonio.borneo@foss.st.com>2022-07-19 14:28:31 +0200
committerPetr Mladek <pmladek@suse.com>2022-07-21 15:32:52 +0200
commite3c8d33e0d62175c31ca7ab7ab01b18f0b6318d3 (patch)
tree6e2693311ac5b129dfaf3fb80b142d70498f2c81 /scripts/gdb/linux/utils.py
parent9a3bfa01aa1c5b5478edaf7c76ea0b3a94f9c13e (diff)
downloadlwn-e3c8d33e0d62175c31ca7ab7ab01b18f0b6318d3.tar.gz
lwn-e3c8d33e0d62175c31ca7ab7ab01b18f0b6318d3.zip
scripts/gdb: fix 'lx-dmesg' on 32 bits arch
The type atomic_long_t can have size 4 or 8 bytes, depending on CONFIG_64BIT; it's only content, the field 'counter', is either an int or a s64 value. Current code incorrectly uses the fixed size utils.read_u64() to read the field 'counter' inside atomic_long_t. On 32 bits architectures reading the last element 'tail_id' of the struct prb_desc_ring: struct prb_desc_ring { ... atomic_long_t tail_id; }; causes the utils.read_u64() to access outside the boundary of the struct and the gdb command 'lx-dmesg' exits with error: Python Exception <class 'IndexError'>: index out of range Error occurred in Python: index out of range Query the really used atomic_long_t counter type size. Link: https://lore.kernel.org/r/20220617143758.137307-1-antonio.borneo@foss.st.com Fixes: e60768311af8 ("scripts/gdb: update for lockless printk ringbuffer") Signed-off-by: Antonio Borneo <antonio.borneo@foss.st.com> [pmladek@suse.com: Query the really used atomic_long_t counter type size] Tested-by: Antonio Borneo <antonio.borneo@foss.st.com> Reviewed-by: John Ogness <john.ogness@linutronix.de> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20220719122831.19890-1-pmladek@suse.com
Diffstat (limited to 'scripts/gdb/linux/utils.py')
-rw-r--r--scripts/gdb/linux/utils.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py
index ff7c1799d588..1553f68716cc 100644
--- a/scripts/gdb/linux/utils.py
+++ b/scripts/gdb/linux/utils.py
@@ -35,13 +35,12 @@ class CachedType:
long_type = CachedType("long")
-
+atomic_long_type = CachedType("atomic_long_t")
def get_long_type():
global long_type
return long_type.get_type()
-
def offset_of(typeobj, field):
element = gdb.Value(0).cast(typeobj)
return int(str(element[field].address).split()[0], 16)
@@ -129,6 +128,17 @@ def read_ulong(buffer, offset):
else:
return read_u32(buffer, offset)
+atomic_long_counter_offset = atomic_long_type.get_type()['counter'].bitpos
+atomic_long_counter_sizeof = atomic_long_type.get_type()['counter'].type.sizeof
+
+def read_atomic_long(buffer, offset):
+ global atomic_long_counter_offset
+ global atomic_long_counter_sizeof
+
+ if atomic_long_counter_sizeof == 8:
+ return read_u64(buffer, offset + atomic_long_counter_offset)
+ else:
+ return read_u32(buffer, offset + atomic_long_counter_offset)
target_arch = None