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

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


The following commit(s) were added to refs/heads/master by this push:
     new ff65512df9c boards/risc-v/qemu-rv/rv-virt: add gdbstub configuration
ff65512df9c is described below

commit ff65512df9c7dc3bc40c5a2b6eb6179b5ba76475
Author: anjiahao <[email protected]>
AuthorDate: Thu Nov 26 00:56:40 2026 +0800

    boards/risc-v/qemu-rv/rv-virt: add gdbstub configuration
    
    rv-virt has a single 16550 UART, so the console and the GDB stub share
    /dev/ttyS0. Enable CONFIG_SERIAL_GDBSTUB with AUTO_ATTACH and
    WAIT_CONNECT so that the serial driver registers the stub transport with
    the uart_dev_s operations. This is the transport that works for hardware
    breakpoints and watchpoints, whose stop is reported from the breakpoint
    exception context; the descriptor based transport of apps/system/gdbstub
    is not usable there.
    
    Describe the configuration and the QEMU/GDB invocation in the rv-virt
    board documentation.
    
    Signed-off-by: anjiahao <[email protected]>
---
 .../risc-v/qemu-rv/boards/rv-virt/index.rst        | 47 ++++++++++++++
 .../qemu-rv/rv-virt/configs/gdbstub/defconfig      | 75 ++++++++++++++++++++++
 2 files changed, 122 insertions(+)

diff --git a/Documentation/platforms/risc-v/qemu-rv/boards/rv-virt/index.rst 
b/Documentation/platforms/risc-v/qemu-rv/boards/rv-virt/index.rst
index 8e6250617f4..83db2591278 100644
--- a/Documentation/platforms/risc-v/qemu-rv/boards/rv-virt/index.rst
+++ b/Documentation/platforms/risc-v/qemu-rv/boards/rv-virt/index.rst
@@ -163,6 +163,53 @@ This configuration uses ``apps/examples/elf`` in order to 
test the ELF loader
 on 32-bit RISC-V. It boots directly into the ELF example and does not provide
 the NuttShell (NSH).
 
+gdbstub
+-------
+
+Debug configuration that runs a GDB remote stub on the console UART. The
+rv-virt machine has a single 16550 UART, so the console and the stub share
+``/dev/ttyS0``. ``CONFIG_SERIAL_GDBSTUB_WAIT_CONNECT`` makes the boot wait
+for GDB and ``CONFIG_SERIAL_GDBSTUB_AUTO_ATTACH`` lets a character received
+on the port stop the running target (Ctrl-C).
+
+The stub is registered by the serial driver and uses the ``uart_dev_s``
+operations for TX and RX (``CONFIG_SERIAL_GDBSTUB``). This is required for
+hardware breakpoints and watchpoints: their stop is reported from the
+breakpoint exception context, where the descriptor based transport of the
+``apps/system/gdbstub`` application is not usable (the descriptor is looked
+up in the interrupted task's file table, which typically fails with
+``-EBADF``).
+
+Build it with::
+
+    $ ./tools/configure.sh rv-virt:gdbstub
+    $ make -j$(nproc)
+
+Export the serial line over TCP so that GDB can speak the remote protocol
+directly::
+
+    $ qemu-system-riscv64 -M virt -bios none -kernel nuttx \
+        -display none -monitor none \
+        -serial tcp:127.0.0.1:1234,server=on,wait=off
+
+Then connect from the host::
+
+    $ gdb-multiarch nuttx
+    (gdb) target remote 127.0.0.1:1234
+    (gdb) break up_idle
+    (gdb) continue
+
+Hardware watchpoints work as well; the following stops on the next timer
+tick::
+
+    (gdb) watch g_hrtimer_last_expired
+    (gdb) continue
+
+``-bios none -kernel nuttx`` is used because this configuration runs in
+machine mode and does not need OpenSBI. A local PTY can be used instead of
+the TCP socket (``-serial pty``); GDB then connects to the printed
+``/dev/pts/N`` path.
+
 libcxx64
 --------
 
diff --git a/boards/risc-v/qemu-rv/rv-virt/configs/gdbstub/defconfig 
b/boards/risc-v/qemu-rv/rv-virt/configs/gdbstub/defconfig
new file mode 100644
index 00000000000..c7c5d98e4cf
--- /dev/null
+++ b/boards/risc-v/qemu-rv/rv-virt/configs/gdbstub/defconfig
@@ -0,0 +1,75 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed 
.config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that 
includes your
+# modifications.
+#
+# CONFIG_DISABLE_OS_API is not set
+# CONFIG_NSH_DISABLE_LOSMART is not set
+CONFIG_16550_ADDRWIDTH=0
+CONFIG_16550_UART0=y
+CONFIG_16550_UART0_BASE=0x10000000
+CONFIG_16550_UART0_CLOCK=3686400
+CONFIG_16550_UART0_IRQ=37
+CONFIG_16550_UART0_SERIAL_CONSOLE=y
+CONFIG_16550_UART=y
+CONFIG_ARCH="risc-v"
+CONFIG_ARCH_BOARD="rv-virt"
+CONFIG_ARCH_BOARD_QEMU_RV_VIRT=y
+CONFIG_ARCH_CHIP="qemu-rv"
+CONFIG_ARCH_CHIP_QEMU_RV64=y
+CONFIG_ARCH_CHIP_QEMU_RV=y
+CONFIG_ARCH_CHIP_QEMU_RV_ISA_A=y
+CONFIG_ARCH_CHIP_QEMU_RV_ISA_C=y
+CONFIG_ARCH_CHIP_QEMU_RV_ISA_M=y
+CONFIG_ARCH_INTERRUPTSTACK=4096
+CONFIG_ARCH_RISCV=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_BCH=y
+CONFIG_BOARDCTL_POWEROFF=y
+CONFIG_BOARD_LOOPSPERMSEC=6366
+CONFIG_BUILTIN=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_FULLOPT=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DEFAULT_TASK_STACKSIZE=4096
+CONFIG_DEVICE_TREE=y
+CONFIG_ELF=y
+CONFIG_EXAMPLES_HELLO=y
+CONFIG_FS_HOSTFS=y
+CONFIG_FS_PROCFS=y
+CONFIG_IDLETHREAD_STACKSIZE=2048
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INIT_STACKSIZE=3072
+CONFIG_LIBC_ENVPATH=y
+CONFIG_LIBC_EXECFUNCS=y
+CONFIG_LIBC_GDBSTUB=y
+CONFIG_LIBC_PERROR_STDOUT=y
+CONFIG_LIBC_STRERROR=y
+CONFIG_LIBM=y
+CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_READLINE=y
+CONFIG_PATH_INITIAL="/system/bin"
+CONFIG_RAM_SIZE=33554432
+CONFIG_RAM_START=0x80000000
+CONFIG_READLINE_CMD_HISTORY=y
+CONFIG_RISCV_SEMIHOSTING_HOSTFS=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_SERIAL_GDBSTUB=y
+CONFIG_SERIAL_GDBSTUB_AUTO_ATTACH=y
+CONFIG_SERIAL_GDBSTUB_PATH="/dev/ttyS0"
+CONFIG_SERIAL_GDBSTUB_WAIT_CONNECT=y
+CONFIG_SERIAL_UART_ARCH_MMIO=y
+CONFIG_STACK_COLORATION=y
+CONFIG_START_MONTH=12
+CONFIG_START_YEAR=2021
+CONFIG_SYMTAB_ORDEREDBYNAME=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_SYSTEM_NSH_STACKSIZE=3072
+CONFIG_TESTING_GETPRIME=y
+CONFIG_TESTING_OSTEST=y
+CONFIG_USEC_PER_TICK=1000

Reply via email to