From nobody Tue Jul 05 15:08:56 2022 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 90AAA1D0246F; Tue, 5 Jul 2022 15:08:57 +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 4LcmKN6wSgz3tsy; Tue, 5 Jul 2022 15:08:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657033737; 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=uaTceTUPFlY8+/7cXfJBtUlqQMlnehpMORUqTzy+BaM=; b=Nfic1xiplwAA93u9EwpbODwS/4OwV8lmm6oLyqNL5o2FNjT7yNMhzoNjSgR3Q0OesgoMEp e93tq8vwS4NUUAYN9nRxwtsN51PfhSePPE7wo/KxWztHpMSggj+4A/rFCkv97+c4ZvE9Ds 8zwjr6Y14NLFq1HJViixFCaP6trqgZ2MR9pxBzQHE+rdyaLb0ZpEhgreh9OpnkMbTjSn2v +F8EdyqVubhdvIpgyGagouCq5qbFSEG8+GrpExcwRVBGpALgF2i69ZmN7ZypNhs4XUJZot mDF+B/lSIymfNXFMVB9UuIgL7yx3+hdH8IpV6cXr0dP1NTGOeyr2WEBbjPYM8w== 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 A7BFE27C81; Tue, 5 Jul 2022 15:08:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 265F8usw069929; Tue, 5 Jul 2022 15:08:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 265F8uqg069928; Tue, 5 Jul 2022 15:08:56 GMT (envelope-from git) Date: Tue, 5 Jul 2022 15:08:56 GMT Message-Id: <202207051508.265F8uqg069928@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 4f2ad6243f15 - main - db_command.c: style 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4f2ad6243f15ef325aa8daa680949b0ee1076c6e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657033737; 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=uaTceTUPFlY8+/7cXfJBtUlqQMlnehpMORUqTzy+BaM=; b=WGCBC8aMjX6i//HfxzxOAkD0KTB/Oswh+uuhpmpiRpRWHdCcoymm2C2phPF2ixHnn1M9Ja IClwO++GQ0EiuOuqS9Wv1HvjmKUwa/+f6z0eJYigUcyDPO/JBnb+fQLAQzMrhj1aVdHZur F+PIsgzLS4BbkcVHsUEGowTtjz7Y1ncZHfeYUCMc7z4531pPN4vPrAapdHH2o1xKX94Bfn dQImd5NykjWvftQ1E/hXrDPqLAsCJMHxLedMo9wOrJlj2hI353b6UmPOszrfMn4ODq7cVr YPmslMWB7PeKkii4ipayS/Y/8cw0FeWLX0DWuW78T/Wz/wv3PAeGfE2f4KryYQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657033737; a=rsa-sha256; cv=none; b=FGpVYWhnntjpCbI7MMdEKYyoHLIJSKwpu8uUYkDPTdgrvz2OwzNuQEhDQWjo6Db8nxs2Hl u29qZW3yEedNGX9uB61zWfqvwnZ6QLolO0YqMJXLojLtjYv2DGkOeoiXea1elcTfGnjY9y KCtCha0lTNrNZx92PGY40AW7Tg+UOXx9BcO74W354kCUb34YpbnOSw1xZhSrWwUbzHTRUm zC0Hg5uMgtso0/wQ9uvTXOJWhgLt/pV2PzU2xtr1RW+jLD9qb4/F3KEuIBeQRQ2zEVUCuQ 58OJ4IJyi385RKvR/HTR4ymvoeFklC4k7V8RXrJ7/FqsX4E+6p33wpvKhiVcYg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=4f2ad6243f15ef325aa8daa680949b0ee1076c6e commit 4f2ad6243f15ef325aa8daa680949b0ee1076c6e Author: Mitchell Horne AuthorDate: 2022-07-05 14:44:36 +0000 Commit: Mitchell Horne CommitDate: 2022-07-05 14:51:31 +0000 db_command.c: style Reviewed by: jhb MFC after: 3 days Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35368 --- sys/ddb/db_command.c | 294 ++++++++++++++++++++++++--------------------------- 1 file changed, 141 insertions(+), 153 deletions(-) diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c index b101b843c437..e0183e11ab93 100644 --- a/sys/ddb/db_command.c +++ b/sys/ddb/db_command.c @@ -37,19 +37,19 @@ __FBSDID("$FreeBSD$"); #include +#include +#include #include +#include +#include #include #include -#include #include #include #include #include #include -#include -#include #include -#include #include #include @@ -172,9 +172,10 @@ static bool db_ed_style = true; void db_skip_to_eol(void) { - int t; + int t; + do { - t = db_read_token(); + t = db_read_token(); } while (t != tEOL); } @@ -193,7 +194,7 @@ static void db_cmd_list(struct db_command_table *table); static int db_cmd_search(char *name, struct db_command_table *table, struct db_command **cmdp); static void db_command(struct db_command **last_cmdp, - struct db_command_table *cmd_table, int dopager); + struct db_command_table *cmd_table, bool dopager); /* * Initialize the command lists from the static tables. @@ -201,19 +202,17 @@ static void db_command(struct db_command **last_cmdp, void db_command_init(void) { -#define N(a) (sizeof(a) / sizeof(a[0])) int i; - for (i = 0; i < N(db_cmds); i++) + for (i = 0; i < nitems(db_cmds); i++) db_command_register(&db_cmd_table, &db_cmds[i]); - for (i = 0; i < N(db_show_cmds); i++) + for (i = 0; i < nitems(db_show_cmds); i++) db_command_register(&db_show_table, &db_show_cmds[i]); - for (i = 0; i < N(db_show_active_cmds); i++) + for (i = 0; i < nitems(db_show_active_cmds); i++) db_command_register(&db_show_active_table, &db_show_active_cmds[i]); - for (i = 0; i < N(db_show_all_cmds); i++) + for (i = 0; i < nitems(db_show_all_cmds); i++) db_command_register(&db_show_all_table, &db_show_all_cmds[i]); -#undef N } /* @@ -353,156 +352,145 @@ db_cmd_list(struct db_command_table *table) static void db_command(struct db_command **last_cmdp, struct db_command_table *cmd_table, - int dopager) + bool dopager) { + char modif[TOK_STRING_SIZE]; struct db_command *cmd = NULL; - int t; - char modif[TOK_STRING_SIZE]; - db_expr_t addr, count; - bool have_addr = false; - int result; + db_expr_t addr, count; + int t, result; + bool have_addr = false; t = db_read_token(); if (t == tEOL) { - /* empty line repeats last command, at 'next' */ - cmd = *last_cmdp; - addr = (db_expr_t)db_next; - have_addr = false; - count = 1; - modif[0] = '\0'; - } - else if (t == tEXCL) { - db_fncall((db_expr_t)0, (bool)false, (db_expr_t)0, (char *)0); - return; - } - else if (t != tIDENT) { - db_printf("Unrecognized input; use \"help\" " - "to list available commands\n"); - db_flush_lex(); - return; - } - else { - /* - * Search for command - */ - while (cmd_table) { - result = db_cmd_search(db_tok_string, - cmd_table, - &cmd); - switch (result) { - case CMD_NONE: - db_printf("No such command; use \"help\" " - "to list available commands\n"); - db_flush_lex(); - return; - case CMD_AMBIGUOUS: - db_printf("Ambiguous\n"); - db_flush_lex(); - return; - case CMD_HELP: - if (cmd_table == &db_cmd_table) { - db_printf("This is ddb(4), the kernel debugger; " - "see https://man.FreeBSD.org/ddb/4 for help.\n"); - db_printf("Use \"bt\" for backtrace, \"dump\" for " - "kernel core dump, \"reset\" to reboot.\n"); - db_printf("Available commands:\n"); - } - db_cmd_list(cmd_table); - db_flush_lex(); - return; - default: - break; - } - if ((cmd_table = cmd->more) != NULL) { - t = db_read_token(); - if (t != tIDENT) { - db_printf("Subcommand required; " - "available subcommands:\n"); - db_cmd_list(cmd_table); - db_flush_lex(); - return; - } - } - } - - if ((cmd->flag & CS_OWN) == 0) { + /* empty line repeats last command, at 'next' */ + cmd = *last_cmdp; + addr = (db_expr_t)db_next; + have_addr = false; + count = 1; + modif[0] = '\0'; + } else if (t == tEXCL) { + db_fncall((db_expr_t)0, false, (db_expr_t)0, NULL); + return; + } else if (t != tIDENT) { + db_printf("Unrecognized input; use \"help\" " + "to list available commands\n"); + db_flush_lex(); + return; + } else { /* - * Standard syntax: - * command [/modifier] [addr] [,count] + * Search for command */ - t = db_read_token(); - if (t == tSLASH) { - t = db_read_token(); - if (t != tIDENT) { - db_printf("Bad modifier\n"); - db_flush_lex(); - return; - } - db_strcpy(modif, db_tok_string); - } - else { - db_unread_token(t); - modif[0] = '\0'; + while (cmd_table != NULL) { + result = db_cmd_search(db_tok_string, cmd_table, &cmd); + switch (result) { + case CMD_NONE: + db_printf("No such command; use \"help\" " + "to list available commands\n"); + db_flush_lex(); + return; + case CMD_AMBIGUOUS: + db_printf("Ambiguous\n"); + db_flush_lex(); + return; + case CMD_HELP: + if (cmd_table == &db_cmd_table) { + db_printf("This is ddb(4), the kernel debugger; " + "see https://man.FreeBSD.org/ddb/4 for help.\n"); + db_printf("Use \"bt\" for backtrace, \"dump\" for " + "kernel core dump, \"reset\" to reboot.\n"); + db_printf("Available commands:\n"); + } + db_cmd_list(cmd_table); + db_flush_lex(); + return; + case CMD_UNIQUE: + case CMD_FOUND: + break; + } + if ((cmd_table = cmd->more) != NULL) { + t = db_read_token(); + if (t != tIDENT) { + db_printf("Subcommand required; " + "available subcommands:\n"); + db_cmd_list(cmd_table); + db_flush_lex(); + return; + } + } } - if (db_expression(&addr)) { - db_dot = (db_addr_t) addr; - db_last_addr = db_dot; - have_addr = true; - } - else { - addr = (db_expr_t) db_dot; - have_addr = false; - } - t = db_read_token(); - if (t == tCOMMA) { - if (!db_expression(&count)) { - db_printf("Count missing\n"); - db_flush_lex(); - return; - } - } - else { - db_unread_token(t); - count = -1; - } - if ((cmd->flag & CS_MORE) == 0) { - db_skip_to_eol(); + if ((cmd->flag & CS_OWN) == 0) { + /* + * Standard syntax: + * command [/modifier] [addr] [,count] + */ + t = db_read_token(); + if (t == tSLASH) { + t = db_read_token(); + if (t != tIDENT) { + db_printf("Bad modifier\n"); + db_flush_lex(); + return; + } + db_strcpy(modif, db_tok_string); + } else { + db_unread_token(t); + modif[0] = '\0'; + } + + if (db_expression(&addr)) { + db_dot = (db_addr_t) addr; + db_last_addr = db_dot; + have_addr = true; + } else { + addr = (db_expr_t) db_dot; + have_addr = false; + } + + t = db_read_token(); + if (t == tCOMMA) { + if (!db_expression(&count)) { + db_printf("Count missing\n"); + db_flush_lex(); + return; + } + } else { + db_unread_token(t); + count = -1; + } + + if ((cmd->flag & CS_MORE) == 0) { + db_skip_to_eol(); + } } - } } + *last_cmdp = cmd; if (cmd != NULL) { - /* - * Execute the command. - */ - if (dopager) - db_enable_pager(); - else - db_disable_pager(); - (*cmd->fcn)(addr, have_addr, count, modif); - if (dopager) - db_disable_pager(); - - if (cmd->flag & CS_SET_DOT) { /* - * If command changes dot, set dot to - * previous address displayed (if 'ed' style). + * Execute the command. */ - if (db_ed_style) { - db_dot = db_prev; - } - else { - db_dot = db_next; + if (dopager) + db_enable_pager(); + else + db_disable_pager(); + (*cmd->fcn)(addr, have_addr, count, modif); + if (dopager) + db_disable_pager(); + + if (cmd->flag & CS_SET_DOT) { + /* + * If command changes dot, set dot to previous address + * displayed (if 'ed' style). + */ + db_dot = db_ed_style ? db_prev : db_next; + } else { + /* + * If command does not change dot, set 'next' location + * to be the same. + */ + db_next = db_dot; } - } - else { - /* - * If command does not change dot, - * set 'next' location to be the same. - */ - db_next = db_dot; - } } } @@ -527,13 +515,13 @@ db_command_loop(void) db_cmd_loop_done = 0; while (!db_cmd_loop_done) { - if (db_print_position() != 0) - db_printf("\n"); + if (db_print_position() != 0) + db_printf("\n"); - db_printf("db> "); - (void) db_read_line(); + db_printf("db> "); + (void)db_read_line(); - db_command(&db_last_command, &db_cmd_table, /* dopager */ 1); + db_command(&db_last_command, &db_cmd_table, /* dopager */ true); } } @@ -551,7 +539,7 @@ db_command_script(const char *command) { db_prev = db_next = db_dot; db_inject_line(command); - db_command(&db_last_command, &db_cmd_table, /* dopager */ 0); + db_command(&db_last_command, &db_cmd_table, /* dopager */ false); } void