linuxdebugginggdbembedded-linuxopenocd

SMP threads not showing in GDB


Trying to debug multi CPU SoC (Amlogic A113X) and faced a problem. So I have this debug configuration: A113X(JTAG) -> Segger J-Link V11 -> OpenOCD -> gdb-multiarch Everything is connected and seems okay, but GDB shows just 1 thread (should be 4 - one for each CPU):

(gdb) info threads
  Id   Target Id         Frame 
* 1    Remote target     0xffffff8009853364 in arch_spin_lock (lock=<optimized out>) at ./arch/arm64/include/asm/spinlock.h:89

Meanwhile there are 4 debug targets according to telenet 'targets' command:

> targets            
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* A113X.a53.0        aarch64    little A113X.cpu          halted
 1  A113X.a53.1        aarch64    little A113X.cpu          halted
 2  A113X.a53.2        aarch64    little A113X.cpu          unknown
 3  A113X.a53.3        aarch64    little A113X.cpu          halted

Core 2 is shut down in this particular case.

When I halt CPUs then get this output in GDB:

(gdb) continue
Continuing.
^CA113X.a53.1 halted in AArch64 state due to debug-request, current mode: EL1H
cpsr: 0x800001c5 pc: 0xffffff8009853364
MMU: enabled, D-Cache: enabled, I-Cache: enabled
A113X.a53.3 halted in AArch64 state due to debug-request, current mode: EL1H
cpsr: 0x800000c5 pc: 0xffffff80098532b4
MMU: enabled, D-Cache: enabled, I-Cache: enabled

Program received signal SIGINT, Interrupt.
0xffffff8009853364 in arch_spin_lock (lock=<optimized out>) at ./arch/arm64/include/asm/spinlock.h:89
89      asm volatile(
(gdb) where
#0  0xffffff8009853364 in arch_spin_lock (lock=<optimized out>) at ./arch/arm64/include/asm/spinlock.h:89
#1  do_raw_spin_lock (lock=<optimized out>) at ./include/linux/spinlock.h:148
#2  __raw_spin_lock (lock=<optimized out>) at ./include/linux/spinlock_api_smp.h:145
#3  _raw_spin_lock (lock=0xffffffc01fb86a00) at kernel/locking/spinlock.c:151
#4  0xffffff80090c2114 in try_to_wake_up (p=0xffffffc01963a880, state=<optimized out>, wake_flags=0) at kernel/sched/core.c:2110
#5  0xffffff80090c239c in wake_up_process (p=<optimized out>) at kernel/sched/core.c:2203
#6  0xffffff80090b1b7c in wake_up_worker (pool=<optimized out>) at kernel/workqueue.c:837
#7  insert_work (pwq=<optimized out>, work=<optimized out>, head=<optimized out>, extra_flags=<optimized out>) at kernel/workqueue.c:1310
#8  0xffffff80090b1d10 in __queue_work (cpu=0, wq=0xdf2, work=0x8df2) at kernel/workqueue.c:1460
#9  0xffffff80090b1fc8 in queue_work_on (cpu=8, wq=0xffffffc01dbb5c00, work=0xffffffc01ccb82a0) at kernel/workqueue.c:1485
#10 0xffffff800191d068 in ?? ()
#11 0xffffffc0138664e8 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Is something wrong with my OpenOCD configuration? SMP config looks fine because it halts all 4 cores. What can be wrong here? Thanks beforehand.

Here is openocd config:

telnet_port 4444
gdb_port 3333
source [find interface/jlink.cfg]
transport select jtag
adapter speed 1000
scan_chain
set _CHIPNAME A113X
set _DAPNAME $_CHIPNAME.dap
jtag newtap $_CHIPNAME cpu -irlen 4 -expected-id 0x5ba00477
dap create $_DAPNAME -chain-position $_CHIPNAME.cpu
echo "$_CHIPNAME.cpu"
set CA53_DBGBASE {0x80410000 0x80510000 0x80610000 0x80710000}
set CA53_CTIBASE {0x80420000 0x80520000 0x80620000 0x80720000}
set _num_ca53 4
set _ap_num 0
set smp_targets ""

proc setup_a5x {core_name dbgbase ctibase num boot} {
    for { set _core 0 } { $_core < $num } { incr _core } {
        set _TARGETNAME $::_CHIPNAME.$core_name.$_core
        set _CTINAME $_TARGETNAME.cti

        cti create $_CTINAME -dap $::_DAPNAME -ap-num $::_ap_num \
            -baseaddr [lindex $ctibase $_core]
    
        target create $_TARGETNAME aarch64 -dap $::_DAPNAME -cti $_CTINAME -coreid $_core
        set ::smp_targets "$::smp_targets $_TARGETNAME"
    }
}

setup_a5x a53 $CA53_DBGBASE $CA53_CTIBASE $_num_ca53 1
echo "SMP targets:$smp_targets"
eval "target smp $smp_targets"
targets $_CHIPNAME.a53.0

And output of OpenOCD:

Open On-Chip Debugger 0.11.0+dev-00640-ge83eeb44a (2022-04-21-10:10)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
A113X.cpu
SMP targets: A113X.a53.0 A113X.a53.1 A113X.a53.2 A113X.a53.3
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : J-Link V11 compiled Mar  3 2022 10:16:14
Info : Hardware version: 11.00
Info : VTarget = 3.309 V
Info : clock speed 1000 kHz
Info : JTAG tap: A113X.cpu tap/device found: 0x5ba00477 (mfg: 0x23b (ARM Ltd), part: 0xba00, ver: 0x5)
Info : A113X.a53.0: hardware has 6 breakpoints, 4 watchpoints
Info : A113X.a53.1: hardware has 6 breakpoints, 4 watchpoints
Error: JTAG-DP STICKY ERROR
Warn : target A113X.a53.2 examination failed
Info : A113X.a53.3: hardware has 6 breakpoints, 4 watchpoints
Info : A113X.a53.0 cluster 0 core 0 multi core
Info : A113X.a53.1 cluster 0 core 1 multi core
Info : A113X.a53.3 cluster 0 core 3 multi core
Info : starting gdb server for A113X.a53.0 on 3333
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
Info : New GDB Connection: 1, Target A113X.a53.0, state: halted
Warn : Prefer GDB command "target extended-remote :3333" instead of "target remote :3333"
A113X.a53.1 halted in AArch64 state due to debug-request, current mode: EL1H
cpsr: 0x800001c5 pc: 0xffffff8009853364
MMU: enabled, D-Cache: enabled, I-Cache: enabled
A113X.a53.3 halted in AArch64 state due to debug-request, current mode: EL1H
cpsr: 0x800000c5 pc: 0xffffff80098532b4
MMU: enabled, D-Cache: enabled, I-Cache: enabled

Solution

  • I tried to combine hwthread and targete smp to achieve multi-cores.

    Add "-rtos hwthread" for each core, like

    target create   ......   -rtos hwthread
    

    In my opinion, a core is regarded as a hwthread by OpenOCD, so set hwthread for each core. Following is the response of info threads.

    (gdb) i threads
      Id   Target Id                                           Frame 
    * 1    Thread 1 (Name: riscv.cpu0.0, state: debug-request) 0x8000000a in _mstart ()
      2    Thread 2 (Name: riscv.cpu0.1, state: debug-request) 0x82000000 in ?? ()
      3    Thread 3 (Name: riscv.cpu0.2, state: debug-request) 0x82000000 in ?? ()
      4    Thread 4 (Name: riscv.cpu0.3, state: debug-request) 0x82000000 in ?? ()