Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1150613pxb; Sun, 21 Feb 2021 13:45:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsCarYMBAcSSDAxqewvyIStfUzaPr4vuYl8fzFAfaRpBWXlWjs0/naJsXukrplAJkg6n86 X-Received: by 2002:a17:906:2bd6:: with SMTP id n22mr158091ejg.91.1613943900832; Sun, 21 Feb 2021 13:45:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613943900; cv=none; d=google.com; s=arc-20160816; b=xr3ibg42vE0zW02V+NYCXHeLSJZq5CbKUQ6JsTe0xmAI1lhb7cqqj1vnhwucy2oMy3 +jEH4MqtAyVljppjNbzWPbubX7SBE+OZT78kSuQNXKrsAOFSG1N+V0p3XW9HOBhsINdK bMTkglT+a2QAzUxFBKRPx7zBOoYHIFGkKUPYcfmA7i18IG/4E1tTPbt5NLVySxZ7CbWx PWHLN+RcRDXMzD4AsJGYV93M5og7MiBkYEr29cMfXkkdy/VEeC7+ZTpPT32FNsssiHg8 d4gesaUiN5LD4ZmtoVeBDjRswXa+cfL7oOIQZ4o32jklImeUpuNc8m/AG2XtX8B4i5NK pNQQ== 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 :message-id:date:subject:cc:to:from; bh=8DflP8ZuacICtZSLO4JhtgZw6Rg+JwKd6xE+7ll6vF8=; b=c5h1dkjGoZoi9EcKEBM4maUxH0C+v9ZBDyKZi80in1Evs7DrbPKeR4TZsx5ZIWw/oR qioBMN5BkqhAmTD44EkLwrqK7Vocls3VNmecwTQ6856JwEdNYE8iQcAjnAOOCxkeV2jO rGGwGkFPbhZCSJlHisLrmozCNHa2qJLSU705Kt3auW55q5gsR2/o+z7V88eq95Ky7UZN W8ij14frnNnoAZ0seEJ3zS6PPDqFGx/lm/j8mJPoTO1YFxuuwftMZPTJvP52uKJgbTQG NHgGlO8zCyJ2dr3zNNfQlxPoDxLHwjC73Ug2PQ+fNG8dHYwUM2WJ1Fj4LT2YkU88fQs6 2UOg== 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 cd24si2884944ejb.280.2021.02.21.13.44.37; Sun, 21 Feb 2021 13:45:00 -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 S230402AbhBUVmV (ORCPT + 99 others); Sun, 21 Feb 2021 16:42:21 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:12197 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbhBUVmU (ORCPT ); Sun, 21 Feb 2021 16:42:20 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DkJcV6GNdzlNC8; Mon, 22 Feb 2021 05:39:38 +0800 (CST) Received: from SWX921481.china.huawei.com (10.126.202.172) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Mon, 22 Feb 2021 05:41:27 +0800 From: Barry Song To: , , , CC: , , Barry Song Subject: [PATCH] scripts/gdb: document lx_current is only supported by x86 Date: Mon, 22 Feb 2021 10:35:27 +1300 Message-ID: <20210221213527.22076-1-song.bao.hua@hisilicon.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.126.202.172] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org lx_current depends on the per_cpu current_task which exists on x86 only: 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