From nobody Wed Jul 5 23:02:11 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QxFXz327Rz4l5WQ; Wed, 5 Jul 2023 23:02:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QxFXz2K0bz47DX; Wed, 5 Jul 2023 23:02:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688598131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GQKmJYBsnSs96CBpGGXVE3ki52SR0exe1u91YMciED4=; b=lZq31cnEkzAzAkaV2qatJpT5R+eBjTi3W5+56Org2ZUXkhkPjOTgnUV5cuu76co+AJOJ/c OFNsS2N1HMp3Ueq50HTgvEvRflfyUPzYoIyduH5ZCYOZqjFb5SnD6waQDdwOeByLeqxbFY ujAAEAYvEMEdV2bCXEDccQbHA74VIyu6Em6TmeX/2VXAd0MPWF0w1rUVk0w5uGZO+kGmrC YorhmNIOQElAdKdLB7tLUQlO7LsG0/xbspJ4HDXlFim+K18ZyAkUiCEhqf9OHSQ4IBEe2J PKV2MnBTcCo0uKy4iy0An2jZY8Ez46tPJ+lokmh/H1V3EDw68eVNtKZEY1ucxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688598131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GQKmJYBsnSs96CBpGGXVE3ki52SR0exe1u91YMciED4=; b=HPanrJjnM0ZmnqHMGTE3FaSMp2tT0MjXrj75IMADXamy54Cf33b4QT2nltwxiAtBUsy+E5 34lCptG27stFB2uUq47l1gxyqMhuNc3Rg2AGm8hJ+NetZiPJX/xYxWI7FHOBWh39AH8x9O 5QLEkWcAkbQzRHebxRYJ9/eYrWuK0CkgwK00roqHKc5QEfnmfjK5/D525S24fc93qW49/r dAbyXmLOBhkKy+xYsn95W4AgirsNl4c0JHBUHcUSsy9HRF+vavqz+eRsGrBB8rGf4Vikgu VJZEONLS/3grXtYkuJHy277POZzCm95LmaBXT56IoQJ30q+tKkNyrADgMwQLzA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1688598131; a=rsa-sha256; cv=none; b=uWZpkNb3+dep67xctRxK5s2Ud6eKDC0zJ+D86UFkN3B5mIrHvsMhSUKMiPp/K4ccv/N/Wl zdAcgivwq/Y+byANr0v7cfUDfjpDrM/MUXodirbtXE2kTu0One4O+Vh3ohIjHjep9OEqNS Lt4SBWK5QL2if/a9ighxElj5MUrnN7n+0FYnXGzugW1heiZshZyOYWNdupFHTlzZ6A/OiK 9mIMcUhGIg+rVmqjE0HnKxIvYQpxntRV5s9qgSS3p9XrcZCRrjQBoCUf5hbyEMt/VtqzGs hHk/VAmzXy+nj+W/UZQ15OI9lL3Gw1prjOwGpLjciEBaB9kvtzYQvSLVKUmMMA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QxFXz1Ms2zYKy; Wed, 5 Jul 2023 23:02:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 365N2Bck060317; Wed, 5 Jul 2023 23:02:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 365N2BKk060316; Wed, 5 Jul 2023 23:02:11 GMT (envelope-from git) Date: Wed, 5 Jul 2023 23:02:11 GMT Message-Id: <202307052302.365N2BKk060316@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 884eaacd24bd - main - ddb: Rework macros to make it easier to add new command tables. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 884eaacd24bdb85c1571d31145278847bad6e55b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=884eaacd24bdb85c1571d31145278847bad6e55b commit 884eaacd24bdb85c1571d31145278847bad6e55b Author: John Baldwin AuthorDate: 2023-07-05 23:00:47 +0000 Commit: John Baldwin CommitDate: 2023-07-05 23:02:01 +0000 ddb: Rework macros to make it easier to add new command tables. - Add new DB_DEFINE_TABLE and DB_DECLARE_TABLE macros to define new command tables. DB_DECLARE_TABLE is intended for use in headers similar to MALLOC_DECLARE and SYSCTL_DECL. DB_DEFINE_TABLE takes three arguments, the name of the parent table, the command name, and the name of the table itself, e.g. DB_DEFINE_TABLE(show, foo, show_foo) defines a new "show foo" table. - DB_TABLE_COMMAND, DB_TABLE_COMMAND_FLAGS, DB_TABLE_ALIAS, and DB_ALIAS_FLAGS allow new commands and aliases to be defined. These are similar to the existing DB_COMMAND, etc. except that they take an initial argument giving the name of the parent table, e.g.: DB_TABLE_COMMAND(show_foo, bar, db_show_foo_bar) defines a new "show foo bar" command. This provides a cleaner interface than the ad-hoc use of internal macros like _DB_SET that was required previously (e.g. in cxgbe(4)). This retires DB_FUNC macro as well as the internal _DB_FUNC macro. Reviewed by: melifaro, kib, markj Differential Revision: https://reviews.freebsd.org/D40819 --- share/man/man9/DB_COMMAND.9 | 39 ++++++++++++++++-- share/man/man9/Makefile | 8 +++- sys/ddb/ddb.h | 96 ++++++++++++++++++++++++++++----------------- sys/dev/cxgbe/t4_main.c | 7 ++-- sys/net/route/route_ddb.c | 4 +- 5 files changed, 108 insertions(+), 46 deletions(-) diff --git a/share/man/man9/DB_COMMAND.9 b/share/man/man9/DB_COMMAND.9 index 15c2adce3580..ebf15f8b73f3 100644 --- a/share/man/man9/DB_COMMAND.9 +++ b/share/man/man9/DB_COMMAND.9 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 24, 2022 +.Dd July 5, 2023 .Dt DB_COMMAND 9 .Os .Sh NAME @@ -34,11 +34,17 @@ .Nm DB_SHOW_COMMAND , .Nm DB_SHOW_COMMAND_FLAGS , .Nm DB_SHOW_ALL_COMMAND , +.Nm DB_TABLE_COMMAND , +.Nm DB_TABLE_COMMAND_FLAGS , .Nm DB_ALIAS , .Nm DB_ALIAS_FLAGS , .Nm DB_SHOW_ALIAS , .Nm DB_SHOW_ALIAS_FLAGS , -.Nm DB_SHOW_ALL_ALIAS +.Nm DB_SHOW_ALL_ALIAS , +.Nm DB_TABLE_ALIAS , +.Nm DB_TABLE_ALIAS_FLAGS +.Nm DB_DECLARE_TABLE , +.Nm DB_DEFINE_TABLE , .Nd Extends the ddb command set .Sh SYNOPSIS .In ddb/ddb.h @@ -47,11 +53,17 @@ .Fn DB_SHOW_COMMAND "command_name" "command_function" .Fn DB_SHOW_COMMAND_FLAGS "command_name" "command_function" "flags" .Fn DB_SHOW_ALL_COMMAND "command_name" "command_function" +.Fn DB_TABLE_COMMAND "table" "command_name" "command_function" +.Fn DB_TABLE_COMMAND_FLAGS "table" "command_name" "command_function" "flags" .Fn DB_ALIAS "alias_name" "command_function" .Fn DB_ALIAS_FLAGS "alias_name" "command_function" "flags" .Fn DB_SHOW_ALIAS "alias_name" "command_function" .Fn DB_SHOW_ALIAS_FLAGS "alias_name" "command_function" "flags" .Fn DB_SHOW_ALL_ALIAS "alias_name" "command_function" +.Fn DB_TABLE_ALIAS "table" "alias_name" "command_function" +.Fn DB_TABLE_ALIAS_FLAGS "table" "alias_name" "command_function" "flags" +.Fn DB_DEFINE_TABLE "parent" "name" "table" +.Fn DB_DECLARE_TABLE "table" .Sh DESCRIPTION The .Fn DB_COMMAND @@ -78,10 +90,18 @@ command and command, respectively. .Pp The +.Fn DB_TABLE_COMMAND +macro is also similar to +.Fn DB_COMMAND +but adds the new command as a sub-command of the ddb command +.Fa table . +.Pp +The .Fn DB_ALIAS , .Fn DB_SHOW_ALIAS , +.Fn DB_SHOW_ALL_ALIAS , and -.Fn DB_SHOW_ALL_ALIAS +.Fn DB_TABLE_ALIAS macros register the existing .Fa command_function under the alternative command name @@ -117,6 +137,19 @@ For example, the .Sy examine command will display words in decimal form if it is passed the modifier "d". .El +.Pp +The +.Fn DB_DEFINE_TABLE +macro adds a new command +.Fa name +as a sub-command of the existing command table +.Fa parent . +The new command defines a table named +.Fa table +which contains sub-commands. +New commands and aliases can be added to this table by passing +.Fa table +as the first argument to one of the DB_TABLE_ macros. .Sh EXAMPLES In your module, the command is declared as: .Bd -literal diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index 2a320cf0fcba..45f9ec9b0515 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -983,7 +983,13 @@ MLINKS+=DB_COMMAND.9 DB_ALIAS.9 \ DB_COMMAND.9 DB_SHOW_ALL_ALIAS.9 \ DB_COMMAND.9 DB_SHOW_ALL_COMMAND.9 \ DB_COMMAND.9 DB_SHOW_COMMAND.9 \ - DB_COMMAND.9 DB_SHOW_COMMAND_FLAGS.9 + DB_COMMAND.9 DB_SHOW_COMMAND_FLAGS.9 \ + DB_COMMAND.9 DB_DECLARE_TABLE.9 \ + DB_COMMAND.9 DB_DEFINE_TABLE.9 \ + DB_COMMAND.9 DB_TABLE_COMMAND.9 \ + DB_COMMAND.9 DB_TABLE_COMMAND_FLAGS.9 \ + DB_COMMAND.9 DB_TABLE_ALIAS.9 \ + DB_COMMAND.9 DB_TABLE_ALIAS_FLAGS.9 MLINKS+=DECLARE_MODULE.9 DECLARE_MODULE_TIED.9 MLINKS+=dev_clone.9 drain_dev_clone_events.9 MLINKS+=dev_refthread.9 devvn_refthread.9 \ diff --git a/sys/ddb/ddb.h b/sys/ddb/ddb.h index 2fa4bfeb495c..591371e8a5c7 100644 --- a/sys/ddb/ddb.h +++ b/sys/ddb/ddb.h @@ -85,21 +85,32 @@ int DB_CALL(db_expr_t, db_expr_t *, int, db_expr_t[]); */ extern vm_offset_t ksymtab, kstrtab, ksymtab_size, ksymtab_relbase; +/* Command tables contain a list of commands. */ +struct db_command; +LIST_HEAD(db_command_table, db_command); + +#define _DB_TABLE_NAME(table) db_##table##_table + +#define DB_DEFINE_TABLE(parent, name, table) \ + struct db_command_table _DB_TABLE_NAME(table) = \ + LIST_HEAD_INITIALIZER(_DB_TABLE_NAME(table)); \ + _DB_SET(parent, name, NULL, 0, &_DB_TABLE_NAME(table)) + +#define DB_DECLARE_TABLE(table) \ + extern struct db_command_table _DB_TABLE_NAME(table) + /* - * There are three "command tables": - * - One for simple commands; a list of these is displayed + * Builtin command tables: + * - cmd: Top-level command table; a list of these is displayed * by typing 'help' at the debugger prompt. - * - One for sub-commands of 'show'; to see this type 'show' - * without any arguments. - * - The last one for sub-commands of 'show all'; type 'show all' - * without any argument to get a list. + * - show: Sub-commands of 'show' + * - show_all: Sub-commands of 'show all' + * - show_active: Sub-commands of 'show active' */ -struct db_command; -LIST_HEAD(db_command_table, db_command); -extern struct db_command_table db_cmd_table; -extern struct db_command_table db_show_table; -extern struct db_command_table db_show_all_table; -extern struct db_command_table db_show_active_table; +DB_DECLARE_TABLE(cmd); +DB_DECLARE_TABLE(show); +DB_DECLARE_TABLE(show_all); +DB_DECLARE_TABLE(show_active); /* * Type signature for a function implementing a ddb command. @@ -133,26 +144,36 @@ struct db_command { * in modules in which case they will be available only when * the module is loaded. */ -#define _DB_SET(_suffix, _name, _func, list, _flag, _more) \ -static struct db_command __CONCAT(_name,_suffix) = { \ +#define _DB_SET(_table, _name, _func, _flag, _more) \ +static struct db_command db_##_table##_##_name##_cmd = { \ .name = __STRING(_name), \ .fcn = _func, \ .flag = _flag, \ .more = _more \ }; \ -static void __CONCAT(__CONCAT(_name,_suffix),_add)(void *arg __unused) \ - { db_command_register(&list, &__CONCAT(_name,_suffix)); } \ -SYSINIT(__CONCAT(_name,_suffix), SI_SUB_KLD, SI_ORDER_ANY, \ - __CONCAT(__CONCAT(_name,_suffix),_add), NULL); \ -static void __CONCAT(__CONCAT(_name,_suffix),_del)(void *arg __unused) \ - { db_command_unregister(&list, &__CONCAT(_name,_suffix)); } \ -SYSUNINIT(__CONCAT(_name,_suffix), SI_SUB_KLD, SI_ORDER_ANY, \ - __CONCAT(__CONCAT(_name,_suffix),_del), NULL); + \ +static void \ +db##_table##_##_name##_add(void *arg __unused) \ +{ \ + db_command_register(&_DB_TABLE_NAME(_table), \ + &db_##_table##_##_name##_cmd); \ +} \ +SYSINIT(db_##_table##_##_name, SI_SUB_KLD, SI_ORDER_ANY, \ + db##_table##_##_name##_add, NULL); \ + \ +static void \ +db##_table##_##_name##_del(void *arg __unused) \ +{ \ + db_command_unregister(&_DB_TABLE_NAME(_table), \ + &db_##_table##_##_name##_cmd); \ +} \ +SYSUNINIT(db_##_table##_##_name, SI_SUB_KLD, SI_ORDER_ANY, \ + db##_table##_##_name##_del, NULL) /* * Like _DB_SET but also create the function declaration which * must be followed immediately by the body; e.g. - * _DB_FUNC(_cmd, panic, db_panic, db_cmd_table, 0, NULL) + * DB_TABLE_COMMAND_FLAGS(_cmd, panic, db_panic, 0) * { * ...panic implementation... * } @@ -160,38 +181,41 @@ SYSUNINIT(__CONCAT(_name,_suffix), SI_SUB_KLD, SI_ORDER_ANY, \ * This macro is mostly used to define commands placed in one of * the ddb command tables; see DB_COMMAND, etc. below. */ -#define _DB_FUNC(_suffix, _name, _func, list, _flag, _more) \ +#define DB_TABLE_COMMAND_FLAGS(_table, _name, _func, _flag) \ static db_cmdfcn_t _func; \ -_DB_SET(_suffix, _name, _func, list, _flag, _more); \ +_DB_SET(_table, _name, _func, _flag, NULL); \ static void \ _func(db_expr_t addr, bool have_addr, db_expr_t count, char *modif) -/* common idom provided for backwards compatibility */ -#define DB_FUNC(_name, _func, list, _flag, _more) \ - _DB_FUNC(_cmd, _name, _func, list, _flag, _more) +#define DB_TABLE_COMMAND(_table, _name, _func) \ + DB_TABLE_COMMAND_FLAGS(_table, _name, _func, 0) + +/* Wrappers around _DB_SET used for aliases. */ +#define DB_TABLE_ALIAS_FLAGS(_table, _name, _func, _flag) \ + _DB_SET(_table, _name, _func, _flag, NULL) +#define DB_TABLE_ALIAS(_table, _name, _func) \ + DB_TABLE_ALIAS_FLAGS(_table, _name, _func, 0) #define DB_COMMAND_FLAGS(cmd_name, func_name, flags) \ - _DB_FUNC(_cmd, cmd_name, func_name, db_cmd_table, flags, NULL) + DB_TABLE_COMMAND_FLAGS(cmd, cmd_name, func_name, flags) #define DB_COMMAND(cmd_name, func_name) \ DB_COMMAND_FLAGS(cmd_name, func_name, 0) #define DB_ALIAS_FLAGS(alias_name, func_name, flags) \ - _DB_SET(_cmd, alias_name, func_name, db_cmd_table, flags, NULL) + DB_TABLE_ALIAS_FLAGS(cmd, alias_name, func_name, flags) #define DB_ALIAS(alias_name, func_name) \ DB_ALIAS_FLAGS(alias_name, func_name, 0) #define DB_SHOW_COMMAND_FLAGS(cmd_name, func_name, flags) \ - _DB_FUNC(_show, cmd_name, func_name, db_show_table, flags, NULL) + DB_TABLE_COMMAND_FLAGS(show, cmd_name, func_name, flags) #define DB_SHOW_COMMAND(cmd_name, func_name) \ DB_SHOW_COMMAND_FLAGS(cmd_name, func_name, 0) #define DB_SHOW_ALIAS_FLAGS(alias_name, func_name, flags) \ - _DB_SET(_show, alias_name, func_name, db_show_table, flags, NULL) + DB_TABLE_ALIAS_FLAGS(show, alias_name, func_name, flags) #define DB_SHOW_ALIAS(alias_name, func_name) \ DB_SHOW_ALIAS_FLAGS(alias_name, func_name, 0) #define DB_SHOW_ALL_COMMAND(cmd_name, func_name) \ - _DB_FUNC(_show_all, cmd_name, func_name, db_show_all_table, \ - DB_CMD_MEMSAFE, NULL) + DB_TABLE_COMMAND_FLAGS(show_all, cmd_name, func_name, DB_CMD_MEMSAFE) #define DB_SHOW_ALL_ALIAS(alias_name, func_name) \ - _DB_SET(_show_all, alias_name, func_name, db_show_all_table, \ - DB_CMD_MEMSAFE, NULL) + DB_TABLE_ALIAS_FLAGS(show_all, alias_name, func_name, DB_CMD_MEMSAFE) extern db_expr_t db_maxoff; extern int db_indent; diff --git a/sys/dev/cxgbe/t4_main.c b/sys/dev/cxgbe/t4_main.c index 2fa49ddee10b..7ddd3b416995 100644 --- a/sys/dev/cxgbe/t4_main.c +++ b/sys/dev/cxgbe/t4_main.c @@ -12921,10 +12921,9 @@ t4_dump_devlog(struct adapter *sc) } while (i != first && !db_pager_quit); } -static struct db_command_table db_t4_table = LIST_HEAD_INITIALIZER(db_t4_table); -_DB_SET(_show, t4, NULL, db_show_table, 0, &db_t4_table); +static DB_DEFINE_TABLE(show, t4, show_t4); -DB_FUNC(devlog, db_show_devlog, db_t4_table, CS_OWN, NULL) +DB_TABLE_COMMAND_FLAGS(show_t4, devlog, db_show_devlog, CS_OWN) { device_t dev; int t; @@ -12950,7 +12949,7 @@ DB_FUNC(devlog, db_show_devlog, db_t4_table, CS_OWN, NULL) t4_dump_devlog(device_get_softc(dev)); } -DB_FUNC(tcb, db_show_t4tcb, db_t4_table, CS_OWN, NULL) +DB_TABLE_COMMAND_FLAGS(show_t4, tcb, db_show_t4tcb, CS_OWN) { device_t dev; int radix, tid, t; diff --git a/sys/net/route/route_ddb.c b/sys/net/route/route_ddb.c index 92e7a6bef574..a8e70a1d65c3 100644 --- a/sys/net/route/route_ddb.c +++ b/sys/net/route/route_ddb.c @@ -166,7 +166,7 @@ rt_dumpentry_ddb(struct radix_node *rn, void *arg __unused) return (0); } -DB_SHOW_COMMAND(routetable, db_show_routetable_cmd) +DB_SHOW_COMMAND(routetable, db_show_routetable) { struct rib_head *rnh; int error, i, lim; @@ -204,7 +204,7 @@ DB_SHOW_COMMAND(routetable, db_show_routetable_cmd) } } -DB_SHOW_COMMAND_FLAGS(route, db_show_route_cmd, CS_OWN) +DB_SHOW_COMMAND_FLAGS(route, db_show_route, CS_OWN) { char abuf[INET6_ADDRSTRLEN], *buf, *end; struct rib_head *rh;