From patchwork Wed May 6 05:52:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1284071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49H5Mk2cdBz9sSt for ; Wed, 6 May 2020 15:52:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=Sr6tY9fF; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49H5Mk1mlxzDqlF for ; Wed, 6 May 2020 15:52:18 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49H5Mg0g6GzDqBy for ; Wed, 6 May 2020 15:52:15 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=Sr6tY9fF; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 49H5Mf5czMz9sRY; Wed, 6 May 2020 15:52:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1588744334; bh=zk4JFkgPao0k1hlloe1AiG741KtF2ICL5teEV0aaO/Y=; h=From:To:Cc:Subject:Date:From; b=Sr6tY9fFmQKXno+fR4CT7IXVMndaz+i/DnzRt4B2t2LVFwMGK1AelwhUAV9q1GqEO faPs6worYnfmt+cSCH7U0LaIZnI3MwVcthScfSb1xVlwNA1GYxiibisSkjiEnLPbII VOnxfSuC+16+HaC2/MWTgHKJqvT9fY71IPocszKO5gjwdg6E83128q7aZHzVJpPTYN hqnJLhpzCE4srzKlsr5vhqCpAqBudNyM8PdK/Nr+WB8iPSVu8Oami76b1c6ACR4x98 x06XGncW2m0BisDq1NNmGieffDIjDxbE7LJzN4z/lD8lWR9TPuypJJrTUuXdZkL4jZ fXBz25qbgOclA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 6 May 2020 15:52:08 +1000 Message-Id: <20200506055209.154149-1-amitay@ozlabs.org> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Subject: [Pdbg] [PATCH 1/2] libpdbg: Add api for iterating over all targets X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs --- libpdbg/libpdbg.c | 26 ++++++++++++++++++++++++++ libpdbg/libpdbg.h | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 8af6a02..a6797ed 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -170,6 +170,32 @@ struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct return NULL; } +static int _pdbg_traverse(struct pdbg_target *parent, pdbg_traverse_callback_fn func, void *priv) +{ + struct pdbg_target *target; + int ret; + + ret = func(parent, priv); + if (ret) + return ret; + + pdbg_for_each_child_target(parent, target) { + ret = _pdbg_traverse(target, func, priv); + if (ret) + return ret; + } + + return 0; +} + +int pdbg_traverse(struct pdbg_target *parent, pdbg_traverse_callback_fn func, void *priv) +{ + if (!parent) + parent = pdbg_target_root(); + + return _pdbg_traverse(parent, func, priv); +} + enum pdbg_target_status pdbg_target_status(struct pdbg_target *target) { return target->status; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 1c974f5..4337025 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -257,6 +257,28 @@ enum pdbg_backend { target; \ target = __pdbg_next_child_target(parent, target, true)) +/** + * @brief Callback function for pdbg traverse + * + * @param[in] target current target + * @param[in] priv private data assoicated with callback function + * @return 0 to continue traverse, non-zero to stop traverse + */ +typedef int (*pdbg_traverse_callback_fn)(struct pdbg_target *target, void *priv); + +/** + * @brief Loop over all children of the given target + * + * @param[in] parent the head pdbg_target + * @param[in] func callback function to call on each target + * @param[in] priv private data for callback function + * @return 0 on successful traverse of all children, non-zero otherwise + * + * If the callback function returns non-zero value, the traverse will stop and + * return the same return non-zero value. + */ +int pdbg_traverse(struct pdbg_target *parent, pdbg_traverse_callback_fn func, void *priv); + /** * @brief Find a target parent of the given class/type * @param[in] klass the desired parent class