From patchwork Mon Feb 22 15:24:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 62594 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1303911lbl; Mon, 22 Feb 2016 07:26:41 -0800 (PST) X-Received: by 10.98.68.86 with SMTP id r83mr39037059pfa.12.1456154801310; Mon, 22 Feb 2016 07:26:41 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 17si40362153pfr.69.2016.02.22.07.26.40; Mon, 22 Feb 2016 07:26:41 -0800 (PST) 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; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754180AbcBVP0j (ORCPT + 30 others); Mon, 22 Feb 2016 10:26:39 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:33216 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752234AbcBVPYZ (ORCPT ); Mon, 22 Feb 2016 10:24:25 -0500 Received: by mail-wm0-f46.google.com with SMTP id g62so161764331wme.0 for ; Mon, 22 Feb 2016 07:24:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nuC1+aB2INOqpGDI/U4W43XPMc2W8O8LyyvY+P9Zbmg=; b=TefePU8sYIjyEILvBEdVyWyH1a/sG929Gkrr+XquCRCgH7E91wJvR1u+tM+4CYBOt7 Kvdww+gRCzyRUQ3eAzJNlPbktr4xsE8Cd94p4tx7HQ+9VivY3ovFUI/MA6VDhN5RjnjT Xdd1SOkohRtgMQl2Tn+VCGGK2rJ/uXyxrQDNA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nuC1+aB2INOqpGDI/U4W43XPMc2W8O8LyyvY+P9Zbmg=; b=GXZ3KlwhYyRMYFqUWQQBKzwZPPgyIB6Gw0BmcG+yqMekwfgz3e2KJJHv3cmW17ysTL ynDUb+9LeoKPO8k726AnwpAgqu0/5ifs3rnNh+638U5lgCBrO6tuNRFxoieYKY9JlseL ZUA3T5X8Ra5USNmL0XDHxG5V2nr7rXK80I4yfHRWegUfDhhnj68/SByKsdzz5YCClk0C duEU+dSmoMyLXY+O+e+fHijUeYKxJw9jwd5t72MnN4igV63sw4HshBZy5rJBOJpHTVr8 ouKvEopUUfVA3jPfTMOZX4SVYBi/CiO5/Hcog+TbMqtaA9D00LqpU27nPN933p0E9qch v7MA== X-Gm-Message-State: AG10YORgbV9F16mgKUQVOptL1brbpkM7u7LA+TSxg7ksjKnRkPrCrZKVYsLueoqHhqITexmU X-Received: by 10.28.147.206 with SMTP id v197mr12525761wmd.70.1456154664501; Mon, 22 Feb 2016 07:24:24 -0800 (PST) Received: from localhost.localdomain (cpc87017-aztw30-2-0-cust65.18-1.cable.virginm.net. [92.232.232.66]) by smtp.gmail.com with ESMTPSA id w66sm21557528wmd.2.2016.02.22.07.24.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 07:24:24 -0800 (PST) From: Kieran Bingham To: jan.kiszka@siemens.com, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, peter.griffin@linaro.org, maxime.coquelin@st.com, Kieran Bingham , Jeff Mahoney Subject: [PATCH 2/8] scripts/gdb: Provide a kernel list item generators Date: Mon, 22 Feb 2016 15:24:06 +0000 Message-Id: <1456154652-29023-3-git-send-email-kieran.bingham@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456154652-29023-1-git-send-email-kieran.bingham@linaro.org> References: <1456154652-29023-1-git-send-email-kieran.bingham@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Facilitate linked-list items by providing a generator to return the dereferenced, and type-cast objects from a kernel linked list CC: Jeff Mahoney Signed-off-by: Kieran Bingham --- Changes since v1: * items function removed, and replaced with Jeff Mahoney's cleaner implementations of list_for_each, and list_for_each_entry --- scripts/gdb/linux/lists.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) -- 2.5.0 diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py index 3a3775bc162b..9f4503738e26 100644 --- a/scripts/gdb/linux/lists.py +++ b/scripts/gdb/linux/lists.py @@ -18,6 +18,26 @@ from linux import utils list_head = utils.CachedType("struct list_head") +def list_for_each(head): + if head.type == list_head.get_type().pointer(): + head = head.dereference() + elif head.type != list_head.get_type(): + raise gdb.GdbError("Must be struct list_head not %s" % list_head.type) + + node = head['next'].dereference() + while node.address != head.address: + yield node.address + node = node['next'].dereference() + + +def list_for_each_entry(head, gdbtype, member): + for node in list_for_each(head): + if node.type != list_head.get_type().pointer(): + raise TypeError("Type %s found. " + "Expected struct list_head *." % node.type) + yield utils.container_of(node, gdbtype, member) + + def list_check(head): nb = 0 if (head.type == list_head.get_type().pointer()):