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 2021/12/30 08:57:51 UTC

[incubator-nuttx] branch master updated: arch/backtrace: correct the skip counter

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.git


The following commit(s) were added to refs/heads/master by this push:
     new 736add0  arch/backtrace: correct the skip counter
736add0 is described below

commit 736add0fe8e8e9ce6f34a535ae435bfee18a3084
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu Dec 30 00:07:46 2021 +0800

    arch/backtrace: correct the skip counter
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 arch/arm/src/common/arm_backtrace_thumb.c | 24 +++++++++++-------------
 arch/risc-v/src/common/riscv_backtrace.c  | 11 +++++------
 arch/xtensa/src/common/xtensa_backtrace.c | 16 +++++++---------
 3 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/arch/arm/src/common/arm_backtrace_thumb.c b/arch/arm/src/common/arm_backtrace_thumb.c
index d742319..9c2ada3 100644
--- a/arch/arm/src/common/arm_backtrace_thumb.c
+++ b/arch/arm/src/common/arm_backtrace_thumb.c
@@ -328,12 +328,12 @@ static int backtrace_push(FAR void *limit, FAR void **sp, FAR void *pc,
 
   pc = (uintptr_t)pc & 0xfffffffe;
 
-  if (*skip-- <= 0)
+  if ((*skip)-- <= 0)
     {
-      *buffer++ = pc;
+      buffer[i++] = pc;
     }
 
-  for (; i < size; i++)
+  while (i < size)
     {
       if (*sp >= limit)
         {
@@ -346,9 +346,9 @@ static int backtrace_push(FAR void *limit, FAR void **sp, FAR void *pc,
           break;
         }
 
-      if (*skip-- <= 0)
+      if ((*skip)-- <= 0)
         {
-          *buffer++ = pc;
+          buffer[i++] = pc;
         }
     }
 
@@ -371,9 +371,9 @@ static int backtrace_branch(FAR void *limit, FAR void *sp,
 {
   uint16_t ins16;
   uint32_t addr;
-  int i = 0;
+  int i;
 
-  for (; i < size && sp < limit; sp += sizeof(uint32_t))
+  for (i = 0; i < size && sp < limit; sp += sizeof(uint32_t))
     {
       addr = *(FAR uint32_t *)sp;
       if (!in_code_region(addr))
@@ -385,10 +385,9 @@ static int backtrace_branch(FAR void *limit, FAR void *sp,
       ins16 = *(FAR uint16_t *)addr;
       if (INSTR_IS(ins16, T_BLX))
         {
-          i++;
-          if (*skip-- <= 0)
+          if ((*skip)-- <= 0)
             {
-              *buffer++ = addr;
+              buffer[i++] = addr;
             }
         }
 
@@ -405,10 +404,9 @@ static int backtrace_branch(FAR void *limit, FAR void *sp,
           ins16 = *(FAR uint16_t *)addr;
           if (INSTR_IS(ins16, T_BL))
             {
-              i++;
-              if (*skip-- <= 0)
+              if ((*skip)-- <= 0)
                 {
-                  *buffer++ = addr;
+                  buffer[i++] = addr;
                 }
             }
         }
diff --git a/arch/risc-v/src/common/riscv_backtrace.c b/arch/risc-v/src/common/riscv_backtrace.c
index 007815b..413340f 100644
--- a/arch/risc-v/src/common/riscv_backtrace.c
+++ b/arch/risc-v/src/common/riscv_backtrace.c
@@ -69,14 +69,13 @@ static int backtrace(uintptr_t *base, uintptr_t *limit,
 
   if (ra)
     {
-      i++;
-      if (*skip-- <= 0)
+      if ((*skip)-- <= 0)
         {
-          *buffer++ = ra;
+          buffer[i++] = ra;
         }
     }
 
-  for (; i < size; fp = (uintptr_t *)*(fp - 2), i++)
+  for (; i < size; fp = (uintptr_t *)*(fp - 2))
     {
       if (fp > limit || fp < base)
         {
@@ -89,9 +88,9 @@ static int backtrace(uintptr_t *base, uintptr_t *limit,
           break;
         }
 
-      if (*skip-- <= 0)
+      if ((*skip)-- <= 0)
         {
-          *buffer++ = ra;
+          buffer[i++] = ra;
         }
     }
 
diff --git a/arch/xtensa/src/common/xtensa_backtrace.c b/arch/xtensa/src/common/xtensa_backtrace.c
index 54b529f..cc2ef4f 100644
--- a/arch/xtensa/src/common/xtensa_backtrace.c
+++ b/arch/xtensa/src/common/xtensa_backtrace.c
@@ -136,10 +136,9 @@ static int backtrace_window(uintptr_t *base, uintptr_t *limit,
               continue;
             }
 
-          i++;
-          if (*skip-- <= 0)
+          if ((*skip)-- <= 0)
             {
-              *buffer++ = MAKE_PC_FROM_RA(ra);
+              buffer[i++] = MAKE_PC_FROM_RA(ra);
             }
         }
     }
@@ -164,14 +163,13 @@ static int backtrace_stack(uintptr_t *base, uintptr_t *limit,
 
   if (ra)
     {
-      i++;
-      if (*skip-- <= 0)
+      if ((*skip)-- <= 0)
         {
-          *buffer++ = MAKE_PC_FROM_RA((uintptr_t)ra);
+          buffer[i++] = MAKE_PC_FROM_RA((uintptr_t)ra);
         }
     }
 
-  for (; i < size; sp = (uintptr_t *)*(sp - 3), i++)
+  for (; i < size; sp = (uintptr_t *)*(sp - 3))
     {
       if (sp > limit || sp < base)
         {
@@ -184,9 +182,9 @@ static int backtrace_stack(uintptr_t *base, uintptr_t *limit,
           break;
         }
 
-      if (*skip-- <= 0)
+      if ((*skip)-- <= 0)
         {
-          *buffer++ = MAKE_PC_FROM_RA((uintptr_t)ra);
+          buffer[i++] = MAKE_PC_FROM_RA((uintptr_t)ra);
         }
     }