From patchwork Wed Mar 30 12:00:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 64697 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2551565lbc; Wed, 30 Mar 2016 05:03:55 -0700 (PDT) X-Received: by 10.98.72.141 with SMTP id q13mr12505671pfi.152.1459339435788; Wed, 30 Mar 2016 05:03:55 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l90si6084681pfb.194.2016.03.30.05.03.55; Wed, 30 Mar 2016 05:03:55 -0700 (PDT) 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; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753563AbcC3MDp (ORCPT + 29 others); 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 Received: by mail-wm0-f53.google.com with SMTP id 191so86547723wmq.0 for ; Wed, 30 Mar 2016 05:01:08 -0700 (PDT) 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=FVppovrcpDUQcT4T7HjyTt0Wu34pKP9Gegri3jaHDdI=; b=Z0cCcDlynCSeRFtvi5RNxSXTg11H1oxgkHkg7chIiGAlzN5zO5HqWw8wo7XpKx41WB hJzjU3XpPCfFo5SYr81Vh8bNxm0SdeWWExjp4t/wmv2ibLUyYLL8YC1QC1Ye7shG9l0f mfEF1/KQEYqZK3aXEsA7IYNslg7oEZUnxQFaU= 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=FVppovrcpDUQcT4T7HjyTt0Wu34pKP9Gegri3jaHDdI=; b=Gvv5s56aocU62Q30AcIJKux8i58AyGU5N2OM89+/1d4Gci8cN9ZcsO/dDBPW/GaidA hHi4DcBuB3mVPuAulkP0gZ1nsNRBm/Peor20cAEx+md/7bw60Z04pdOXASS9XWP94+HH ZDXMWKzA+WwchHTXz2ZXeluntudSKqEUfGXXiK/rNi8NB9m1YEOvSPtKoYSj3gxL8ktv 1MOlYLjh6db759QGf2iwML9vdA6d63eRIImxrHHfrk41ag90DoU5El34U6UeuQa/0iYD kw+nFddGQglv1T06pp/Km/GVip9wLgLELzqdGAG3qKF7a2WIaRbCauOol94/t9K2f/4e f6Yw== X-Gm-Message-State: AD7BkJIevitm9rXQmMPvqS6XPPx+rUihH99iAMfr0vS5lRi0IBDQg5ek19scTHM/KlPgkxTO X-Received: by 10.28.156.146 with SMTP id f140mr9226172wme.99.1459339267936; Wed, 30 Mar 2016 05:01:07 -0700 (PDT) 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 e190sm1175530wma.15.2016.03.30.05.01.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Mar 2016 05:01:07 -0700 (PDT) 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 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 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(+) -- 2.5.0 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()):