xiaoxiang781216 commented on code in PR #19528:
URL: https://github.com/apache/nuttx/pull/19528#discussion_r3653097042
##########
arch/risc-v/src/common/riscv_backtrace.c:
##########
@@ -25,11 +25,81 @@
****************************************************************************/
#include <nuttx/config.h>
+#include <stdbool.h>
#include <nuttx/arch.h>
#include <nuttx/addrenv.h>
+#include <nuttx/compiler.h>
#include "sched/sched.h"
#include "riscv_internal.h"
+/****************************************************************************
+ * Private Types
Review Comment:
macro section
##########
arch/risc-v/src/common/riscv_backtrace.c:
##########
@@ -25,11 +25,81 @@
****************************************************************************/
#include <nuttx/config.h>
+#include <stdbool.h>
#include <nuttx/arch.h>
#include <nuttx/addrenv.h>
+#include <nuttx/compiler.h>
#include "sched/sched.h"
#include "riscv_internal.h"
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* Maximum number of independent starting points up_backtrace() can splice
+ * together. Current worst case: the main fp chain (possibly starting on
+ * the interrupt or kernel stack) plus the xcp.sregs splice used to reach
+ * the user call site of a task that is mid-syscall.
+ */
+
+#define BT_MAX_SEGMENTS 2
+
+/* Upper bound on how many candidate ranges a single segment can
+ * register: interrupt stack, kernel stack, user stack.
+ */
+
+#define BT_MAX_RANGES 3
+
+/* One candidate stack range a segment's fp chain may be walking. */
+
+struct bt_range_s
Review Comment:
let change bt_/BT_ to backtrace_/BACKTRACE_
##########
arch/risc-v/src/common/riscv_backtrace.c:
##########
@@ -42,7 +112,7 @@
*
****************************************************************************/
-static inline uintptr_t getfp(void)
+always_inline_function static uintptr_t getfp(void)
Review Comment:
```static always_inline_function...```
##########
arch/risc-v/src/common/riscv_backtrace.c:
##########
@@ -184,100 +392,98 @@ static int backtrace(uintptr_t *base, uintptr_t *limit,
int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
{
struct tcb_s *rtcb = running_task();
- int ret;
+ struct bt_segment_s segments[BT_MAX_SEGMENTS];
+ struct bt_segment_s *segment;
+ uintptr_t *ubase;
+ uintptr_t *ulimit;
+ bool self = (tcb == NULL || tcb == rtcb);
+ int nsegments = 0;
+#if CONFIG_ARCH_INTERRUPTSTACK > 15
+ int cpu;
+ uintptr_t *ilimit;
+ uintptr_t *ibase;
+#endif
if (size <= 0 || !buffer)
{
return 0;
}
- if (tcb == NULL || tcb == rtcb)
+ if (self)
{
- if (up_interrupt_context())
- {
- ret = backtrace(rtcb->stack_base_ptr,
- (uintptr_t *)((uintptr_t)rtcb->stack_base_ptr +
- rtcb->adj_stack_size),
- (void *)getfp(), NULL, buffer, size, &skip
-#ifdef CONFIG_ARCH_ADDRENV
- , NULL
-#endif
- );
- if (ret < size)
- {
- ret += backtrace(rtcb->stack_base_ptr, (uintptr_t *)
- ((uintptr_t)rtcb->stack_base_ptr +
- rtcb->adj_stack_size),
- running_regs()[REG_FP],
- running_regs()[REG_EPC],
- &buffer[ret], size - ret, &skip
-#ifdef CONFIG_ARCH_ADDRENV
- , NULL
-#endif
- );
- }
- }
- else
- {
-#ifdef CONFIG_ARCH_KERNEL_STACK
- if ((rtcb->flags & TCB_FLAG_SYSCALL) != 0)
- {
- ret = backtrace(rtcb->stack_base_ptr, (uintptr_t *)
- ((uintptr_t)rtcb->stack_base_ptr +
- rtcb->adj_stack_size),
- (void *)rtcb->xcp.sregs[REG_FP],
- (void *)rtcb->xcp.sregs[REG_EPC],
- buffer, size, &skip
-#ifdef CONFIG_ARCH_ADDRENV
- , NULL
-#endif
- );
- }
- else
-#endif
- {
- ret = backtrace(rtcb->stack_base_ptr, (uintptr_t *)
- ((uintptr_t)rtcb->stack_base_ptr +
- rtcb->adj_stack_size),
- (void *)getfp(), NULL, buffer, size, &skip
-#ifdef CONFIG_ARCH_ADDRENV
- , NULL
-#endif
- );
- }
- }
+ tcb = rtcb;
}
- else
- {
-#ifdef CONFIG_ARCH_KERNEL_STACK
- if ((tcb->flags & TCB_FLAG_SYSCALL) != 0)
- {
- ret = backtrace(tcb->stack_base_ptr,
- (uintptr_t *)((uintptr_t)tcb->stack_base_ptr +
- tcb->adj_stack_size),
- (void *)tcb->xcp.sregs[REG_FP],
- (void *)tcb->xcp.sregs[REG_EPC],
- buffer, size, &skip
-#ifdef CONFIG_ARCH_ADDRENV
- , tcb->addrenv_own
+
+ ubase = tcb->stack_base_ptr;
+ ulimit = (uintptr_t *)((uintptr_t)tcb->stack_base_ptr +
+ tcb->adj_stack_size);
+
+#ifdef CONFIG_LIB_SYSCALL
+ bool insyscall = (tcb->flags & TCB_FLAG_SYSCALL) != 0;
Review Comment:
move to the beginning
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]