GDB中寄存器偏移1的可能原因有哪些?
What are the possible reasons for registers to be offset by 1 in GDB?
微控制器是一个STM32 F767ZI,其中包含一个32位ARM Cortex M7
给寄存器赋值时,寄存器都显示为偏移1
例如下面的代码:
core.S
.syntax unified
.cpu cortex-m7
.fpu softvfp
.thumb
// Global memory locations
.global vtable
.global reset_handler
.type vtable, %object
vtable:
.word _estack
.word reset_handler
.size vtable, .-vtable
/*
* The Reset handler
*/
.type reset_handler, %function
reset_handler:
// The '_estack' value is defined in the linker script
LDR sp, =_estack
// Dummy values
LDR r5, =0xDEADBEEF
MOV r3, #50
.size reset_handler, .-reset_handler
linkerScripts/stm32-767zi.ld
_estack = 0x20080000;
MEMORY
{
FLASH ( rx ) : ORIGIN = 0x08000000, LENGTH = 2048K
RAM ( rxw ) : ORIGIN = 0x20000000, LENGTH = 512K
}
当被运行编译时:
arm-none-eabi-gcc -x assembler-with-cpp -c -O0 -mcpu=cortex-m7 -mthumb -Wall core.S -o core.o
然后...
arm-none-eabi-gcc core.o -mcpu=cortex-m7 -mthumb -Wall --specs=nosys.specs -nostdlib -lgcc -T./linkerScripts/stm32-767zi.ld -o main.elf
结果:
如您所见,r6
设置为0xdeadbeef
而不是r5
,这是前面代码中写的。此偏移量与设置的其他两个寄存器相同。
我相信链接描述文件的值是正确的,所以我认为问题是其他地方配置不正确造成的。
所以,我有点不确定如何从这里开始,请问是否有人对可能出现的问题有任何想法或建议。
嗯,看到大多数评论表明这可能是 GDB 服务器的问题,我决定试试另一个 GDB 服务器。
结果很喜人:
对于:
core.S
.syntax unified
.cpu cortex-m7
.fpu softvfp
.thumb
// Global memory locations
.global vtable
.global reset_handler
.type vtable, %object
vtable:
.word _estack
.word reset_handler
.size vtable, .-vtable
/*
* The Reset handler
*/
.type reset_handler, %function
reset_handler:
// The '_estack' value is defined in the linker script
LDR sp, =_estack
// Dummy values
LDR r5, =0xDEADBEEF
MOV r3, #50
.size reset_handler, .-reset_handler
这解决了我的问题。
最初,我使用的是 stlink v1.6.1 on Windows, however I switched over to the GDB which comes as part of the STM32CubeIDE。
看来问题确实出在 GDB 服务器上。
感谢大家的帮助和建议,非常感谢。
微控制器是一个STM32 F767ZI,其中包含一个32位ARM Cortex M7
给寄存器赋值时,寄存器都显示为偏移1
例如下面的代码:
core.S
.syntax unified
.cpu cortex-m7
.fpu softvfp
.thumb
// Global memory locations
.global vtable
.global reset_handler
.type vtable, %object
vtable:
.word _estack
.word reset_handler
.size vtable, .-vtable
/*
* The Reset handler
*/
.type reset_handler, %function
reset_handler:
// The '_estack' value is defined in the linker script
LDR sp, =_estack
// Dummy values
LDR r5, =0xDEADBEEF
MOV r3, #50
.size reset_handler, .-reset_handler
linkerScripts/stm32-767zi.ld
_estack = 0x20080000;
MEMORY
{
FLASH ( rx ) : ORIGIN = 0x08000000, LENGTH = 2048K
RAM ( rxw ) : ORIGIN = 0x20000000, LENGTH = 512K
}
当被运行编译时:
arm-none-eabi-gcc -x assembler-with-cpp -c -O0 -mcpu=cortex-m7 -mthumb -Wall core.S -o core.o
然后...
arm-none-eabi-gcc core.o -mcpu=cortex-m7 -mthumb -Wall --specs=nosys.specs -nostdlib -lgcc -T./linkerScripts/stm32-767zi.ld -o main.elf
结果:
如您所见,r6
设置为0xdeadbeef
而不是r5
,这是前面代码中写的。此偏移量与设置的其他两个寄存器相同。
我相信链接描述文件的值是正确的,所以我认为问题是其他地方配置不正确造成的。
所以,我有点不确定如何从这里开始,请问是否有人对可能出现的问题有任何想法或建议。
嗯,看到大多数评论表明这可能是 GDB 服务器的问题,我决定试试另一个 GDB 服务器。
结果很喜人:
对于:
core.S
.syntax unified
.cpu cortex-m7
.fpu softvfp
.thumb
// Global memory locations
.global vtable
.global reset_handler
.type vtable, %object
vtable:
.word _estack
.word reset_handler
.size vtable, .-vtable
/*
* The Reset handler
*/
.type reset_handler, %function
reset_handler:
// The '_estack' value is defined in the linker script
LDR sp, =_estack
// Dummy values
LDR r5, =0xDEADBEEF
MOV r3, #50
.size reset_handler, .-reset_handler
这解决了我的问题。
最初,我使用的是 stlink v1.6.1 on Windows, however I switched over to the GDB which comes as part of the STM32CubeIDE。
看来问题确实出在 GDB 服务器上。
感谢大家的帮助和建议,非常感谢。