You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/08/20 12:37:55 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4381: arch/riscv/assert: enhance the assert dump

xiaoxiang781216 commented on a change in pull request #4381:
URL: https://github.com/apache/incubator-nuttx/pull/4381#discussion_r692677224



##########
File path: arch/risc-v/src/rv32im/riscv_assert.c
##########
@@ -185,9 +188,16 @@ static void riscv_dumpstate(void)
   uint32_t istacksize;
 #endif
 
+  /* Show back trace */
+
+#ifdef CONFIG_ARCH_HAVE_BACKTRACE

Review comment:
       change to CONFIG_SCHED_BACKTRACE

##########
File path: arch/risc-v/src/rv32im/riscv_assert.c
##########
@@ -85,88 +85,91 @@ static void riscv_stackdump(uint32_t sp, uint32_t stack_top)
 #endif
 
 /****************************************************************************
- * Name: riscv_taskdump
+ * Name: riscv_registerdump
  ****************************************************************************/
 
-#ifdef CONFIG_STACK_COLORATION
-static void riscv_taskdump(FAR struct tcb_s *tcb, FAR void *arg)
+#ifdef CONFIG_ARCH_STACKDUMP
+static inline void riscv_registerdump(FAR volatile uint32_t *regs)
 {
-  /* Dump interesting properties of this task */
+  /* Are user registers available from interrupt processing? */
 
-#if CONFIG_TASK_NAME_SIZE > 0
-  _alert("%s: PID=%d Stack Used=%lu of %lu\n",
-        tcb->name, tcb->pid, (unsigned long)up_check_tcbstack(tcb),
-        (unsigned long)tcb->adj_stack_size);
+  _alert("EPC:%08x \n", regs[REG_EPC]);
+  _alert("A0:%08x A1:%08x A2:%08x A3:%08x A4:%08x A5:%08x "
+         "A6:%08x A7:%08x\n",
+        regs[REG_A0], regs[REG_A1], regs[REG_A2], regs[REG_A3],
+        regs[REG_A4], regs[REG_A5], regs[REG_A6], regs[REG_A7]);
+  _alert("T0:%08x T1:%08x T2:%08x T3:%08x T4:%08x T5:%08x T6:%08x\n",
+        regs[REG_T0], regs[REG_T1], regs[REG_T2], regs[REG_T3],
+        regs[REG_T4], regs[REG_T5], regs[REG_T6]);
+  _alert("S0:%08x S1:%08x S2:%08x S3:%08x S4:%08x S5:%08x "
+         "S6:%08x S7:%08x\n",
+        regs[REG_S0], regs[REG_S1], regs[REG_S2], regs[REG_S3],
+        regs[REG_S4], regs[REG_S5], regs[REG_S6], regs[REG_S7]);
+  _alert("S8:%08x S9:%08x S10:%08x S11:%08x\n",
+        regs[REG_S8], regs[REG_S9], regs[REG_S10], regs[REG_S11]);
+#ifdef RISCV_SAVE_GP
+  _alert("GP:%08x SP:%08x FP:%08x TP:%08x RA:%08x\n",
+        regs[REG_GP], regs[REG_SP], regs[REG_FP], regs[REG_TP],
+        regs[REG_RA]);
 #else
-  _alert("PID: %d Stack Used=%lu of %lu\n",
-        tcb->pid, (unsigned long)up_check_tcbstack(tcb),
-        (unsigned long)tcb->adj_stack_size);
+  _alert("SP:%08x FP:%08x TP:%08x RA:%08x\n",
+        regs[REG_SP], regs[REG_FP], regs[REG_TP], regs[REG_RA]);
 #endif
 }
+#else
+#  define riscv_registerdump(reg)
 #endif
 
 /****************************************************************************
- * Name: riscv_showtasks
+ * Name: riscv_taskdump
  ****************************************************************************/
 
-#ifdef CONFIG_STACK_COLORATION
-static inline void riscv_showtasks(void)
+#if defined(CONFIG_STACK_COLORATION) || defined(CONFIG_ARCH_HAVE_BACKTRACE)
+static void riscv_taskdump(FAR struct tcb_s *tcb, FAR void *arg)
 {
-  /* Dump interesting properties of each task in the crash environment */
+  /* Dump interesting properties of this task */
 
-  nxsched_foreach(riscv_taskdump, NULL);
-}
+#if CONFIG_TASK_NAME_SIZE > 0
+  _alert("%s: PID=%d\n", tcb->name, tcb->pid);
 #else
