From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1426078AbdEZLNO (ORCPT ); Fri, 26 May 2017 07:13:14 -0400 Received: from thoth.sbs.de ([192.35.17.2]:39072 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S940625AbdEZLMp (ORCPT ); Fri, 26 May 2017 07:12:45 -0400 Subject: Re: [PATCH] scripts/gdb: make lx-dmesg command work (reliably) To: =?UTF-8?Q?Andr=c3=a9_Draszik?= , linux-kernel@vger.kernel.org Cc: Kieran Bingham References: <20170526110454.1119-1-git@andred.net> From: Jan Kiszka Message-ID: <1c56ad8f-2128-3fe2-7a22-fb2074084a5e@siemens.com> Date: Fri, 26 May 2017 13:12:29 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: <20170526110454.1119-1-git@andred.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017-05-26 13:04, André Draszik wrote: > 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 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 /kernel/bpf/verifier.c: > static char *log_buf; > > File /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 > --- > 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) Overlong line. Please stay pep8 compliant. > + 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 > Looks good otherwise, thanks for addressing this! Jan -- Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux