Topics

GDB thread listing on NUCLEO-F091RC

evan.gates@...
 

I'm runing Zephyr 1.10 on a NUCLEO-F091RC. It's a Cotex-M0. I want to
be able to debug it with GDB. I've included snipits of command output
inline with more verbose output at the end of the message.

I'm using the zephyr branch of openocd
found here: https://github.com/zephyrproject-rtos/openocd/tree/zephyr

It contains this commit adding zephyr support:
https://github.com/zephyrproject-rtos/openocd/commit/7852ae77b12118dbf902d85ab826ed0261c144ad

I've added a change in rtos/Zephyr.c so it can recognize my board.

diff --git a/src/rtos/Zephyr.c b/src/rtos/Zephyr.c
index 6fa0ffb..e60d3b5 100644
--- a/src/rtos/Zephyr.c
+++ b/src/rtos/Zephyr.c
@@ -66,6 +66,11 @@ static struct Zephyr_params Zephyr_params_list[] = {
.reg_stacking = &rtos_standard_Cortex_M4F_FPU_stacking,
},
{
+ .target_name = "hla_target",
+ .pointer_width = 4,
+ .reg_stacking = &rtos_standard_Cortex_M3_stacking,
+ },
+ {
.target_name = NULL
}
};

I chose the M3 stacking as it looks to me like it's closest to M0. I
can't tell if I have to make any other changes. Particularly, the size
and number of core regs looks right, but I have no idea where the initial
offset of 0x20 comes from in rtos_standard_Cortex_M3_stack_offsets.

I did find a note in src/target/cortex_m.c saying:

NOTE: most of this should work fine for the Cortex-M1 and
Cortex-M0 cores too, although they're ARMv6-M not ARMv7-M.

Which makes me think this may be alright.

I'm using the zephyr-sdk tcl files for openocd, specifically
interface/stlink-v2-1.cfg and target/stm32f09x.cfg. I
added -rtos auto to the end of the $_TARGETNAME configure
-work-area-phys line of target/stm32f09x.cfg as mentioned here:
https://github.com/zephyrproject-rtos/zephyr/issues/2933

Now gdb recognizes threads, but it seems like some things aren't working
correctly. Threads look like they have the right stack pointer but many
have program counter 0:

sp 0x200019f0 0x200019f0 <adc_stack+224>
pc 0x0 0x0

Some have program counter 0x08012718. If I'm reading the objdump output
correctly, it looks like it's the last word in the rodata section:

objdump -h zephyr.elf
Idx Name Size VMA LMA File off Algn
...
3 rodata 00001ed8 08010844 08010844 000088f8 2**2
...

08010844 + 00001ed8 = 0801271c

Backtraces often end with:
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Questions:
- Does this look wrong to you, too?
- Do I have to make other changes for Cortex-M0?
- Can you tell what's going on with the pc?
- Is there any other information I can provide that would be helpful?

I'd greatly appreciate any help/hints/guesses/pointers to other docs, etc.

Thanks,
Evan





Full output listings

objdump -h zephyr.elf:

zephyr.elf: file format elf32-littlearm

Sections:
Idx Name Size VMA LMA File off Algn
0 text 00008762 08008000 08008000 000000b4 2**2
CONTENTS, ALLOC, LOAD, CODE
1 .ARM.exidx 00000008 08010764 08010764 00008818 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 devconfig 000000d8 0801076c 0801076c 00008820 2**2
CONTENTS, ALLOC, LOAD, DATA
3 rodata 00001ed8 08010844 08010844 000088f8 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .st_stm32f0x_vt 000003e8 20000000 20000000 0000bb70 2**0
ALLOC
5 bss 00001528 200003e8 200003e8 0000bb70 2**3
ALLOC
6 noinit 00001700 20001910 20001910 0000bb70 2**3
ALLOC
7 datas 000011d0 20003010 0801271c 0000a7d0 2**2
CONTENTS, ALLOC, LOAD, DATA
8 initlevel 000000d8 200041e0 080138ec 0000b9a0 2**2
CONTENTS, ALLOC, LOAD, DATA
9 _k_timer_area 000000d0 200042b8 080139c4 0000ba78 2**2
CONTENTS, ALLOC, LOAD, DATA
10 _k_mutex_area 00000028 20004388 08013a94 0000bb48 2**2
CONTENTS, ALLOC, LOAD, DATA
11 .debug_info 00040fcb 00000000 00000000 0000bb70 2**0
CONTENTS, READONLY, DEBUGGING
12 .debug_abbrev 0000b71b 00000000 00000000 0004cb3b 2**0
CONTENTS, READONLY, DEBUGGING
13 .debug_aranges 00001560 00000000 00000000 00058258 2**3
CONTENTS, READONLY, DEBUGGING
14 .debug_line 00011973 00000000 00000000 000597b8 2**0
CONTENTS, READONLY, DEBUGGING
15 .debug_str 00009c35 00000000 00000000 0006b12b 2**0
CONTENTS, READONLY, DEBUGGING
16 .comment 00000011 00000000 00000000 00074d60 2**0
CONTENTS, READONLY
17 .ARM.attributes 0000002f 00000000 00000000 00074d71 2**0
CONTENTS, READONLY
18 .debug_loc 00015509 00000000 00000000 00074da0 2**0
CONTENTS, READONLY, DEBUGGING
19 .debug_ranges 00001df8 00000000 00000000 0008a2b0 2**3
CONTENTS, READONLY, DEBUGGING
20 .debug_frame 00002cf0 00000000 00000000 0008c0a8 2**2
CONTENTS, READONLY, DEBUGGING

openocd command:
/usr/local/bin/openocd -s $(PROJECT_DIR)/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/share/openocd/scripts/ \
-f $(PROJECT_DIR)/stm32f0.cfg -c 'gdb_port 3333' -c init -c targets -c halt

gdb command:
PATH=$(PROJECT_DIR)/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/arm-zephyr-eabi:$(PATH) \
arm-zephyr-eabi-gdb --eval-command="target remote :3333" \
$(BUILD_DIR_BASE)/fw/zephyr/zephyr.elf

openocd output:
Open On-Chip Debugger 0.10.0-g7852ae7-dirty (2018-06-20-14:35)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v28 API v2 SWIM v17 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.255336
Info : stm32f0x.cpu: hardware has 4 breakpoints, 2 watchpoints
TargetName Type Endian TapName State
-- ------------------ ---------- ------ ------------------ ------------
0* stm32f0x.cpu hla_target little stm32f0x.cpu running
target halted due to debug-request, current mode: Thread
xPSR: 0x21000000 pc: 0x0800ccf8 psp: 0x200027f8
Info : accepting 'gdb' connection on tcp/3333
Debugger attaching: halting execution
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
adapter speed: 950 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0xc1000000 pc: 0x080028ec msp: 0x20004ec8
force hard breakpoints
Info : device id = 0x10006442
Info : flash size = 256kbytes
Info : Zephyr: does it have symbol 0 (mandatory)?
Info : Zephyr: does it have symbol 1 (mandatory)?
Info : Zephyr: does it have symbol 2 (mandatory)?
Info : Zephyr: all mandatory symbols found
Info : Auto-detected RTOS: Zephyr
Info : Zephyr: looking for target: hla_target
Info : Zephyr: target known, params at 0x83f460

gdb commands:
info threads
thread apply all bt
thread apply all info reg

gdb output:
GNU gdb (GDB) 7.11.0.20160511-git
Copyright (C) 2016 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 "--host=x86_64-pokysdk-linux --target=arm-zephyr-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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 /home/emg/gnar/gbxv2-mcu/build/nucleo_f091rc/fw/zephyr/zephyr.elf...done.
Remote debugging using :3333
0x080028ec in ?? ()
(gdb) c
Continuing.
^C[New Thread 536871912]
[New Thread 536872188]
[New Thread 536874900]
[New Thread 536872312]
[New Thread 536872024]
[New Thread 536875012]
[New Thread 536872572]
[New Thread 536876624]
[New Thread 536876728]

Thread 1 received signal SIGINT, Interrupt.
[Switching to Thread 536873704]
OLED_WEO012864L_ClearPixel (Xpos=Xpos@entry=55, Ypos=Ypos@entry=27) at /home/emg/gnar/gbxv2-mcu/fw/src/oled_weo012864l.c:889
889 OLED_WEO012864L_DrawPixel(Xpos, Ypos, BackColor);
(gdb) info threads
Id Target Id Frame
* 1 Thread 536873704 (Name: thr_20002070_20000ae8, prio:-13,useropts:0) OLED_WEO012864L_ClearPixel (Xpos=Xpos@entry=55, Ypos=Ypos@entry=27)
at /home/emg/gnar/gbxv2-mcu/fw/src/oled_weo012864l.c:889
2 Thread 536871912 (Name: thr_200019f0_200003e8, prio:-12,useropts:0) 0x00000000 in ?? ()
3 Thread 536872188 (Name: thr_20001c70_200004fc, prio:-12,useropts:0) 0x03000000 in ?? ()
4 Thread 536874900 (Name: thr_20002170_20000f94, prio:-12,useropts:0) 0x00000000 in ?? ()
5 Thread 536872312 (Name: thr_20001d70_20000578, prio:-12,useropts:0) 0x08012718 in ?? ()
6 Thread 536872024 (Name: thr_20001af0_20000458, prio:-12,useropts:0) 0x08012718 in ?? ()
7 Thread 536875012 (Name: thr_200022f0_20001004, prio:-12,useropts:0) 0x08012718 in ?? ()
8 Thread 536872572 (Name: thr_20001ef0_2000067c, prio:-12,useropts:0) 0x00000000 in ?? ()
9 Thread 536876624 (Name: thr_200027f0_20001650, prio:15,useropts:1) 0x0f8a158a in ?? ()
10 Thread 536876728 (Name: thr_200026f0_200016b8, prio:0,useropts:1) 0x20004e94 in ?? ()
(gdb) thread apply all bt

Thread 10 (Thread 536876728):
#0 0x20004e94 in ?? ()
#1 0x08012718 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 9 (Thread 536876624):
#0 0x0f8a158a in ?? ()
#1 0x0800f960 in _thread_entry (entry=0x1, p1=<optimized out>, p2=<optimized out>, p3=<optimized out>) at /home/emg/gnar/gbxv2-mcu/zephyr/kernel/thread.c:194
#2 0x94c3f7dc in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 8 (Thread 536872572):
#0 0x00000000 in ?? ()
#1 0x0800f960 in _thread_entry (entry=0x0, p1=<optimized out>, p2=<optimized out>, p3=<optimized out>) at /home/emg/gnar/gbxv2-mcu/zephyr/kernel/thread.c:194
#2 0x00000000 in ?? ()

Thread 7 (Thread 536875012):
#0 0x08012718 in ?? ()
#1 0x0800bf12 in k_sleep (duration=100) at /home/emg/gnar/gbxv2-mcu/build/nucleo_f091rc/fw/zephyr/include/generated/syscalls/kernel.h:19
#2 gbxv2_system_thread_entry () at /home/emg/gnar/gbxv2-mcu/fw/src/system.c:56
#3 0x00000000 in ?? ()

Thread 6 (Thread 536872024):
#0 0x08012718 in ?? ()
#1 0x08008ba6 in k_sleep (duration=1000) at /home/emg/gnar/gbxv2-mcu/build/nucleo_f091rc/fw/zephyr/include/generated/syscalls/kernel.h:19
#2 gbxv2_battery_thread_entry () at /home/emg/gnar/gbxv2-mcu/fw/src/battery.c:112
#3 0x00000000 in ?? ()

Thread 5 (Thread 536872312):
#0 0x08012718 in ?? ()
#1 0x080094d6 in k_sleep (duration=1000) at /home/emg/gnar/gbxv2-mcu/build/nucleo_f091rc/fw/zephyr/include/generated/syscalls/kernel.h:19
#2 gbxv2_charger_thread_entry () at /home/emg/gnar/gbxv2-mcu/fw/src/charger.c:190
#3 0x00000000 in ?? ()

Thread 4 (Thread 536874900):
#0 0x00000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 3 (Thread 536872188):
#0 0x03000000 in ?? ()
#1 0x00000000 in ?? ()

Thread 2 (Thread 536871912):
#0 0x00000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 1 (Thread 536873704):
#0 OLED_WEO012864L_ClearPixel (Xpos=Xpos@entry=55, Ypos=Ypos@entry=27) at /home/emg/gnar/gbxv2-mcu/fw/src/oled_weo012864l.c:889
#1 0x0800ae82 in OLED_WEO012864L_DrawSprite (Xpos=<optimized out>, Ypos=<optimized out>, sprite=sprite@entry=0x200036ac <GnarboxLogo>)
at /home/emg/gnar/gbxv2-mcu/fw/src/oled_weo012864l.c:317
#2 0x0800a5e6 in gbxv2_oled_thread_entry () at /home/emg/gnar/gbxv2-mcu/fw/src/oled.c:197
#3 0x0800f960 in _thread_entry (entry=0x800a531 <gbxv2_oled_thread_entry>, p1=<optimized out>, p2=<optimized out>, p3=<optimized out>)
at /home/emg/gnar/gbxv2-mcu/zephyr/kernel/thread.c:194
#4 0x00000800 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) thread apply all info reg

Thread 10 (Thread 536876728):
r0 0x800ec19 134278169
r1 0x800a395 134259605
r2 0x8012718 134293272
r3 0x8011674 134289012
r4 0x0 0
r5 0xe000ed04 -536810236
r6 0x200016b8 536876728
r7 0x10000000 268435456
r8 0x0 0
r9 0x800f689 134280841
r10 0x800cb60 134269792
r11 0x61000000 1627389952
r12 0x30 48
sp 0x20002700 0x20002700 <_main_stack+1008>
lr 0x8012718 134293272
pc 0x20004e94 0x20004e94
xPSR 0x800ec37 134278199

Thread 9 (Thread 536876624):
r0 0x8010735 134285109
r1 0x8010745 134285125
r2 0x8010735 134285109
r3 0x800f961 134281569
r4 0x1 1
r5 0x0 0
r6 0x20000af8 536873720
r7 0x2000172c 536876844
r8 0x8010735 134285109
r9 0x8010733 134285107
r10 0x800ccf8 134270200
r11 0x21000000 553648128
r12 0x0 0
sp 0x2000281c 0x2000281c <_interrupt_stack+12>
lr 0x800f961 134281569
pc 0xf8a158a 0xf8a158a
xPSR 0xaa9a76c5 -1432717627

Thread 8 (Thread 536872572):
r0 0x0 0
r1 0x8009caf 134257839
r2 0x8009c85 134257797
r3 0x0 0
r4 0x0 0
r5 0xe000ed04 -536810236
r6 0x2000067c 536872572
r7 0x10000000 268435456
r8 0x0 0
r9 0x800f689 134280841
r10 0x800cb60 134269792
r11 0x61000000 1627389952
r12 0x0 0
sp 0x20001f10 0x20001f10 <oled_stack>
lr 0x800f961 134281569
pc 0x0 0x0
xPSR 0x0 0

Thread 7 (Thread 536875012):
r0 0x0 0
r1 0xb 11
r2 0x1 1
r3 0x0 0
r4 0x0 0
r5 0xe000ed04 -536810236
r6 0x20001004 536875012
r7 0x10000000 268435456
r8 0x0 0
r9 0x800f4f9 134280441
r10 0x800cb60 134269792
r11 0x61000000 1627389952
r12 0x1 1
sp 0x200022d8 0x200022d8 <system_stack+328>
lr 0x800bf13 134266643
pc 0x8012718 0x8012718
xPSR 0x8011d84 134290820

