From ccb6ffb997835073a650faeac61b2fcdf2f74503 Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 17 Jun 2016 21:47:17 +0200 Subject: Enable monitor debugging commands only, if env var 'cmd' is set to 'debug'. --- avr/command.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'avr') diff --git a/avr/command.c b/avr/command.c index e696202..5499b9d 100644 --- a/avr/command.c +++ b/avr/command.c @@ -1,10 +1,10 @@ /* - * (C) Copyright 2014 Leo C. + * (C) Copyright 2014, 2016 Leo C. * * (C) Copyright 2000-2009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */ /* @@ -19,9 +19,7 @@ #include "config.h" #include "print-utils.h" #include "con-utils.h" -#ifdef CONFIG_AUTO_COMPLETE #include "env.h" -#endif #include "debug.h" #include "command.h" @@ -81,6 +79,9 @@ command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, (void) flag; + char *optenv = getenv_str(PSTR("cmd")); + bool opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL; + if (argc == 1) { /*show list of commands */ cmd_tbl_t *cmd_array[cmd_items]; int i; @@ -99,19 +100,21 @@ command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, /* print short help (usage) */ for (i = 0; i < cmd_items; i++) { - const FLASH char *usage = cmd_array[i]->usage; - - /* allow user abort */ - if (ctrlc ()) - return CMD_RET_FAILURE; - if (usage == NULL) - continue; + if (opt_debug || cmd_array[i]->name[0] != '!') { + const FLASH char *usage = cmd_array[i]->usage; + + /* allow user abort */ + if (ctrlc ()) + return CMD_RET_FAILURE; + if (usage == NULL) + continue; #ifdef GCC_BUG_61443 - print_usage_line(cmd_array[i]->name, max_len, usage); + print_usage_line(cmd_array[i]->name, max_len, usage); #else - printf_P(PSTR("%-" stringify(8) /*FIXME*/ "S - %S\n"), - cmd_array[i]->name, usage); + printf_P(PSTR("%-" stringify(8) /*FIXME*/ "S - %S\n"), + cmd_array[i]->name, usage); #endif + } } return CMD_RET_SUCCESS; } @@ -119,7 +122,8 @@ command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, * command help (long version) */ for (i = 1; i < argc; ++i) { - if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL) { + if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL && + (opt_debug || cmdtp->name[0] != '!')) { cmd_usage(cmdtp); } else { printf_P(PSTR("Unknown command '%s' - try 'help'" @@ -141,6 +145,9 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len) size_t len; uint_fast8_t n_found = 0; + char *optenv = getenv_str(PSTR("cmd")); + bool opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL; + if (!cmd) return NULL; @@ -149,7 +156,8 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len) for (cmdtp = table; cmdtp != table + table_len; cmdtp++) { - if (strncmp_P(cmd, cmdtp->name, len) == 0) { + if (strncmp_P(cmd, cmdtp->name, len) == 0 && + (opt_debug || cmdtp->name[0] != '!')) { if (len == strlen_P(cmdtp->name)) return cmdtp; /* full match */ @@ -157,9 +165,8 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len) n_found++; } } - if (n_found == 1) { /* exactly one match */ + if (n_found == 1) /* exactly one match */ return cmdtp_temp; - } return NULL; /* not found or ambiguous command */ } -- cgit v1.2.3