aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Colledge <joel.colledge@linbit.com>2019-10-18 23:19:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-10-19 06:32:31 -0400
commitca210ba32ef7537b02731bfe255ed8eb1e4e2b59 (patch)
tree98a7918375b841cc78fd3f4a4f137030ba19db12
parent96c804a6ae8c59a9092b3d5dd581198472063184 (diff)
scripts/gdb: fix lx-dmesg when CONFIG_PRINTK_CALLER is set
When CONFIG_PRINTK_CALLER is set, struct printk_log contains an additional member caller_id. This affects the offset of the log text. Account for this by using the type information from gdb to determine all the offsets instead of using hardcoded values. This fixes following error: (gdb) lx-dmesg Python Exception <class 'ValueError'> embedded null character: Error occurred in Python command: embedded null character The read_u* utility functions now take an offset argument to make them easier to use. Link: http://lkml.kernel.org/r/20191011142500.2339-1-joel.colledge@linbit.com Signed-off-by: Joel Colledge <joel.colledge@linbit.com> Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com> Cc: Kieran Bingham <kbingham@kernel.org> Cc: Leonard Crestez <leonard.crestez@nxp.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--scripts/gdb/linux/dmesg.py16
-rw-r--r--scripts/gdb/linux/utils.py25
2 files changed, 25 insertions, 16 deletions
diff --git a/scripts/gdb/linux/dmesg.py b/scripts/gdb/linux/dmesg.py
index 6d2e09a2ad2f..2fa7bb83885f 100644
--- a/scripts/gdb/linux/dmesg.py
+++ b/scripts/gdb/linux/dmesg.py
@@ -16,6 +16,8 @@ import sys
16 16
17from linux import utils 17from linux import utils
18 18
19printk_log_type = utils.CachedType("struct printk_log")
20
19 21
20class LxDmesg(gdb.Command): 22class LxDmesg(gdb.Command):
21 """Print Linux kernel log buffer.""" 23 """Print Linux kernel log buffer."""
@@ -42,9 +44,14 @@ class LxDmesg(gdb.Command):
42 b = utils.read_memoryview(inf, log_buf_addr, log_next_idx) 44 b = utils.read_memoryview(inf, log_buf_addr, log_next_idx)
43 log_buf = a.tobytes() + b.tobytes() 45 log_buf = a.tobytes() + b.tobytes()
44 46
47 length_offset = printk_log_type.get_type()['len'].bitpos // 8
48 text_len_offset = printk_log_type.get_type()['text_len'].bitpos // 8
49 time_stamp_offset = printk_log_type.get_type()['ts_nsec'].bitpos // 8
50 text_offset = printk_log_type.get_type().sizeof
51
45 pos = 0 52 pos = 0
46 while pos < log_buf.__len__(): 53 while pos < log_buf.__len__():
47 length = utils.read_u16(log_buf[pos + 8:pos + 10]) 54 length = utils.read_u16(log_buf, pos + length_offset)
48 if length == 0: 55 if length == 0:
49 if log_buf_2nd_half == -1: 56 if log_buf_2nd_half == -1:
50 gdb.write("Corrupted log buffer!\n") 57 gdb.write("Corrupted log buffer!\n")
@@ -52,10 +59,11 @@ class LxDmesg(gdb.Command):
52 pos = log_buf_2nd_half 59 pos = log_buf_2nd_half
53 continue 60 continue
54 61
55 text_len = utils.read_u16(log_buf[pos + 10:pos + 12]) 62 text_len = utils.read_u16(log_buf, pos + text_len_offset)
56 text = log_buf[pos + 16:pos + 16 + text_len].decode( 63 text_start = pos + text_offset
64 text = log_buf[text_start:text_start + text_len].decode(
57 encoding='utf8', errors='replace') 65 encoding='utf8', errors='replace')
58 time_stamp = utils.read_u64(log_buf[pos:pos + 8]) 66 time_stamp = utils.read_u64(log_buf, pos + time_stamp_offset)
59 67
60 for line in text.splitlines(): 68 for line in text.splitlines():
61 msg = u"[{time:12.6f}] {line}\n".format( 69 msg = u"[{time:12.6f}] {line}\n".format(
diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py
index bc67126118c4..ea94221dbd39 100644
--- a/scripts/gdb/linux/utils.py
+++ b/scripts/gdb/linux/utils.py
@@ -92,15 +92,16 @@ def read_memoryview(inf, start, length):
92 return memoryview(inf.read_memory(start, length)) 92 return memoryview(inf.read_memory(start, length))
93 93
94 94
95def read_u16(buffer): 95def read_u16(buffer, offset):
96 buffer_val = buffer[offset:offset + 2]
96 value = [0, 0] 97 value = [0, 0]
97 98
98 if type(buffer[0]) is str: 99 if type(buffer_val[0]) is str:
99 value[0] = ord(buffer[0]) 100 value[0] = ord(buffer_val[0])
100 value[1] = ord(buffer[1]) 101 value[1] = ord(buffer_val[1])
101 else: 102 else:
102 value[0] = buffer[0] 103 value[0] = buffer_val[0]
103 value[1] = buffer[1] 104 value[1] = buffer_val[1]
104 105
105 if get_target_endianness() == LITTLE_ENDIAN: 106 if get_target_endianness() == LITTLE_ENDIAN:
106 return value[0] + (value[1] << 8) 107 return value[0] + (value[1] << 8)
@@ -108,18 +109,18 @@ def read_u16(buffer):
108 return value[1] + (value[0] << 8) 109 return value[1] + (value[0] << 8)
109 110
110 111
111def read_u32(buffer): 112def read_u32(buffer, offset):
112 if get_target_endianness() == LITTLE_ENDIAN: 113 if get_target_endianness() == LITTLE_ENDIAN:
113 return read_u16(buffer[0:2]) + (read_u16(buffer[2:4]) << 16) 114 return read_u16(buffer, offset) + (read_u16(buffer, offset + 2) << 16)
114 else: 115 else:
115 return read_u16(buffer[2:4]) + (read_u16(buffer[0:2]) << 16) 116 return read_u16(buffer, offset + 2) + (read_u16(buffer, offset) << 16)
116 117
117 118
118def read_u64(buffer): 119def read_u64(buffer, offset):
119 if get_target_endianness() == LITTLE_ENDIAN: 120 if get_target_endianness() == LITTLE_ENDIAN:
120 return read_u32(buffer[0:4]) + (read_u32(buffer[4:8]) << 32) 121 return read_u32(buffer, offset) + (read_u32(buffer, offset + 4) << 32)
121 else: 122 else:
122 return read_u32(buffer[4:8]) + (read_u32(buffer[0:4]) << 32) 123 return read_u32(buffer, offset + 4) + (read_u32(buffer, offset) << 32)
123 124
124 125
125target_arch = None 126target_arch = None