From nobody Thu Aug 11 14:32:47 2022 X-Original-To: dev-commits-src-all@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 4M3Tmc3zt5z4Y1dC; Thu, 11 Aug 2022 14:32:48 +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 4M3Tmc1Rvtz3Mcm; Thu, 11 Aug 2022 14:32:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660228368; 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=KQxjECEYQZcN/bZjb2Wr6rUDrMSfS/6n29QBTdum6xk=; b=oFgQwgA2+AUZL5NYkevGjx64seHDeLvbeGeq1iUI/0L9AlhPg4d9l5pyX9161mhMwHewAe 9ZHdWZoh1k4iL7JPKTD8eRURW5TQa0TsIwq4RrRXIbwzAe9WKeoOQD3vxIjdBScJkaReif D1PdUAaHGRaarpy3prGZgHzX4iEiQiEhJRzpaBLE3KoCLAIYua5EbI1PiS9xkr4hbS3axB RnMtf1u78/lJiSxNk6QVpTeiufovEGTDBYIZV9+aPJ6HewCsG8YJ4SQWqPUhHain5doGD+ 8Jex97afoIfPWNVALZ5YJsKWWgJhOQ2FfJJDvuguHOqyXKIiiZlxDqmYssHu+Q== 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 4M3Tmc07qPzvGL; Thu, 11 Aug 2022 14:32:48 +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 27BEWlg6004520; Thu, 11 Aug 2022 14:32:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27BEWl10004519; Thu, 11 Aug 2022 14:32:47 GMT (envelope-from git) Date: Thu, 11 Aug 2022 14:32:47 GMT Message-Id: <202208111432.27BEWl10004519@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: e4f615b3e0f5 - stable/13 - db_command.c: style List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: e4f615b3e0f564df1dee5b8bc6cd40259bd4c156 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660228368; 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=KQxjECEYQZcN/bZjb2Wr6rUDrMSfS/6n29QBTdum6xk=; b=HHaDiXqHVBmmdMsVYdK7Q8UfEbjmlCqTcg+x+4n0/YUKZ433O2YXeBLqKhbH4eRMuPqW1r 152U+56ph85UjayUiRSY8gqWLAXalU1JzFYR5VYvVLGOn5+6jt3Dsfvnl1D2NIF+Y62hrx W/KcjhLW2hbKpLBb6JbtzDi8iYAjYenfN94kgADz/FH4yqNOXFIsh+gYCGMWHOgXV4Is2A x5wQIFCYWXBcJbq6GFUsiINdH8T5N9zumQ82843S18VsV7MfT9sWvg6YNibtNXTYbakxQ2 M3KrovSwXmTI77JeeIvZg/ZWxKHMejpgVwLaVV5ASCH55mFgNFQG+Y2QKRcofw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660228368; a=rsa-sha256; cv=none; b=LKKwKUTZpyeUR4/R2V4XuiYXDQ0l0tGRzWYLid7qC0oXU+Z5Jb8exGJIAqqXF993sKNLI8 DNrqVrLZfUrDq2gv2SsebruhqEtzE10k+eVOf+21NSHx1dmPi6wofn/5Lie4qBeVmUyjB3 3gEhjdknUlhlzMaSciIVLg7f5u5+D9oOK/0E+bWdd+Bfh+620FLG2uWJfdfNfLSCGfjQ9k KWz8Z9mq+k3QZk8cGftXugSL2bQbCqejEn1kA9m8uQ+kgAkZ+afLGHNM3g4lWP+goq+wO1 nfJ8SDLzmpN+JZDUrF53HnwwUia0hlMCuZLfMIwmfVYbaGi3OIYhTahrhTHvPw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=e4f615b3e0f564df1dee5b8bc6cd40259bd4c156 commit e4f615b3e0f564df1dee5b8bc6cd40259bd4c156 Author: Mitchell Horne AuthorDate: 2022-07-05 14:44:36 +0000 Commit: Mitchell Horne CommitDate: 2022-08-11 14:22:26 +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 (cherry picked from commit 4f2ad6243f15ef325aa8daa680949b0ee1076c6e) --- 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 710b50755272..4c42ee6a6e6b 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