-#  define riscv_showtasks()
+  _alert("PID: %d\n", tcb->pid);
+#endif
+
+  /* Show stack info */
+
+#ifdef CONFIG_STACK_COLORATION
+  _alert("Stack Used=%lu of %lu\n", (unsigned long)up_check_tcbstack(tcb),
+                                    (unsigned long)tcb->adj_stack_size);
 #endif
 
+  /* Show back trace */
+
+#ifdef CONFIG_ARCH_HAVE_BACKTRACE

Review comment:
       change to CONFIG_SCHED_BACKTRACE

##########
File path: arch/risc-v/src/rv64gc/riscv_assert.c
##########
@@ -86,104 +86,99 @@ static void up_stackdump(uint64_t sp, uintptr_t stack_top)
     }
 }
 
+/****************************************************************************
+ * Name: up_registerdump
+ ****************************************************************************/
+
+static inline void up_registerdump(FAR volatile uintptr_t *regs)
+{
+  /* Are user registers available from interrupt processing? */
+
+  _alert("EPC:%016" PRIx64 " \n", regs[REG_EPC]);
+  _alert("A0:%016" PRIx64 " A1:%01" PRIx64 "6 A2:%016" PRIx64
+         " A3:%016" PRIx64 " \n",
+         regs[REG_A0], regs[REG_A1], regs[REG_A2], regs[REG_A3]);
+  _alert("A4:%016" PRIx64 " A5:%016" PRIx64 "A6:%016" PRIx64
+         " A7:%016" PRIx64 " \n",
+         regs[REG_A4], regs[REG_A5], regs[REG_A6], regs[REG_A7]);
+  _alert("T0:%016" PRIx64 " T1:%016" PRIx64 " T2:%016" PRIx64
+         " T3:%016" PRIx64 " \n",
+         regs[REG_T0], regs[REG_T1], regs[REG_T2], regs[REG_T3]);
+  _alert("T4:%016" PRIx64 " T5:%016" PRIx64 " T6:%016" PRIx64 " \n",
+         regs[REG_T4], regs[REG_T5], regs[REG_T6]);
+  _alert("S0:%016" PRIx64 " S1:%016" PRIx64 " S2:%016" PRIx64
+         " S3:%016" PRIx64 " \n",
+         regs[REG_S0], regs[REG_S1], regs[REG_S2], regs[REG_S3]);
+  _alert("S4:%016" PRIx64 " S5:%016" PRIx64 " S6:%016" PRIx64
+         " S7:%016" PRIx64 " \n",
+         regs[REG_S4], regs[REG_S5], regs[REG_S6], regs[REG_S7]);
+  _alert("S8:%016" PRIx64 " S9:%016" PRIx64 " S10:%016" PRIx64
+         " S11:%016" PRIx64 " \n",
+         regs[REG_S8], regs[REG_S9], regs[REG_S10], regs[REG_S11]);
+#ifdef RISCV_SAVE_GP
+  _alert("GP:%016" PRIx64 " SP:%016" PRIx64 " FP:%016" PRIx64
+         " TP:%016" PRIx64 " RA:%016" PRIx64 " \n",
+         regs[REG_GP], regs[REG_SP], regs[REG_FP], regs[REG_TP],
+         regs[REG_RA]);
+#else
+  _alert("SP:%016" PRIx64 " FP:%016" PRIx64 " TP:%016" PRIx64
+         " RA:%016" PRIx64 " \n",
+         regs[REG_SP], regs[REG_FP], regs[REG_TP], regs[REG_RA]);
+#endif
+}
+
 /****************************************************************************
  * Name: up_taskdump
  ****************************************************************************/
 
-#ifdef CONFIG_STACK_COLORATION
+#if defined(CONFIG_STACK_COLORATION) || defined(CONFIG_ARCH_HAVE_BACKTRACE)
 static void up_taskdump(FAR struct tcb_s *tcb, FAR void *arg)
 {
   /* Dump interesting properties of this task */
 
 #if CONFIG_TASK_NAME_SIZE > 0
-  _alert("%s: PID=%d Stack Used=%lu of %lu\n",
-        tcb->name, tcb->pid, (unsigned long)up_check_tcbstack(tcb),
-        (unsigned long)tcb->adj_stack_size);
+  _alert("%s: PID=%d\n", tcb->name, tcb->pid);
 #else
-  _alert("PID: %d Stack Used=%lu of %lu\n",
-        tcb->pid, (unsigned long)up_check_tcbstack(tcb),
-        (unsigned long)tcb->adj_stack_size);
+  _alert("PID: %d\n", tcb->pid);
 #endif
-}
+
+  /* Show stack info */
+
+#ifdef CONFIG_STACK_COLORATION
+  _alert("Stack Used=%lu of %lu\n", (unsigned long)up_check_tcbstack(tcb),
+                                    (unsigned long)tcb->adj_stack_size);
 #endif
 
