Shanks0224 opened a new pull request, #22605: URL: https://github.com/apache/nuttx/pull/22605
*Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary `up_debugpoint_add()` on Xtensa supports breakpoints and watchpoints, but returns -EINVAL for `DEBUGPOINT_STEPPOINT`, which a debugger such as the gdbstub uses to step one instruction. - **Remove an unused variable** in `up_debugpoint_add()` and fix the brace alignment that nxstyle reports in `up_debugpoint_remove()`. - **Support single-step debugpoints** with the ICOUNT register: arming ICOUNT with -2 raises a debug exception after the next instruction of the stopped code, and the debug exception handler calls the callback of the steppoint. The handler now also marks the CPU as being in an interrupt context and saves the exception frame in `xcp.regs` while it runs, as the interrupt dispatcher does, so that a callback can read and change the registers of the stopped code. - **Step at the interrupt level of the stopped code.** ICOUNT only counts instructions that run below ICOUNTLEVEL. With ICOUNTLEVEL fixed at `XCHAL_EXCM_LEVEL`, code that runs with interrupts disabled or in a high priority handler was not counted, so a step from there stopped only after the code returned to a lower level. ICOUNTLEVEL is now set one above the interrupt level of the stopped code; for this the handlers of levels above `XCHAL_EXCM_LEVEL` keep PS.INTLEVEL at their own level instead of lowering it, otherwise the debug exception handler itself would be counted. ## Impact Xtensa only, and only when `up_debugpoint_add(DEBUGPOINT_STEPPOINT, ...)` is used. Breakpoints and watchpoints behave as before. The debug exception handler now sets the interrupt context flag and `xcp.regs` while it runs. The handlers of interrupt levels above `XCHAL_EXCM_LEVEL` keep their own PS.INTLEVEL; the normal interrupt path is unchanged. ## Testing ESP32 on the Espressif QEMU (esp-develop-9.0.0-20240606), esp32-devkitc:nsh + `CONFIG_ESP32_QEMU_IMAGE=y`, xtensa-esp-elf 14.2.0. The test programs set a breakpoint on a function of 16 `nop`s and, from the breakpoint callback, step through it with steppoints, recording the PC of each step (`R4` counts the steps whose PC is inside the function). Stepping a normal function: master: ``` R1 breakpoint add 0 R2 breakpoint hits 1, steppoint add -22, steps 0 R4 target 400e7608-400e7630, 0/0 steps inside FAIL ``` this PR: ``` R1 breakpoint add 0 R2 breakpoint hits 1, steppoint add 0, steps 6 R4 target 400e76b8-400e76e0, 6/6 steps inside TEST DONE ``` Stepping code that runs with interrupts disabled (`up_irq_save()`): master: ``` R2 breakpoint hits 1, steppoint add -22, steps 0 FAIL ``` first two commits only (ICOUNTLEVEL = `XCHAL_EXCM_LEVEL`), the steps are counted only after the code returns to a lower level: ``` R2 breakpoint hits 1, steppoint add 0, steps 6 R4 target 400e7698-400e76c0, 0/6 steps inside FAIL ``` this PR: ``` R2 breakpoint hits 1, steppoint add 0, steps 6 R4 target 400e76c0-400e76e8, 6/6 steps inside TEST DONE ``` Stepping 3000 instructions through a busy loop, so that the timer interrupt arrives while stepping: master: ``` R2 breakpoint hits 1, steppoint add -22, steps 0 FAIL ``` this PR: ``` R2 breakpoint hits 1, steppoint add 0, steps 3000 R4 target 400e76c4-400e76dc, 3000/3000 steps inside TEST DONE ``` ostest on the same QEMU: `ostest_main: Exiting with status 0`, no ERROR lines. (`strto_test()` was skipped: on ESP32 `strtol()`/`strtoul()` come from the ROM newlib, which does not set the NuttX errno, so it asserts on master independently of this change.) Each commit builds esp32-devkitc:nsh, esp32-devkitc:smp, esp32s2-saola-1:nsh, esp32s3-devkit:nsh and esp32s3-devkit:smp without warnings. Not tested on real hardware. -- 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]
