Regression: ARMv8M secure mode debugging non-functional since ~v7.2.0 Description of problem: Prior to qemu commit 4a35855682cebb89f9630b07aa9fd37c4e8c733b, both semihosting printf calls and debugging via gdb work as expected. Builds of qemu containing commit 4a35855682cebb89f9630b07aa9fd37c4e8c733b do not produce any semihosting output and are not debuggable via gdb. Steps to reproduce: 1. Run ``qemu-system-arm -machine mps2-an505 -nographic -semihosting -kernel build/mps2_an505_cm33_blink_demo.elf`` with qemu v7.1.0, note the "blinking" print to the console once a second. 2. Run ``qemu-system-arm -machine mps2-an505 -nographic -semihosting -kernel build/mps2_an505_cm33_blink_demo.elf`` with qemu v7.2.0, note that no messages are printed to the console. 3. Run ``qemu-system-arm -machine mps2-an505 -nographic -semihosting -kernel build/mps2_an505_cm33_blink_demo.elf -S -s`` and 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 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: . Find the GDB manual and other documentation resources online at: . 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 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: . Find the GDB manual and other documentation resources online at: . 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 = dataIndex = (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](/uploads/c86e086b00651a8d5392857b9e4a2c4d/mps2_an505_cm33_blink_demo.elf) [target-arm-Fix-debugging-of-ARMv8M-Secure-code.patch](/uploads/5735d5f7d7b15dbbeb0c2d214a46c1a8/target-arm-Fix-debugging-of-ARMv8M-Secure-code.patch)