+  /* Show back trace */
+
+#ifdef CONFIG_ARCH_HAVE_BACKTRACE
+  sched_dumpstack(tcb->pid);
+#endif
+
+  /* Dump the registers */
+
+  up_registerdump(tcb->xcp.regs);
+
+  /* Add a blank line */
+
+  _alert("\n");

Review comment:
       remove

##########
File path: arch/risc-v/src/rv64gc/riscv_assert.c
##########
@@ -199,9 +194,16 @@ static void up_dumpstate(void)
   uintptr_t istacksize;
 #endif
 
+  /* Show back trace */
+
+#ifdef CONFIG_ARCH_HAVE_BACKTRACE

Review comment:
       CONFIG_SCED_BACKTRACE

##########
File path: arch/risc-v/src/rv32im/riscv_assert.c
##########
@@ -85,88 +85,91 @@ static void riscv_stackdump(uint32_t sp, uint32_t stack_top)
 #endif
 
 /****************************************************************************
- * Name: riscv_taskdump
+ * Name: riscv_registerdump
  ****************************************************************************/
 
-#ifdef CONFIG_STACK_COLORATION
-static void riscv_taskdump(FAR struct tcb_s *tcb, FAR void *arg)
+#ifdef CONFIG_ARCH_STACKDUMP
+static inline void riscv_registerdump(FAR volatile uint32_t *regs)
 {
-  /* Dump interesting properties of this task */
+  /* Are user registers available from interrupt processing? */
 
-#if CONFIG_TASK_NAME_SIZE > 0
-  _alert("%s: PID=%d Stack Used=%lu of %lu\n",
-        tcb->name, tcb->pid, (unsigned long)up_check_tcbstack(tcb),
-        (unsigned long)tcb->adj_stack_size);
+  _alert("EPC:%08x \n", regs[REG_EPC]);
+  _alert("A0:%08x A1:%08x A2:%08x A3:%08x A4:%08x A5:%08x "
+         "A6:%08x A7:%08x\n",
+        regs[REG_A0], regs[REG_A1], regs[REG_A2], regs[REG_A3],
+        regs[REG_A4], regs[REG_A5], regs[REG_A6], regs[REG_A7]);
+  _alert("T0:%08x T1:%08x T2:%08x T3:%08x T4:%08x T5:%08x T6:%08x\n",
+        regs[REG_T0], regs[REG_T1], regs[REG_T2], regs[REG_T3],
+        regs[REG_T4], regs[REG_T5], regs[REG_T6]);
+  _alert("S0:%08x S1:%08x S2:%08x S3:%08x S4:%08x S5:%08x "
+         "S6:%08x S7:%08x\n",
+        regs[REG_S0], regs[REG_S1], regs[REG_S2], regs[REG_S3],
+        regs[REG_S4], regs[REG_S5], regs[REG_S6], regs[REG_S7]);
+  _alert("S8:%08x S9:%08x S10:%08x S11:%08x\n",
+        regs[REG_S8], regs[REG_S9], regs[REG_S10], regs[REG_S11]);
+#ifdef RISCV_SAVE_GP
+  _alert("GP:%08x SP:%08x FP:%08x TP:%08x RA:%08x\n",
+        regs[REG_GP], regs[REG_SP], regs[REG_FP], regs[REG_TP],
+        regs[REG_RA]);
 #else
-  _alert("PID: %d Stack Used=%lu of %lu\n",
-        tcb->pid, (unsigned long)up_check_tcbstack(tcb),
-        (unsigned long)tcb->adj_stack_size);
+  _alert("SP:%08x FP:%08x TP:%08x RA:%08x\n",
+        regs[REG_SP], regs[REG_FP], regs[REG_TP], regs[REG_RA]);
 #endif
 }
+#else
+#  define riscv_registerdump(reg)
 #endif
 
 /****************************************************************************
- * Name: riscv_showtasks
+ * Name: riscv_taskdump
  ****************************************************************************/
 
-#ifdef CONFIG_STACK_COLORATION
-static inline void riscv_showtasks(void)
+#if defined(CONFIG_STACK_COLORATION) || defined(CONFIG_ARCH_HAVE_BACKTRACE)

Review comment:
       change to CONFIG_SCHED_BACKTRACE

##########
File path: arch/risc-v/src/rv64gc/riscv_assert.c
##########
@@ -199,9 +194,16 @@ static void up_dumpstate(void)
   uintptr_t istacksize;
 #endif
 
