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

anchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ad5133be49b6e747b17b6794d13446b5df113a47
Author: zhangyu117 <[email protected]>
AuthorDate: Wed Oct 21 20:27:53 2026 +0800

    arch/tricore: emit lower context frame in backtrace.
    
    On trap/interrupt entry the hardware saves an upper context with the
    old A11 (the interrupted function's own return address), and only the
    following SVLCX lower context carries the real fault/interrupt PC in
    LA11.  The CSA unwinder skipped lower contexts, so the newest frame --
    the one that actually trapped -- was missing from panic backtraces.
    
    Select the A11 offset by the PCXI_UL bit instead of skipping lower
    contexts: LA11 for lower context frames, UA11 for upper ones.
    
    Signed-off-by: zhangyu117 <[email protected]>
---
 arch/tricore/src/common/tricore_backtrace.c | 29 +++++++----------------------
 1 file changed, 7 insertions(+), 22 deletions(-)

diff --git a/arch/tricore/src/common/tricore_backtrace.c 
b/arch/tricore/src/common/tricore_backtrace.c
index 4128d1787e8..ed468b3e766 100644
--- a/arch/tricore/src/common/tricore_backtrace.c
+++ b/arch/tricore/src/common/tricore_backtrace.c
@@ -44,34 +44,20 @@
  ****************************************************************************/
 
 nosanitize_address
-static int backtrace(uintptr_t pcxi, void **buffer,
-                     int size, int *skip)
+static int backtrace(uintptr_t pcxi, void **buffer, int size, int *skip)
 {
+  uintptr_t return_addr;
   uintptr_t *csa;
   int i = 0;
 
-  for (; i < size && (pcxi & FCX_FREE) != 0; )
+  for (; pcxi != 0 && i < size; pcxi = csa[REG_UPCXI])
     {
       csa = tricore_csa2addr(pcxi);
-      if (csa == NULL)
+      return_addr = (pcxi & PCXI_UL) ? csa[REG_UA11] : csa[REG_LA11];
+      if (return_addr && (*skip)-- <= 0)
         {
-          break;
+          buffer[i++] = (void *)return_addr;
         }
-
-      if ((pcxi & PCXI_UL) != 0)
-        {
-          if (csa[REG_UA11] == 0)
-            {
-              break;
-            }
-
-          if ((*skip)-- <= 0)
-            {
-              buffer[i++] = (void *)csa[REG_UA11];
-            }
-        }
-
-      pcxi = csa[REG_UPCXI];
     }
 
   return i;
@@ -131,8 +117,7 @@ int up_backtrace(struct tcb_s *tcb,
     }
   else
     {
-      uintptr_t *regs = tcb->xcp.regs;
-      ret = backtrace(regs[REG_LPCXI], buffer, size, &skip);
+      ret = backtrace(tricore_addr2csa(tcb->xcp.regs), buffer, size, &skip);
     }
 
   return ret;

Reply via email to