You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/05/12 06:55:40 UTC

[incubator-nuttx-apps] 02/03: system/trace: correct arg index if command is alreay set

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 089c05cbd80a6c0ebc16d2e2e10ef3bba504fbef
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon May 9 12:11:13 2022 +0800

    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>...
    Subcommand:
      start [-c][<duration>]          : Start task tracing
      stop                            : Stop task tracing
      dump [-a][-c][<filename>]           : Output the trace result
     [-a] <Android SysTrace>
      mode [{+|-}{o|w|s|a|i|d}...]        : Set task trace options
      switch [+|-] : Configure switch trace filter
      syscall [{+|-}<syscallname>...] : Configure syscall trace filter
      irq [{+|-}<irqnum>...]          : Configure IRQ trace filter
      print [+|-] : Configure dump tnsh>
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 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++;
         }
     }