+  /* Show back trace */
+
+#ifdef CONFIG_ARCH_HAVE_BACKTRACE
+  _alert("Call Trace:\n");

Review comment:
       remove

##########
File path: arch/risc-v/src/rv64gc/riscv_assert.c
##########
@@ -86,104 +86,99 @@ static void up_stackdump(uint64_t sp, uintptr_t stack_top)
     }
 }
 
+/****************************************************************************
+ * Name: up_registerdump
+ ****************************************************************************/
+
+static inline void up_registerdump(FAR volatile uintptr_t *regs)
+{
+  /* Are user registers available from interrupt processing? */
+
+  _alert("EPC:%016" PRIx64 " \n", regs[REG_EPC]);
+  _alert("A0:%016" PRIx64 " A1:%01" PRIx64 "6 A2:%016" PRIx64
+         " A3:%016" PRIx64 " \n",
+         regs[REG_A0], regs[REG_A1], regs[REG_A2], regs[REG_A3]);
+  _alert("A4:%016" PRIx64 " A5:%016" PRIx64 "A6:%016" PRIx64
+         " A7:%016" PRIx64 " \n",
+         regs[REG_A4], regs[REG_A5], regs[REG_A6], regs[REG_A7]);
+  _alert("T0:%016" PRIx64 " T1:%016" PRIx64 " T2:%016" PRIx64
+         " T3:%016" PRIx64 " \n",
+         regs[REG_T0], regs[REG_T1], regs[REG_T2], regs[REG_T3]);
+  _alert("T4:%016" PRIx64 " T5:%016" PRIx64 " T6:%016" PRIx64 " \n",
+         regs[REG_T4], regs[REG_T5], regs[REG_T6]);
+  _alert("S0:%016" PRIx64 " S1:%016" PRIx64 " S2:%016" PRIx64
+         " S3:%016" PRIx64 " \n",
+         regs[REG_S0], regs[REG_S1], regs[REG_S2], regs[REG_S3]);
+  _alert("S4:%016" PRIx64 " S5:%016" PRIx64 " S6:%016" PRIx64
+         " S7:%016" PRIx64 " \n",
+         regs[REG_S4], regs[REG_S5], regs[REG_S6], regs[REG_S7]);
+  _alert("S8:%016" PRIx64 " S9:%016" PRIx64 " S10:%016" PRIx64
+         " S11:%016" PRIx64 " \n",
+         regs[REG_S8], regs[REG_S9], regs[REG_S10], regs[REG_S11]);
+#ifdef RISCV_SAVE_GP
+  _alert("GP:%016" PRIx64 " SP:%016" PRIx64 " FP:%016" PRIx64
+         " TP:%016" PRIx64 " RA:%016" PRIx64 " \n",
+         regs[REG_GP], regs[REG_SP], regs[REG_FP], regs[REG_TP],
+         regs[REG_RA]);
+#else
+  _alert("SP:%016" PRIx64 " FP:%016" PRIx64 " TP:%016" PRIx64
+         " RA:%016" PRIx64 " \n",
+         regs[REG_SP], regs[REG_FP], regs[REG_TP], regs[REG_RA]);
+#endif
+}
+
 /****************************************************************************
  * Name: up_taskdump
  ****************************************************************************/
 
-#ifdef CONFIG_STACK_COLORATION
+#if defined(CONFIG_STACK_COLORATION) || defined(CONFIG_ARCH_HAVE_BACKTRACE)
 static void up_taskdump(FAR struct tcb_s *tcb, FAR void *arg)
 {
   /* Dump interesting properties of this task */
 
 #if CONFIG_TASK_NAME_SIZE > 0
-  _alert("%s: PID=%d Stack Used=%lu of %lu\n",
-        tcb->name, tcb->pid, (unsigned long)up_check_tcbstack(tcb),
-        (unsigned long)tcb->adj_stack_size);
+  _alert("%s: PID=%d\n", tcb->name, tcb->pid);
 #else
-  _alert("PID: %d Stack Used=%lu of %lu\n",
-        tcb->pid, (unsigned long)up_check_tcbstack(tcb),
-        (unsigned long)tcb->adj_stack_size);
+  _alert("PID: %d\n", tcb->pid);

Review comment:
       wh not put stack info in the same line.

##########
File path: arch/risc-v/src/rv64gc/riscv_assert.c
##########
@@ -86,104 +86,99 @@ static void up_stackdump(uint64_t sp, uintptr_t stack_top)
     }
 }
 
