Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1651306

[PATCH] scripts/gdb: make lx-dmesg command work (reliably)

From André Draszik <git@andred.net>
Newsgroups linux.kernel
Subject [PATCH] scripts/gdb: make lx-dmesg command work (reliably)
Date 2017-05-26 13:10 +0200
Message-ID <tLli2-57l-19@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


lx-dmesg needs access to the log_buf symbol from printk.c.
Unfortunately, the symbol log_buf also exists in BPF's
verifier.c and hence gdb can pick one or the other. If it
happens to pick BPF's log_buf, lx-dmesg doesn't work:

  (gdb) lx-dmesg
  Python Exception <class 'gdb.MemoryError'> Cannot access memory at address 0x0:
  Error occurred in Python command: Cannot access memory at address 0x0
  (gdb) p log_buf
  $15 = 0x0

Luckily, GDB has a way to deal with this, see
  https://sourceware.org/gdb/onlinedocs/gdb/Symbols.html

  (gdb) info variables ^log_buf$
  All variables matching regular expression "^log_buf$":

  File <linux.git>/kernel/bpf/verifier.c:
  static char *log_buf;

  File <linux.git>/kernel/printk/printk.c:
  static char *log_buf;
  (gdb) p 'verifier.c'::log_buf
  $1 = 0x0
  (gdb) p 'printk.c'::log_buf
  $2 = 0x811a6aa0 <__log_buf> ""

By being explicit about the location of the symbol, we
can make lx-dmesg work again. While at it, do the same
for the other symbols we need from printk.c

Signed-off-by: André Draszik <git@andred.net>
---
 scripts/gdb/linux/dmesg.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/gdb/linux/dmesg.py b/scripts/gdb/linux/dmesg.py
index f9b92ece7834..11f2397d40ed 100644
--- a/scripts/gdb/linux/dmesg.py
+++ b/scripts/gdb/linux/dmesg.py
@@ -23,10 +23,10 @@ class LxDmesg(gdb.Command):
         super(LxDmesg, self).__init__("lx-dmesg", gdb.COMMAND_DATA)
 
     def invoke(self, arg, from_tty):
-        log_buf_addr = int(str(gdb.parse_and_eval("log_buf")).split()[0], 16)
-        log_first_idx = int(gdb.parse_and_eval("log_first_idx"))
-        log_next_idx = int(gdb.parse_and_eval("log_next_idx"))
-        log_buf_len = int(gdb.parse_and_eval("log_buf_len"))
+        log_buf_addr = int(str(gdb.parse_and_eval("'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"))
 
         inf = gdb.inferiors()[0]
         start = log_buf_addr + log_first_idx
-- 
2.11.0

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] scripts/gdb: make lx-dmesg command work (reliably) André Draszik <git@andred.net> - 2017-05-26 13:10 +0200
  Re: [PATCH] scripts/gdb: make lx-dmesg command work (reliably) Jan Kiszka <jan.kiszka@siemens.com> - 2017-05-26 13:20 +0200
    Re: [PATCH] scripts/gdb: make lx-dmesg command work (reliably) Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-05-27 16:10 +0200
      Re: [PATCH] scripts/gdb: make lx-dmesg command work (reliably) Jan Kiszka <jan.kiszka@siemens.com> - 2017-05-28 18:40 +0200
  [PATCH v2] scripts/gdb: make lx-dmesg command work (reliably) André Draszik <git@andred.net> - 2017-05-26 13:20 +0200
  [PATCH v3] scripts/gdb: make lx-dmesg command work (reliably) André Draszik <git@andred.net> - 2017-05-26 13:30 +0200
    Re: [PATCH v3] scripts/gdb: make lx-dmesg command work (reliably) Jan Kiszka <jan.kiszka@siemens.com> - 2017-05-26 13:40 +0200
      Re: [PATCH v3] scripts/gdb: make lx-dmesg command work (reliably) Kieran Bingham <kieran@ksquared.org.uk> - 2017-05-31 07:20 +0200

csiph-web