You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenOCD SMP调试树莓派5时GDB仅显示1个线程求助

Raspberry Pi 5 SMP调试问题:GDB无法识别多核心线程

我正在用调试探针、OpenOCD和GDB调试Raspberry Pi 5,四个核心均在运行代码,目标是配置SMP模式,让GDB为每个核心对应一个独立线程。

此前尝试非SMP方式调试(在GDB中为每个核心添加inferior并连接不同端口)虽能运行,但存在断点跳转后OpenOCD无法将暂停指令恢复为原指令的问题,必须手动修改程序计数器与指令,因此希望切换到无该问题的SMP调试方案。

我认为Raspberry Pi 5的OpenOCD配置文件存在遗漏或错误,已参考相似问题添加了-rtos hwthread参数,但GDB执行info threads仍仅显示一个线程,而monitor targets显示OpenOCD能正常识别四个核心。


OpenOCD配置文件

# rpi5 chip name
set _CHIP_NAME bcm2712
# the rpi5 has four cortex-a76 cores
set _CORES 4
# Use SMP since we are running code on multiple cores
set _USE_SMP 1
#
set _DAP_TAPID 0x4ba00477

# Specify that the debug probe is using the SWD protocol
transport select swd
# Related to creating a new debug access port
swd newdap $_CHIP_NAME cpu -expected-id $_DAP_TAPID -irlen 4
# Sets clock speed in KHz
adapter speed 4000

# Create a debug access port
dap create $_CHIP_NAME.dap -chain-position $_CHIP_NAME.cpu

# TODO: don't know why this is needed or if it's messing up the SMP config
# MEM-AP for direct access
# target create $_CHIP_NAME.ap mem_ap -dap $_CHIP_NAME.dap -ap-num 0

# these addresses are obtained from the ROM table via 'dap info 0' command
# Each address if for is for a specific core
#
# Debug controller base address for each core
set _DBG_BASE {0x80010000 0x80110000 0x80210000 0x80310000}
#
set _CTI_BASE {0x80020000 0x80120000 0x80220000 0x80320000}

# Used for building the 'target smp' command for each core
set _SMP_COMMAND "target smp"

# Perform configuration for each of the four cores
for { set _CORE 0 } { $_CORE < $_CORES } { incr _CORE } {
        # Set the CTI name for each core
        set _CTI_NAME $_CHIP_NAME.cti$_CORE
        # Set the target name for each core
        set _TARGET_NAME $_CHIP_NAME.cpu$_CORE
        # Add each target name to the SMP command
        set _SMP_COMMAND "$_SMP_COMMAND $_TARGET_NAME"

        # Create an ARM Cross-Trigger Interface for each core
        # CTI is control core states and access registers
        cti create $_CTI_NAME -dap $_CHIP_NAME.dap -ap-num 0 -baseaddr [lindex $_CTI_BASE $_CORE]

        # Create debug target for GDB that refers to a JTAG TAP
        # aarch64: this is an ARMv8-A core with an MMU
        # -dap: debug access port to use for this target
        target create $_TARGET_NAME aarch64 -dap $_CHIP_NAME.dap

        #
        # Configure the debug target
        #
        # Set the CTI for this core
        $_TARGET_NAME configure -cti $_CTI_NAME
        # Set the address of the debug controller for this core
        $_TARGET_NAME configure -dbgbase [lindex $_DBG_BASE $_CORE]
        # Set the access port for the target
        $_TARGET_NAME configure -ap-num 0
        # This is needed for GDB to correctly inspect the SMP system (section 20.7)
        $_TARGET_NAME configure -rtos hwthread
}

# Run the SMP command to add each target to the SMP config
eval $_SMP_COMMAND
# Print to verify command
echo "Running SMP Command: $_SMP_COMMAND"

# Set the current target to the primary core before GDB starts
targets $_CHIP_NAME.cpu0