+/****************************************************************************
+ * Name: up_registerdump
+ ****************************************************************************/
+
+static inline void up_registerdump(FAR volatile uintptr_t *regs)
+{
+  /* Are user registers available from interrupt processing? */
+
+  _alert("EPC:%016" PRIx64 " \n", regs[REG_EPC]);
+  _alert("A0:%016" PRIx64 " A1:%01" PRIx64 "6 A2:%016" PRIx64
+         " A3:%016" PRIx64 " \n",
+         regs[REG_A0], regs[REG_A1], regs[REG_A2], regs[REG_A3]);
+  _alert("A4:%016" PRIx64 " A5:%016" PRIx64 "A6:%016" PRIx64
+         " A7:%016" PRIx64 " \n",
+         regs[REG_A4], regs[REG_A5], regs[REG_A6], regs[REG_A7]);
+  _alert("T0:%016" PRIx64 " T1:%016" PRIx64 " T2:%016" PRIx64
+         " T3:%016" PRIx64 " \n",
+         regs[REG_T0], regs[REG_T1], regs[REG_T2], regs[REG_T3]);
+  _alert("T4:%016" PRIx64 " T5:%016" PRIx64 " T6:%016" PRIx64 " \n",
+         regs[REG_T4], regs[REG_T5], regs[REG_T6]);
+  _alert("S0:%016" PRIx64 " S1:%016" PRIx64 " S2:%016" PRIx64
+         " S3:%016" PRIx64 " \n",
+         regs[REG_S0], regs[REG_S1], regs[REG_S2], regs[REG_S3]);
+  _alert("S4:%016" PRIx64 " S5:%016" PRIx64 " S6:%016" PRIx64
+         " S7:%016" PRIx64 " \n",
+         regs[REG_S4], regs[REG_S5], regs[REG_S6], regs[REG_S7]);
+  _alert("S8:%016" PRIx64 " S9:%016" PRIx64 " S10:%016" PRIx64
+         " S11:%016" PRIx64 " \n",
+         regs[REG_S8], regs[REG_S9], regs[REG_S10], regs[REG_S11]);
+#ifdef RISCV_SAVE_GP
+  _alert("GP:%016" PRIx64 " SP:%016" PRIx64 " FP:%016" PRIx64
+         " TP:%016" PRIx64 " RA:%016" PRIx64 " \n",
+         regs[REG_GP], regs[REG_SP], regs[REG_FP], regs[REG_TP],
+         regs[REG_RA]);
+#else
+  _alert("SP:%016" PRIx64 " FP:%016" PRIx64 " TP:%016" PRIx64
+         " RA:%016" PRIx64 " \n",
+         regs[REG_SP], regs[REG_FP], regs[REG_TP], regs[REG_RA]);
+#endif
+}
+
 /****************************************************************************
  * Name: up_taskdump
  ****************************************************************************/
 
-#ifdef CONFIG_STACK_COLORATION
+#if defined(CONFIG_STACK_COLORATION) || defined(CONFIG_ARCH_HAVE_BACKTRACE)
 static void up_taskdump(FAR struct tcb_s *tcb, FAR void *arg)
 {
   /* Dump interesting properties of this task */
 
 #if CONFIG_TASK_NAME_SIZE > 0
-  _alert("%s: PID=%d Stack Used=%lu of %lu\n",
-        tcb->name, tcb->pid, (unsigned long)up_check_tcbstack(tcb),
-        (unsigned long)tcb->adj_stack_size);
+  _alert("%s: PID=%d\n", tcb->name, tcb->pid);
 #else
-  _alert("PID: %d Stack Used=%lu of %lu\n",
-        tcb->pid, (unsigned long)up_check_tcbstack(tcb),
-        (unsigned long)tcb->adj_stack_size);
+  _alert("PID: %d\n", tcb->pid);
 #endif
-}
+
+  /* Show stack info */
+
+#ifdef CONFIG_STACK_COLORATION
+  _alert("Stack Used=%lu of %lu\n", (unsigned long)up_check_tcbstack(tcb),
+                                    (unsigned long)tcb->adj_stack_size);
 #endif
 
+  /* Show back trace */
+
+#ifdef CONFIG_ARCH_HAVE_BACKTRACE
+  sched_dumpstack(tcb->pid);
+#endif
+
+  /* Dump the registers */
+
+  up_registerdump(tcb->xcp.regs);
+
+  /* Add a blank line */
+
+  _alert("\n");
+}
+
 /****************************************************************************
  * Name: up_showtasks
  ****************************************************************************/
 
-#ifdef CONFIG_STACK_COLORATION
 static inline void up_showtasks(void)
 {
   /* Dump interesting properties of each task in the crash environment */
 
+  _alert("Tasks status:\n");

Review comment:
       remove




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org