Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp848415ybp; Fri, 11 Oct 2019 05:25:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEfKqPaoCn88JN/eZJxVauuMdCV3aiAHPM6u6o6da2+y4KL47NE7zljIQKcDDjG3PfX6Xv X-Received: by 2002:a50:9eac:: with SMTP id a41mr13223063edf.237.1570796746368; Fri, 11 Oct 2019 05:25:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570796746; cv=none; d=google.com; s=arc-20160816; b=mWwwusw9PBrqs/lSQmH697JNVKCtJfPTtnTz2I6ZbCNdMiQ28bKZblsx/ngVcQ/mgh PQLq1XhGXV51jz+IkgfOI0hRxjb1KQumz6bISRQzBbLh7OEQfogmSq70q9W3TZv+3T1D dxuOfQqnpG48kPFrn0TaWKx6vJ6HVsWObNmX8lwy4clY8+3aPFD7PCuAxcJY5LqXCQ5+ eNw/uIZGx/vcyL1rHw8+TCuwhMs58CFWUWaawGeZOxnzEwNickMG0/HGwSWQeqlplyJY oLRo8HjKl1NfzbdokVcOUvmklyKNIa3/fHdll5HDqLqgwWucqlf4erX+LXiYhu2TSv3M cAgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:in-reply-to:message-id:date :subject:cc:from:dkim-signature; bh=dAeqKC6K8N5cmj43hqb8ltvoAlQKh/8rOuZ6jadV1rQ=; b=I5zz2+g6QtMk3ARSw7qOYCD2s4gpLehe1js5/BmnzHq2SfUgT2AETnOASb6AiaZ16z oifmR1CFUPyUrGuonUO77ng9Pqr1lLvD6RkBMONaGSWcmG8JmszbDM6g3knKAVVb7jfh iqKC17kDILtr2DLkZnOzGwusdoGf1vpSWhpFJI0gEnszbX3t//KK18l9rfnmmFMOPjRl kcy6A0PGFc8MRXBGe3ZnM3OIYBebFlwzDLFC7Rd7f6Gg+G+H6k/beK516FpnHPyDrBa0 d+py+RrHxTSd87S74QVWPn/e8q9LuatE9mVQDJkP4ny4kA+Gnlsx8OCfbpoGHKYfi9y8 elBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linbit-com.20150623.gappssmtp.com header.s=20150623 header.b=PXwWQ12r; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ns21si4897890ejb.167.2019.10.11.05.25.23; Fri, 11 Oct 2019 05:25:46 -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; dkim=fail header.i=@linbit-com.20150623.gappssmtp.com header.s=20150623 header.b=PXwWQ12r; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727932AbfJKMZE (ORCPT + 99 others); Fri, 11 Oct 2019 08:25:04 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50912 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727672AbfJKMZE (ORCPT ); Fri, 11 Oct 2019 08:25:04 -0400 Received: by mail-wm1-f67.google.com with SMTP id 5so10236940wmg.0 for ; Fri, 11 Oct 2019 05:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linbit-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dAeqKC6K8N5cmj43hqb8ltvoAlQKh/8rOuZ6jadV1rQ=; b=PXwWQ12ryqAtScNi+fsKIt0TugXL72/xc9tn8VUNg3QrNC9hEXVSGDbf7FI8gJJTJu b4/iUyR0aKwuCEfRL35Cl7fNUXUzVUaBDHEkfJhozUd0gdyZf6v0ShUOrhcPeYfDTgLh rapPPtaRCJpk6jTJujuvzPDElc4bpE9ziUaqJKaprvFPAeomxQLo5Isw33CYPyF7DLpV XtU/wpT1n51kb8V8IfberAtswU3odsVNkvNEB5mi1JPCr0AOT89m6V9u/1ZvbKQQywtm BVrqUkD8VG2uGzHd8BPq8wcd3RbwdIqK8+gt1sgEPxFcf+3XwwARMMKks/RrfvphPy3v 7fUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dAeqKC6K8N5cmj43hqb8ltvoAlQKh/8rOuZ6jadV1rQ=; b=jrOUOPwV5E9CmfC7WaF+S1lLOo6J1mZByvDlgoV98cx5eLtt2gAIWBUwkZiNryQORF JMn8KjmG93q4wiu9FFFoFWb+yWagNqU9KYXOSwQKq+dhNGL7PXN2xoZRzhWS/WIHuUSb t5F/7yQGxnxbC3N0p+5r+yTTVQfonhjnz2cex3bM+sHjptqnp6gTyjm12a6PlBmhzjMB zqn413J6EZhfEvXkiPTyUCfqFbv3WKFFKPn5RqJYuanp8d+sk+aLHxuOJBU1VRPjYi7+ 4mc4hdHGtB6wnoYN9fSTi0QlQl1rw+VtViPl4dIZj49waEazvU+2z/vI2XQHuMC2QlW5 gavw== X-Gm-Message-State: APjAAAUpkwRt7D4Mw/JE1mAiCRo8GOignIakTrBVRrJHJsQnkzx9CQ3F Vmg0rcGvIwSsIlw0M6VFWxnHcQ== X-Received: by 2002:a1c:dcd6:: with SMTP id t205mr3094964wmg.10.1570796702317; Fri, 11 Oct 2019 05:25:02 -0700 (PDT) Received: from baileys.linbit (212-186-191-219.static.upcbusiness.at. [212.186.191.219]) by smtp.gmail.com with ESMTPSA id n15sm9416044wrw.47.2019.10.11.05.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 05:25:01 -0700 (PDT) From: Joel Colledge Cc: Leonard Crestez , Joel Colledge , Jan Kiszka , Kieran Bingham , linux-kernel@vger.kernel.org Subject: [PATCH v2] scripts/gdb: fix lx-dmesg when CONFIG_PRINTK_CALLER is set Date: Fri, 11 Oct 2019 14:24:08 +0200 Message-Id: <20191011122409.23868-1-joel.colledge@linbit.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Joel Colledge --- Changes in v2: - use type information from gdb instead of hardcoded offsets Thanks for the idea about using the struct layout info from gdb, Leonard. I can't see any reason we shouldn't use that here, since most of the other commands use it. LxDmesg has used hardcoded offsets since scripts/gdb was introduced, so I assume it just ended up like that during the initial development of the tool. Here is a version of the fix using offsets from gdb. scripts/gdb/linux/dmesg.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/gdb/linux/dmesg.py b/scripts/gdb/linux/dmesg.py index 6d2e09a2ad2f..8f5d899029b7 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:pos + length_offset + 2]) 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:pos + text_len_offset + 2]) + text = log_buf[pos + text_offset:pos + text_offset + 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:pos + time_stamp_offset + 8]) for line in text.splitlines(): msg = u"[{time:12.6f}] {line}\n".format( -- 2.17.1