Thread 6 (Thread 536872024):
r0 0x20001004 536875012
r1 0x65 101
r2 0x200004c4 536872132
r3 0x0 0
r4 0x0 0
r5 0xe000ed04 -536810236
r6 0x20000458 536872024
r7 0x10000000 268435456
r8 0xb9c 2972
r9 0x800f4f9 134280441
r10 0x800cb60 134269792
r11 0x41000000 1090519040
r12 0x0 0
sp 0x20001af4 0x20001af4 <battery_stack+228>
lr 0x8008ba7 134253479
pc 0x8012718 0x8012718
xPSR 0x8012718 134293272

Thread 5 (Thread 536872312):
r0 0x0 0
r1 0x65 101
r2 0x2280 8832
r3 0x200005e4 536872420
r4 0x0 0
r5 0xe000ed04 -536810236
r6 0x20000578 536872312
r7 0x10000000 268435456
r8 0x0 0
r9 0x800f4f9 134280441
r10 0x800cb60 134269792
r11 0x61000000 1627389952
r12 0xa000 40960
sp 0x20001d70 0x20001d70 <charger_stack+224>
lr 0x80094d7 134255831
pc 0x8012718 0x8012718
xPSR 0x8010c34 134286388

Thread 4 (Thread 536874900):
r0 0x200018c8 536877256
r1 0x800b8f9 134265081
r2 0x0 0
r3 0x0 0
r4 0x0 0
r5 0xe000ed04 -536810236
r6 0x20000f94 536874900
r7 0x10000000 268435456
r8 0x0 0
r9 0x800f689 134280841
r10 0x800cb60 134269792
r11 0x61000000 1627389952
r12 0x800b8c9 134265033
sp 0x20002180 0x20002180 <rgb_led_stack+240>
lr 0x0 0
pc 0x0 0x0
xPSR 0x800b8c9 134265033

Thread 3 (Thread 536872188):
r0 0x20001c7c 536878204
r1 0x8009065 134254693
r2 0x1 1
r3 0x800 2048
r4 0x0 0
r5 0xe000ed04 -536810236
r6 0x200004fc 536872188
r7 0x10000000 268435456
r8 0x2000 8192
r9 0x800f689 134280841
r10 0x800cb60 134269792
r11 0x61000000 1627389952
r12 0x8009011 134254609
sp 0x20001c80 0x20001c80 <usb_otg_stack+368>
lr 0x0 0
pc 0x3000000 0x3000000
xPSR 0x60002 393218

Thread 2 (Thread 536871912):
r0 0x80088c1 134252737
r1 0x80088cf 134252751
r2 0x0 0
r3 0x0 0
r4 0x0 0
r5 0xe000ed04 -536810236
r6 0x200003e8 536871912
r7 0x10000000 268435456
r8 0x0 0
r9 0x800f689 134280841
r10 0x800cb60 134269792
r11 0x61000000 1627389952
r12 0x0 0
sp 0x200019f0 0x200019f0 <adc_stack+224>
lr 0x0 0
pc 0x0 0x0
xPSR 0x0 0

Thread 1 (Thread 536873704):
r0 0x37 55
r1 0x1b 27
r2 0x0 0
r3 0x1a 26
r4 0x1f 31
r5 0x1 1
r6 0x200036ac 536884908
r7 0x18 24
r8 0x1a 26
r9 0x0 0
r10 0x0 0
r11 0x0 0
r12 0x20002050 536879184
sp 0x20002028 0x20002028 <oled_stack+280>
lr 0x800ae83 134262403
pc 0x800ac46 0x800ac46 <OLED_WEO012864L_ClearPixel+2>
xPSR 0x1000000 16777216
(gdb)

evan.gates@...
 

evan.gates@... wrote:

I'm using the zephyr branch of openocd
found here: https://github.com/zephyrproject-rtos/openocd/tree/zephyr
I also just tried cherry picking that commit on openocd's upstream master
branch. The results are the same.