Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753561AbcC3MDp (ORCPT ); Wed, 30 Mar 2016 08:03:45 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:35835 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751541AbcC3MBJ (ORCPT ); Wed, 30 Mar 2016 08:01:09 -0400 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: [PATCHv4 02/12] scripts/gdb: Provide kernel list item generators Date: Wed, 30 Mar 2016 13:00:41 +0100 Message-Id: <1459339251-29611-3-git-send-email-kieran.bingham@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459339251-29611-1-git-send-email-kieran.bingham@linaro.org> References: <1459339251-29611-1-git-send-email-kieran.bingham@linaro.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1737 Lines: 53 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 Changes since v3: - GdbError strings formatted on single line - list_head type corrected to head.type - .format() style preferred over % --- scripts/gdb/linux/lists.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py index 3a3775bc162b..2f335fbd86fd 100644 --- a/scripts/gdb/linux/lists.py +++ b/scripts/gdb/linux/lists.py @@ -18,6 +18,27 @@ 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 {}" + .format(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 {} found. Expected struct list_head *." + .format(node.type)) + yield utils.container_of(node, gdbtype, member) + + def list_check(head): nb = 0 if (head.type == list_head.get_type().pointer()): -- 2.5.0