From: Jim Cromie <jim.cromie@gmail.com>
To: Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>, Jason Baron <jbaron@akamai.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Petr Pavlu <petr.pavlu@suse.com>,
Daniel Gomez <da.gomez@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
Aaron Tomlin <atomlin@atomlin.com>,
Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org, linux-modules@vger.kernel.org,
linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org,
Jim Cromie <jim.cromie@gmail.com>,
Louis Chauvet <louis.chauvet@bootlin.com>
Subject: [PATCH v4 17/25] dyndbg: macrofy a 2-index for-loop pattern
Date: Tue, 02 Jun 2026 22:48:14 +0000 [thread overview]
Message-ID: <20260602-dd-maint-2-v4-17-19a1445585a8@gmail.com> (raw)
In-Reply-To: <20260602-dd-maint-2-v4-0-19a1445585a8@gmail.com>
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 <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
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 b8a494835ef5..a593e040d1ae 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;
@@ -1162,8 +1176,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.54.0
next prev parent reply other threads:[~2026-06-02 22:49 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 22:47 [PATCH v4 00/25] dynamic-debug cleanups refactors maintenance + alignment fix Jim Cromie
2026-06-02 22:47 ` [PATCH v4 01/25] docs/dyndbg: update examples \012 to \n Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:47 ` [PATCH v4 02/25] docs/dyndbg: explain flags parse 1st Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 03/25] vmlinux.lds.h: refactor BOUNDED_SECTION_* macros into bounded_sections.lds.h Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 04/25] vmlinux.lds.h: drop unused HEADERED_SECTION* macros Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 05/25] vmlinux.lds.h: Fix ALIGN(8) omission causing NULL ptr on i386 Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 06/25] vmlinux.lds.h: remove redundant ALIGN(8) directives Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 07/25] dyndbg.lds.S: fix lost dyndbg sections in modules Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 08/25] dyndbg: factor ddebug_match_desc out from ddebug_change Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 09/25] dyndbg: add stub macro for DECLARE_DYNDBG_CLASSMAP Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 10/25] dyndbg: reword "class unknown," to "class:_UNKNOWN_" Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 11/25] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 12/25] dyndbg: drop NUM_TYPE_ARGS Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 13/25] dyndbg: reduce verbose/debug clutter Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 14/25] dyndbg: refactor param_set_dyndbg_classes and below Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 15/25] dyndbg: tighten fn-sig of ddebug_apply_class_bitmap Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 16/25] dyndbg: replace classmap list with an array-slice Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` Jim Cromie [this message]
2026-06-04 2:12 ` Claude review: dyndbg: macrofy a 2-index for-loop pattern Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 18/25] dyndbg: Upgrade class param storage to u64 for 64-bit classmaps Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 19/25] dyndbg,module: make proper substructs in _ddebug_info Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 20/25] dyndbg: move mod_name down from struct ddebug_table to _ddebug_info Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 21/25] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 22/25] selftests-dyndbg: add a dynamic_debug run_tests target Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 23/25] dyndbg: change __dynamic_func_call_cls* macros into expressions Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 24/25] lib/parser: add match_wildcard_hyphen() for agnostic matching Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 25/25] dynamic_debug: use KBUILD_MODFILE for unique builtin module names Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-04 2:12 ` Claude review: dynamic-debug cleanups refactors maintenance + alignment fix Claude Code Review Bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260602-dd-maint-2-v4-17-19a1445585a8@gmail.com \
--to=jim.cromie@gmail.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=atomlin@atomlin.com \
--cc=corbet@lwn.net \
--cc=da.gomez@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=jbaron@akamai.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=louis.chauvet@bootlin.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mcgrof@kernel.org \
--cc=mripard@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=samitolvanen@google.com \
--cc=shuah@kernel.org \
--cc=simona@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox