Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1082840ybp; Fri, 11 Oct 2019 08:42:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbd+wEz/VZIn2KiK8r2d5YukFMW2P+/FotnqElode8fkzSA19XlG6PLG+l2V7+LQxab+To X-Received: by 2002:a50:a781:: with SMTP id i1mr14212835edc.17.1570808550051; Fri, 11 Oct 2019 08:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570808550; cv=none; d=google.com; s=arc-20160816; b=lVDXljQ3dZnmdDxJF9oHWn4/AMcnhKIZP0jQGYL5aKlpG8gAejeXuGvr2QrLjbuAlk App545tzC95r2tEGMLiOb7cEp4nK/SzAsOLSp9/e/Vh70msaQw2KWM+lju0rnGvEIiss BzsmA5cP5ex2dcZp2W1iWsRPOI4wlBj9zNhw7W2/r91v54FhMHELawOab1Ptez1esvfD mqMlO+8aKG6Z2/DKb8F4rDXdKTaYhw6F2YBW7RSjya3Bl3ZOgFToDWOFjIar2ORnz2th rA3hhUzCfYbct1vLzLwBUUsKijTMf693ZjbzQfd2IM7you54VjgYRpURdpuhNaHrTiHf gc3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=WbIC0OnP86s7y6QD3f6FPdzYAm4N87dRD6z1B1L8v2U=; b=Vc6zYDWlV3xtmh+K+2KxKaYac5F0wOdsSOngoAc42s6Xz5o8+oEWxjs1oruppR/mmr D1gxFXMRcn620NXttW/SaD/mq0k3se35Hy3W/GgCte3woTJAkTef2jj9Qdn9uBh5vslL rz1FdIMLOk9XVNcgdlxI0qbo3Hu9TL+23zun55btWkhOdq3Epvs5bchrWCTMoGunMgLw IN/ULDzZT0ubuYPt6Q8av8JoNXphiWbIXK0iWM1OdYE+8uaAZyfuypy/sVLlTzz94pDo 4SjLYTE/tF76YtOIliM14zP9HDUDgSuByTft6CX5lDr44ZPaaeEd6/zLBtFHHrl1U9iJ axfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=siemens.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sb7si5634971ejb.321.2019.10.11.08.42.06; Fri, 11 Oct 2019 08:42:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727985AbfJKPly (ORCPT + 99 others); Fri, 11 Oct 2019 11:41:54 -0400 Received: from goliath.siemens.de ([192.35.17.28]:33725 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726642AbfJKPly (ORCPT ); Fri, 11 Oct 2019 11:41:54 -0400 Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id x9BFfkNj031898 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2019 17:41:47 +0200 Received: from [139.25.68.37] ([139.25.68.37]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id x9BFfkjS028759; Fri, 11 Oct 2019 17:41:46 +0200 Subject: Re: [PATCH v3] scripts/gdb: fix lx-dmesg when CONFIG_PRINTK_CALLER is set To: Joel Colledge , Andrew Morton Cc: Kieran Bingham , Leonard Crestez , linux-kernel@vger.kernel.org References: <20191011142500.2339-1-joel.colledge@linbit.com> From: Jan Kiszka Message-ID: <040babb5-e2fc-6a0f-50c0-2af5aafd0855@siemens.com> Date: Fri, 11 Oct 2019 17:41:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <20191011142500.2339-1-joel.colledge@linbit.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11.10.19 16:25, Joel Colledge wrote: > 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 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. > > Signed-off-by: Joel Colledge > --- > Changes in v3: > - fix some overlong lines and generally make the code more readable by > pushing the slicing down into the read_u* helper functions > > In general, I would consider slicing to be more "pythonic" than passing > around offsets. However, in this case we always want to slice with > (offset, length), rather than (start, end), so the normal slicing syntax > is not very helpful. Rather than writing [a:a+b] everywhere I just > decided to pass the whole buffer and an offset to the read_u* helpers. Agreed. > > scripts/gdb/linux/dmesg.py | 16 ++++++++++++---- > scripts/gdb/linux/utils.py | 25 +++++++++++++------------ > 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 > > from linux import utils > > +printk_log_type = utils.CachedType("struct printk_log") > + > > class LxDmesg(gdb.Command): > """Print Linux kernel log buffer.""" > @@ -42,9 +44,14 @@ class LxDmesg(gdb.Command): > b = utils.read_memoryview(inf, log_buf_addr, log_next_idx) > log_buf = a.tobytes() + b.tobytes() > > + length_offset = printk_log_type.get_type()['len'].bitpos // 8 > + text_len_offset = printk_log_type.get_type()['text_len'].bitpos // 8 > + time_stamp_offset = printk_log_type.get_type()['ts_nsec'].bitpos // 8 > + text_offset = printk_log_type.get_type().sizeof > + > pos = 0 > while pos < log_buf.__len__(): > - length = utils.read_u16(log_buf[pos + 8:pos + 10]) > + length = utils.read_u16(log_buf, pos + length_offset) > if length == 0: > if log_buf_2nd_half == -1: > gdb.write("Corrupted log buffer!\n") > @@ -52,10 +59,11 @@ class LxDmesg(gdb.Command): > pos = log_buf_2nd_half > continue > > - text_len = utils.read_u16(log_buf[pos + 10:pos + 12]) > - text = log_buf[pos + 16:pos + 16 + text_len].decode( > + text_len = utils.read_u16(log_buf, pos + text_len_offset) > + text_start = pos + text_offset > + text = log_buf[text_start:text_start + text_len].decode( > encoding='utf8', errors='replace') > - time_stamp = utils.read_u64(log_buf[pos:pos + 8]) > + time_stamp = utils.read_u64(log_buf, pos + time_stamp_offset) > > for line in text.splitlines(): > 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): > return memoryview(inf.read_memory(start, length)) > > > -def read_u16(buffer): > +def read_u16(buffer, offset): > + buffer_val = buffer[offset:offset + 2] > value = [0, 0] > > - if type(buffer[0]) is str: > - value[0] = ord(buffer[0]) > - value[1] = ord(buffer[1]) > + if type(buffer_val[0]) is str: > + value[0] = ord(buffer_val[0]) > + value[1] = ord(buffer_val[1]) > else: > - value[0] = buffer[0] > - value[1] = buffer[1] > + value[0] = buffer_val[0] > + value[1] = buffer_val[1] > > if get_target_endianness() == LITTLE_ENDIAN: > return value[0] + (value[1] << 8) > @@ -108,18 +109,18 @@ def read_u16(buffer): > return value[1] + (value[0] << 8) > > > -def read_u32(buffer): > +def read_u32(buffer, offset): > if get_target_endianness() == LITTLE_ENDIAN: > - return read_u16(buffer[0:2]) + (read_u16(buffer[2:4]) << 16) > + return read_u16(buffer, offset) + (read_u16(buffer, offset + 2) << 16) > else: > - return read_u16(buffer[2:4]) + (read_u16(buffer[0:2]) << 16) > + return read_u16(buffer, offset + 2) + (read_u16(buffer, offset) << 16) > > > -def read_u64(buffer): > +def read_u64(buffer, offset): > if get_target_endianness() == LITTLE_ENDIAN: > - return read_u32(buffer[0:4]) + (read_u32(buffer[4:8]) << 32) > + return read_u32(buffer, offset) + (read_u32(buffer, offset + 4) << 32) > else: > - return read_u32(buffer[4:8]) + (read_u32(buffer[0:4]) << 32) > + return read_u32(buffer, offset + 4) + (read_u32(buffer, offset) << 32) > > > target_arch = None > Reviewed-by: Jan Kiszka Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux