git: bb61cba751b3 - main - ddb: add the DB_CMD_MEMSAFE flag for commands

From: Allan Jude <allanjude_at_FreeBSD.org>
Date: Mon, 18 Jul 2022 22:06:51 UTC
The branch main has been updated by allanjude:

URL: https://cgit.FreeBSD.org/src/commit/?id=bb61cba751b3b1620d14af987a4025974b4b1b2e

commit bb61cba751b3b1620d14af987a4025974b4b1b2e
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2022-07-18 20:04:24 +0000
Commit:     Allan Jude <allanjude@FreeBSD.org>
CommitDate: 2022-07-18 22:06:04 +0000

    ddb: add the DB_CMD_MEMSAFE flag for commands
    
    This flag value can be used to indicate if a command has the property of
    being "memory safe". In this instance, memory safe means that the
    command does not allow/enable reads or writes of arbitrary memory,
    regardless of the arguments passed to it. For example, 'backtrace' is
    considered a memory-safe command since its output is deterministic,
    while 'show vnode' is not, since it requires a memory address as an
    argument and will print the contents beginning at that location.
    
    Apply the flag to the "show all" command macros. It is expected that
    commands added to this table will always exhibit this property.
    
    Reviewed by:    markj
    Sponsored by:   Juniper Networks, Inc.
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D35581
---
 sys/ddb/ddb.h | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/sys/ddb/ddb.h b/sys/ddb/ddb.h
index 4e63907a6ed0..dce4e80ac117 100644
--- a/sys/ddb/ddb.h
+++ b/sys/ddb/ddb.h
@@ -110,13 +110,15 @@ typedef void db_cmdfcn_t(db_expr_t addr, bool have_addr, db_expr_t count,
  * Command table entry.
  */
 struct db_command {
-	char *	name;		/* command name */
+	char *name;		/* command name */
 	db_cmdfcn_t *fcn;	/* function to call */
-	int	flag;		/* extra info: */
+	int flag;
 #define	CS_OWN		0x1	/* non-standard syntax */
 #define	CS_MORE		0x2	/* standard syntax, but may have other words
 				 * at end */
 #define	CS_SET_DOT	0x100	/* set dot after command */
+#define	DB_CMD_MEMSAFE	0x1000	/* Command does not allow reads or writes to
+				 * arbitrary memory. */
 	struct db_command_table *more; /* another level of command */
 	LIST_ENTRY(db_command) next; /* next entry in the command table */
 };
@@ -180,10 +182,12 @@ _func(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
 	_DB_SET(_show, alias_name, func_name, db_show_table, flags, NULL)
 #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, 0, NULL)
-#define	DB_SHOW_ALL_ALIAS(alias_name, func_name) \
-	_DB_SET(_show_all, alias_name, func_name, db_show_all_table, 0, NULL)
+#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)
+#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)
 
 extern db_expr_t db_maxoff;
 extern int db_indent;