OpenOCD与GDB启动输出

Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : Hardware thread awareness created
Running SMP Command: target smp bcm2712.cpu0 bcm2712.cpu1 bcm2712.cpu2 bcm2712.cpu3
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : Using CMSIS-DAPv2 interface with VID:PID=0x2e8a:0x000c, serial=E6633861A32A5938
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 4000 kHz
Info : SWD DPIDR 0x2ba01477
Info : bcm2712.cpu0: hardware has 6 breakpoints, 4 watchpoints
Info : bcm2712.cpu1: hardware has 6 breakpoints, 4 watchpoints
Info : bcm2712.cpu2: hardware has 6 breakpoints, 4 watchpoints
GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Reading symbols from ./fsix_files/fsix.arm64-rpi5.elf...
Info : bcm2712.cpu3: hardware has 6 breakpoints, 4 watchpoints
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/ubuntu/Documents/rpi5_debug/fsix_files/fsix.arm64-rpi5.elf.
Use `info auto-load python-scripts [REGEXP]' to list them.
Info : starting gdb server for bcm2712.cpu0 on 3333
Info : Listening on port 3333 for gdb connections
Breakpoint 1 at 0x80000
Breakpoint 2 at 0x8087c
Remote debugging using :3333
Info : accepting 'gdb' connection on tcp/3333
Info : bcm2712.cpu0 cluster 0 core 0 multi core
Info : bcm2712.cpu1 cluster 1 core 0 multi core
bcm2712.cpu1 halted in AArch64 state due to debug-request, current mode: EL3H
cpsr: 0x200002cd pc: 0x1c14
MMU: disabled, D-Cache: disabled, I-Cache: enabled
Info : bcm2712.cpu2 cluster 2 core 0 multi core
bcm2712.cpu2 halted in AArch64 state due to debug-request, current mode: EL3H
cpsr: 0x200002cd pc: 0x1c14
MMU: disabled, D-Cache: disabled, I-Cache: enabled
Info : bcm2712.cpu3 cluster 3 core 0 multi core
bcm2712.cpu3 halted in AArch64 state due to debug-request, current mode: EL3H
cpsr: 0x200002cd pc: 0x1c14
MMU: disabled, D-Cache: disabled, I-Cache: enabled
bcm2712.cpu0 halted in AArch64 state due to debug-request, current mode: EL2H
cpsr: 0x000003c9 pc: 0x80000
MMU: disabled, D-Cache: disabled, I-Cache: disabled
Info : New GDB Connection: 1, Target bcm2712.cpu0, state: halted

当前info threads输出

(gdb) info threads
  Id   Target Id                                                          Frame
* 1    Thread 1 "bcm2712.cpu3" (Name: bcm2712.cpu3, state: debug-request) 0x0000000000080000 in _start ()

期望的info threads输出

(gdb) info threads
  Id   Target Id                    Frame
* 1    Thread 1.1 (CPU#0 [running]) 0x0000000000080000 in _start ()
  2    Thread 1.2 (CPU#1 [running]) 0x000000000000030c in ?? ()
  3    Thread 1.3 (CPU#2 [running]) 0x000000000000030c in ?? ()
  4    Thread 1.4 (CPU#3 [running]) 0x000000000000030c in ?? ()

monitor targets输出

(gdb) monitor targets
    TargetName         Type       Endian TapName            State      
--  ------------------ ---------- ------ ------------------ ------------
 0* bcm2712.cpu0       aarch64    little bcm2712.cpu        halted
 1  bcm2712.cpu1       aarch64    little bcm2712.cpu        halted
 2  bcm2712.cpu2       aarch64    little bcm2712.cpu        halted
 3  bcm2712.cpu3       aarch64    little bcm2712.cpu        halted


我是OpenOCD新手,已经查阅了不少用户指南但仍无头绪,恳请帮助。

内容的提问来源于stack exchange,提问作者CorkiMain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 05:59:54