From patchwork Thu Mar 3 11:40:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 63474 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2896804lbc; Thu, 3 Mar 2016 03:48:00 -0800 (PST) X-Received: by 10.66.191.202 with SMTP id ha10mr3037278pac.8.1457005680081; Thu, 03 Mar 2016 03:48:00 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 81si65221304pfq.221.2016.03.03.03.47.59; Thu, 03 Mar 2016 03:48:00 -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 S932399AbcCCLr6 (ORCPT + 30 others); Thu, 3 Mar 2016 06:47:58 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:35068 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755200AbcCCLlU (ORCPT ); Thu, 3 Mar 2016 06:41:20 -0500 Received: by mail-wm0-f54.google.com with SMTP id l68so127165943wml.0 for ; Thu, 03 Mar 2016 03:41:19 -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=GS/dBdPpR/x+sJ7rzS1jn8JSuYqEg5ZO3Zvw/9Vq8i8uaM8DWlMCmoccmjuV0Ts9sM BxGTXmmPl/1fj33426hN5TemCeWcsFhUqPsEpMaUZoXM+2oPQMG6FI1P79C2YT1kkqBV 2jq/c3hAMYPon8iV15I5X9oln0EMbGwIoBup4= 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=ScbVgi4FK9KlMTyMTwveY5AWmMky3G2Bp+t1N1RIvQnJaf+IrWvYv+VAfgyRLVdRSC cGVXRZaSrOZ0V58IVUOHFzfGkkiheM7mxU3LE6E8shr0r6M5Te3/3z7/Hw7GddbLIgzQ HT48ox12LLaaebMpxtZgoHdH/n8c3IqVf7XqLZ6CySuAQsWm3ljZg9/IVwedEbF/56hU EwnRQOgm5rFfBKiKc/nlXWhRz/EreH5o+WZYV0Pv9kQ/q3ArC+FhJxkw1cpTkCoGkmVj uH+CO9veck8Y41OP6eHvKMKwGqm0zJIeMvgKrpNKioJC3bGialT6hgSG8T1CYAPqRz0W OW5g== X-Gm-Message-State: AD7BkJJ+np8WVgjtbM4DNWjO+Y0bovDJBvXyKNMV5wgnm8n50n2xNXv+Nn0bDKenOUiND9fF X-Received: by 10.194.250.103 with SMTP id zb7mr2706099wjc.65.1457005278675; Thu, 03 Mar 2016 03:41:18 -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 e19sm8570696wmd.1.2016.03.03.03.41.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Mar 2016 03:41:18 -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: [PATCHv3 02/13] scripts/gdb: Provide kernel list item generators Date: Thu, 3 Mar 2016 11:40:56 +0000 Message-Id: <1457005267-843-3-git-send-email-kieran.bingham@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1457005267-843-1-git-send-email-kieran.bingham@linaro.org> References: <1457005267-843-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()):