From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9224030FF08; Wed, 9 Sep 2026 00:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788915303; cv=none; b=CGHTK6WesJcB5ccEzTQyjco7mPMoarD+1jCKVMH1zTil/Q51Rf5XKprp+sz7U771iyi2SKrtl5Hsqa10p6GofumUH1/i5SRUv3K/QvtReApMk1t7ot1GSAZGON7BVOUumzufNUGt/9ekm/z2l4L7keyz3BqJmK6ZKpDLyyFPZ2c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788915303; c=relaxed/simple; bh=c/QTyVAsDCMJjhEmfLZJXGNebqTBLgzDCbg18a+iR5o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ftiLV9nqQiFfUOJV2beih4jqimJNWBXsgKKws2jfvxVC+B1CEk3ZLudxXAahoUv2y7fZfPFoprGG0mOH2xNi8vruluNuog8YnexfNKEXwtiCG1DgXGhjFn3hYZ/wtTlLShcPvE5SgBuflOkoj1ackp+c0RtCh6OznSFfSmvFbRo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eIcNxXFA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eIcNxXFA" Received: by smtp.kernel.org (Postfix) with ESMTPS id 68DA2C2BD01; Wed, 9 Sep 2026 00:55:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1788915303; bh=c/QTyVAsDCMJjhEmfLZJXGNebqTBLgzDCbg18a+iR5o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=eIcNxXFAiPjmHBdV3oHDKup7celHHFboGPejjVFzDnyjWEXrnFhoTC0vgqcm0fJ1y HTMpi5E1rZ/lROi+jm5U/S3Yv2pbTB+kfaed/gyYoQwLQI3umnz33j8SdI9e/fnrsf h7csTRaQKJvZYatmJ9FNKfst56upR0MD5XYaJUmuhcYxulU2mlecA5aFVQgkSh9SRu t+/ONFWxCBeCLfzHL+son2DcNcbchhct5r/tPaiV+67yKvXymhA4HfFx3PJ2EUkIBK TW2+IrW0OB702h9k8DL7gscH47pTSc6xGmrvTPlBGJI+ajhaphmr8NYGfZujEuJRka dt77W8/TOv2tA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55F6CC79FB6; Wed, 9 Sep 2026 00:55:03 +0000 (UTC) From: Jim Cromie via B4 Relay Date: Tue, 08 Sep 2026 18:55:15 -0600 Subject: [PATCH v9 19/39] dyndbg: macrofy a 2-index for-loop pattern Precedence: bulk X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260908-dd-cmap-part2-clean-v9-19-3a3f621f4a10@gmail.com> References: <20260908-dd-cmap-part2-clean-v9-0-3a3f621f4a10@gmail.com> In-Reply-To: <20260908-dd-cmap-part2-clean-v9-0-3a3f621f4a10@gmail.com> To: Jason Baron , Shuah Khan , Andrew Morton , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Arnd Bergmann , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Jonathan Corbet , Greg Kroah-Hartman , Nathan Chancellor , Nicolas Schier , Shuah Khan , Randy Dunlap , "Rafael J. Wysocki" , Pavel Machek , Len Brown Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arch@vger.kernel.org, linux-modules@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-pm@vger.kernel.org, Jim Cromie , Louis Chauvet X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788915300; l=2812; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=HUq81c/st/wsa9vvV6Id45s8G94T+cNy13m/KzXZW1Q=; b=PrAeM3OBPpo8NuxJf3liIR1Fu5nR/iRCTt3GZ3f7MlU7rfmQSC9DwVt2WQoUxGIxog3S+uKYW CN2TlfC7KB+Cz5Sfh6Y3thppKWCfyBhoWluzs/sfXH2pgjueU9P2U5Z X-Developer-Key: i=jim.cromie@gmail.com; a=ed25519; pk=C6E5ODlPQo7ZBynATXH9wg7K6HxP0pIXyf4s38Qw0XE= X-Endpoint-Received: by B4 Relay for jim.cromie@gmail.com/20260203 with auth_id=958 X-Original-From: Jim Cromie Reply-To: jim.cromie@gmail.com From: Jim Cromie dynamic-debug currently has 2 __sections (__dyndbg, __dyndb_classes), struct _ddebug_info keeps track of them both, with 2 members each: _vec and _vec#_len. We need to loop over these sections, with index and record pointer, making ref to both _vec and _vec_len. This is already fiddly and error-prone, and will get worse as we add a 3rd section. Lets instead embed/abstract the fiddly-ness in the `for_subvec()` macro, and avoid repeating it going forward. This is a for-loop macro expander, so it syntactically expects to precede either a single statement or a { block } of them, and the usual typeof or do-while-0 tricks are unavailable to fix the multiple-expansion warning. Signed-off-by: Jim Cromie Reviewed-by: Louis Chauvet --- v2: move RvB after SoB --- lib/dynamic_debug.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index b163e5c4ec3a..e5a3658dd9bd 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -149,6 +149,20 @@ static void v3pr_info_dq(const struct ddebug_query *query, const char *msg) query->first_lineno, query->last_lineno, query->class_string); } +/* + * simplify a repeated for-loop pattern walking N steps in a T _vec + * member inside a struct _box. It expects int i and T *_sp to be + * declared in the caller. + * @_i: caller provided counter. + * @_sp: cursor into _vec, to examine each item. + * @_box: ptr to a struct containing @_vec member + * @_vec: name of a member in @_box + */ +#define for_subvec(_i, _sp, _box, _vec) \ + for ((_i) = 0, (_sp) = (_box)->_vec; \ + (_i) < (_box)->num_##_vec; \ + (_i)++, (_sp)++) /* { block } */ + static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt, const char *class_string, int *class_id) @@ -156,7 +170,7 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons struct ddebug_class_map *map; int i, idx; - for (map = dt->classes, i = 0; i < dt->num_classes; i++, map++) { + for_subvec(i, map, dt, classes) { idx = match_string(map->class_names, map->length, class_string); if (idx >= 0) { *class_id = idx + map->base; @@ -1165,8 +1179,7 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug * the builtin/modular classmap vector/section. Save the start * and length of the subrange at its edges. */ - for (cm = di->classes, i = 0; i < di->num_classes; i++, cm++) { - + for_subvec(i, cm, di, classes) { if (!strcmp(cm->mod_name, dt->mod_name)) { if (!nc) { v2pr_info("start subrange, class[%d]: module:%s base:%d len:%d ty:%d\n", -- 2.55.0