Regression: ARMv8M secure mode debugging non-functional since ~v7.2.0
Host environment
- Operating system: MacOS 12.6.4, Ubuntu 22.04
- OS/kernel version: Darwin 21.6.0 Darwin Kernel Version 21.6.0: Thu Mar 9 20:08:59 PST 2023; root:xnu-8020.240.18.700.8~1/RELEASE_X86_64 x86_64, Linux 5.15.49-linuxkit #1 SMP Tue Sep 13 07:51:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
- Architecture: ARMv8M (Cortex-M23, M33)
- QEMU flavor: qemu-system-arm
- QEMU version: v7.2.0+, All revisions after commit 4a358556
- QEMU command line:
qemu-system-arm -machine mps2-an505 -nographic -semihosting -kernel build/mps2_an505_cm33_blink_demo.elf qemu-system-arm -machine mps2-an505 -nographic -semihosting -kernel build/mps2_an505_cm33_blink_demo.elf -S -s
Emulated/Virtualized environment
- Operating system: Bare-metal / FreeRTOS
- OS/kernel version: FreeRTOS Kernel Revhash: aa987a3443b60894bc64714135bca44831406886
- Architecture: ARMv8M/Cortex-M33 in secure mode
- Demo Project: https://github.com/paulbartell/FreeRTOS/tree/add-generic-arm-mps-project/FreeRTOS/Demo/ARM_MPS
Description of problem
Prior to qemu commit 4a358556, both semihosting printf calls and debugging via gdb work as expected.
Builds of qemu containing commit 4a358556 do not produce any semihosting output and are not debuggable via gdb.
Steps to reproduce
- Run
qemu-system-arm -machine mps2-an505 -nographic -semihosting -kernel build/mps2_an505_cm33_blink_demo.elfwith qemu v7.1.0, note the "blinking" print to the console once a second. - Run
qemu-system-arm -machine mps2-an505 -nographic -semihosting -kernel build/mps2_an505_cm33_blink_demo.elfwith qemu v7.2.0, note that no messages are printed to the console. - Run
qemu-system-arm -machine mps2-an505 -nographic -semihosting -kernel build/mps2_an505_cm33_blink_demo.elf -S -sand attach gdb with the following gdbinit file.
Additional information
Log of successful gdb session with the attached patch on top of qemu master branch:
% arm-none-eabi-gdb build/mps2_an505_cm33_blink_demo.elf
GNU gdb (Arm GNU Toolchain 12.2.MPACBTI-Rel1 (Build arm-12-mpacbti.34)) 13.1.90.20230307-git
Copyright (C) 2023 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-apple-darwin19.6.0 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.linaro.org/>.
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 build/mps2_an505_cm33_blink_demo.elf...
The target architecture is set to "armv8-m.main".
Reset_Handler () at /FreeRTOS/FreeRTOS/Demo/ARM_MPS/startup.c:172
172 {
Section .privileged_functions, range 0x10000000 -- 0x10008000: matched.
Section .text, range 0x10008000 -- 0x10019c18: matched.
Section .rodata, range 0x10019c18 -- 0x1001b270: matched.
Section .ARM.exidx, range 0x1001b270 -- 0x1001b278: matched.
Section .copy.table, range 0x1001b278 -- 0x1001b284: matched.
Section .data, range 0x1001b28c -- 0x1001bb90: matched.
Section .ram_vectors, range 0x1001bb90 -- 0x1001bdd0: matched.
Section .zero.table, range 0x1001b284 -- 0x1001b28c: matched.
Breakpoint 1 at 0x10009900: file /FreeRTOS/Demo/ARM_MPS/fault_handlers.c, line 494.
(gdb) s
174 asm volatile
(gdb) s
189 init_data_sections();
(gdb) s
init_data_sections () at /FreeRTOS/FreeRTOS/Demo/ARM_MPS/startup.c:99
99 for( pCopyTable = &__copy_table_start__; pCopyTable <= &__copy_table_end__; pCopyTable++ )
(gdb) s
101 for( dataIndex = 0; dataIndex < pCopyTable->uxLen; dataIndex++ )
(gdb) info locals
pCopyTable = 0x1001b278
dataIndex = 0
(gdb) print /x *0xE000ED08
$1 = 0x10000000
Log of an unsuccessful gdb session with qemu v7.2.0
pbartell@147dda7342a9 ARM_MPS % arm-none-eabi-gdb build/mps2_an505_cm33_blink_demo.elf
GNU gdb (Arm GNU Toolchain 12.2.MPACBTI-Rel1 (Build arm-12-mpacbti.34)) 13.1.90.20230307-git
Copyright (C) 2023 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-apple-darwin19.6.0 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.linaro.org/>.
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 build/mps2_an505_cm33_blink_demo.elf...
The target architecture is set to "armv8-m.main".
Reset_Handler () at /FreeRTOS/FreeRTOS/Demo/ARM_MPS/startup.c:172
172 {
Section .privileged_functions, range 0x10000000 -- 0x10008000: MIS-MATCHED!
Section .text, range 0x10008000 -- 0x10019c18: MIS-MATCHED!
Section .rodata, range 0x10019c18 -- 0x1001b270: MIS-MATCHED!
Section .ARM.exidx, range 0x1001b270 -- 0x1001b278: MIS-MATCHED!
Section .copy.table, range 0x1001b278 -- 0x1001b284: MIS-MATCHED!
Section .data, range 0x1001b28c -- 0x1001bb90: MIS-MATCHED!
Section .ram_vectors, range 0x1001bb90 -- 0x1001bdd0: MIS-MATCHED!
Section .zero.table, range 0x1001b284 -- 0x1001b28c: MIS-MATCHED!
warning: One or more sections of the target image does not match
the loaded file
Breakpoint 1 at 0x10009900: file /FreeRTOS/FreeRTOS/Demo/ARM_MPS/fault_handlers.c, line 494.
(gdb) s
Reset_Handler () at /FreeRTOS/FreeRTOS/Demo/ARM_MPS/startup.c:174
174 asm volatile
(gdb) s
Reset_Handler () at /FreeRTOS/FreeRTOS/Demo/ARM_MPS/startup.c:189
189 init_data_sections();
(gdb) s
init_data_sections () at /FreeRTOS/FreeRTOS/Demo/ARM_MPS/startup.c:95
95 {
(gdb) s
init_data_sections () at /FreeRTOS/FreeRTOS/Demo/ARM_MPS/startup.c:99
99 for( pCopyTable = &__copy_table_start__; pCopyTable <= &__copy_table_end__; pCopyTable++ )
(gdb) info locals
pCopyTable = <error reading variable pCopyTable (Cannot access memory at address 0x381fffdc)>
dataIndex = <error reading variable dataIndex (Cannot access memory at address 0x381fffd8)>
(gdb) print /x *0xE000ED08
$1 = 0x0
(gdb) quit
.gdbinit file:
set architecture armv8-m.main
target extended-remote :1234
compare-sections
break HardFault_Handler
mps2_an505_cm33_blink_demo.elf target-arm-Fix-debugging-of-ARMv8M-Secure-code.patch
Edited by Paul Bartell