Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp21221pxb; Tue, 23 Feb 2021 16:47:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZoSgQb4JUmD+9VpIKf2jBn2QbwGW/i3IhyzcL6yQ92NES2qYcmp3ZBB3oo8S3Sj/L3Tmw X-Received: by 2002:a05:6402:22a8:: with SMTP id cx8mr31725813edb.376.1614127636018; Tue, 23 Feb 2021 16:47:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614127636; cv=none; d=google.com; s=arc-20160816; b=TmkDIJwNlcfqlZliWSdbgw59yR2osj3rYSvyAugJZyRPdXUwyxjxLUu8oDcktGhAZq cwWinbyILp/Hn4Q8LOrjbnR9S/UW7PWgnoutrfoIC7/6WQkDtmMSyzP1M4Tsg4ESOyoS oLjNtROvNHuJmfslIN8YmJAxnZcS0UJgI9k4a5Detq2/ilctUX59v94GUE4PvFyLsQ9v ez8hcThFGAcN/c0CQpGUJb6RMtVrgzsISJzajIboKOWQPBYrn/eySnVn/5cUH07n+mTD Kb0n96Kyg9EJpBgI4dnXM3JYr9BGp4CzrZSrnhEfi0e4Q+zXmDYOGOcIE1pu9GzU9DLY 1VAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=b62k3dykz55hlQKSRgmN5/AHnQo0Av/qdV4QGt/97hU=; b=UonHjEmf8YUPzHgdkaIGbkz1kwhJCYLkGTKxFJm6FFxG6rX+JaQpi2i8ziwx7jHHEv a2wta6P8GoC6m8TIrf2nkGEIZXKzdCHEcl4QtaOtuGA/fx2NRhsdSKw5l5UDYeEGfzB7 2538eLBTTI7X4stnh6n01HblxZgY0kzUfbgVup6TjN6bKtAhcL+Wmq1fIH+iN38gb1VI 3GC9kZWhx1U3UmIJWjbMZL7k/yt8MPjouPaP8hbVFIsZ7T05mEQBhurORo4D1Q+cMPPi C7QDY9+4+czh+jQNMKOYTZyakEpso8qC8qwD7+95CTaZ21SADPOxvIOngtK62Ls+HhVA ls4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a18si86172edy.522.2021.02.23.16.45.29; Tue, 23 Feb 2021 16:47:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233337AbhBWWtg (ORCPT + 99 others); Tue, 23 Feb 2021 17:49:36 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:12643 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232450AbhBWWc7 (ORCPT ); Tue, 23 Feb 2021 17:32:59 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DlYf45rR7z16Bs5; Wed, 24 Feb 2021 06:30:20 +0800 (CST) Received: from SWX921481.china.huawei.com (10.126.200.133) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Wed, 24 Feb 2021 06:31:46 +0800 From: Barry Song To: , , , CC: , , , Barry Song Subject: [PATCH v2 1/2] scripts/gdb: document lx_current is only supported by x86 Date: Wed, 24 Feb 2021 11:25:39 +1300 Message-ID: <20210223222540.9120-2-song.bao.hua@hisilicon.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20210223222540.9120-1-song.bao.hua@hisilicon.com> References: <20210223222540.9120-1-song.bao.hua@hisilicon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.126.200.133] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org x86 is the only architecture which has per_cpu current_task: arch$ git grep current_task | grep -i per_cpu x86/include/asm/current.h:DECLARE_PER_CPU(struct task_struct *, current_task); x86/kernel/cpu/common.c:DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned = x86/kernel/cpu/common.c:EXPORT_PER_CPU_SYMBOL(current_task); x86/kernel/cpu/common.c:DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task; x86/kernel/cpu/common.c:EXPORT_PER_CPU_SYMBOL(current_task); x86/kernel/smpboot.c: per_cpu(current_task, cpu) = idle; On other architectures, lx_current() will lead to a python exception: (gdb) p $lx_current().pid Python Exception No symbol "current_task" in current context.: Error occurred in Python: No symbol "current_task" in current context. To avoid more people struggling and wasting time in other architectures, document it. Cc: Jan Kiszka Signed-off-by: Barry Song --- Documentation/dev-tools/gdb-kernel-debugging.rst | 2 +- scripts/gdb/linux/cpus.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Documentation/dev-tools/gdb-kernel-debugging.rst b/Documentation/dev-tools/gdb-kernel-debugging.rst index 4756f6b3a04e..1586901b683c 100644 --- a/Documentation/dev-tools/gdb-kernel-debugging.rst +++ b/Documentation/dev-tools/gdb-kernel-debugging.rst @@ -114,7 +114,7 @@ Examples of using the Linux-provided gdb helpers [ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved .... -- Examine fields of the current task struct:: +- Examine fields of the current task struct(supported by x86 only):: (gdb) p $lx_current().pid $1 = 4998 diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py index 008e62f3190d..f382762509d3 100644 --- a/scripts/gdb/linux/cpus.py +++ b/scripts/gdb/linux/cpus.py @@ -156,6 +156,13 @@ Note that VAR has to be quoted as string.""" PerCpu() +def get_current_task(cpu): + if utils.is_target_arch("x86"): + var_ptr = gdb.parse_and_eval("¤t_task") + return per_cpu(var_ptr, cpu).dereference() + else: + raise gdb.GdbError("Sorry, obtaining the current task is not yet " + "supported with this arch") class LxCurrentFunc(gdb.Function): """Return current task. @@ -167,8 +174,7 @@ number. If CPU is omitted, the CPU of the current context is used.""" super(LxCurrentFunc, self).__init__("lx_current") def invoke(self, cpu=-1): - var_ptr = gdb.parse_and_eval("¤t_task") - return per_cpu(var_ptr, cpu).dereference() + return get_current_task(cpu) LxCurrentFunc() -- 2.25.1