From 089c05cbd80a6c0ebc16d2e2e10ef3bba504fbef Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Mon, 9 May 2022 12:11:13 +0800 Subject: [PATCH] system/trace: correct arg index if command is alreay set An error occurs when the same command is executed twice $ trace switch + $ trace switch + Usage: trace ... Subcommand: start [-c][] : Start task tracing stop : Stop task tracing dump [-a][-c][] : Output the trace result [-a] mode [{+|-}{o|w|s|a|i|d}...] : Set task trace options switch [+|-] : Configure switch trace filter syscall [{+|-}...] : Configure syscall trace filter irq [{+|-}...] : Configure IRQ trace filter print [+|-] : Configure dump tnsh> Signed-off-by: chao.an --- system/trace/trace.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/system/trace/trace.c b/system/trace/trace.c index d7e38f673..c5c7f0fc0 100644 --- a/system/trace/trace.c +++ b/system/trace/trace.c @@ -501,13 +501,13 @@ static int trace_cmd_switch(int index, int argc, FAR char **argv, { if (argv[index][0] == '-' || argv[index][0] == '+') { - enable = (argv[index][0] == '+'); + enable = (argv[index++][0] == '+'); if (enable == ((mode.flag & NOTE_FILTER_MODE_FLAG_SWITCH) != 0)) { /* Already set */ - return false; + return index; } if (enable) @@ -520,8 +520,6 @@ static int trace_cmd_switch(int index, int argc, FAR char **argv, } ioctl(notectlfd, NOTECTL_SETMODE, (unsigned long)&mode); - - index++; } } @@ -754,13 +752,13 @@ static int trace_cmd_print(int index, int argc, FAR char **argv, { if (argv[index][0] == '-' || argv[index][0] == '+') { - enable = (argv[index][0] == '+'); + enable = (argv[index++][0] == '+'); if (enable == ((mode.flag & NOTE_FILTER_MODE_FLAG_DUMP) != 0)) { /* Already set */ - return false; + return index; } if (enable) @@ -773,8 +771,6 @@ static int trace_cmd_print(int index, int argc, FAR char **argv, } ioctl(notectlfd, NOTECTL_SETMODE, (unsigned long)&mode); - - index++; } }