Skip to contentSkip to conversation

scripts/gdb: lx-dmesg: cast log_buf to void* for addr fetch

PATCH New [email protected] 1 participant 1 message Jul 12, 2017 GDB kernel debugging helper scripts

lore
Share & tools
lore
#0 lore raw

PATCH 25/96 scripts/gdb: lx-dmesg: cast log_buf to void* for addr fetch

From: Leonard Crestez <[email protected]>
Subject: scripts/gdb: lx-dmesg: cast log_buf to void* for addr fetch

In some cases it is possible for the str() conversion here to throw encoding errors because log_buf might not point to valid ascii. For example:

(gdb) python print str(gdb.parse_and_eval("log_buf")) Traceback (most recent call last):
File "<string>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0303' in
position 24: ordinal not in range(128)

Avoid this by explicitly casting to (void *) inside the gdb expression.

---

 scripts/gdb/linux/dmesg.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/gdb/linux/dmesg.py renamed from scripts/gdb/linux/dmesg.py~scripts-gdb-lx-dmesg-cast-log_buf-to-void-for-addr-fetch +1 -1
diff -puN scripts/gdb/linux/dmesg.py~scripts-gdb-lx-dmesg-cast-log_buf-to-void-for-addr-fetch scripts/gdb/linux/dmesg.py
@@ -24,7 +24,7 @@ class LxDmesg(gdb.Command):
 
     def invoke(self, arg, from_tty):
         log_buf_addr = int(str(gdb.parse_and_eval(
-            "'printk.c'::log_buf")).split()[0], 16)
+            "(void *)'printk.c'::log_buf")).split()[0], 16)
         log_first_idx = int(gdb.parse_and_eval("'printk.c'::log_first_idx"))
         log_next_idx = int(gdb.parse_and_eval("'printk.c'::log_next_idx"))
         log_buf_len = int(gdb.parse_and_eval("'printk.c'::log_buf_len"))

_