我正在尝试在使用 QEMU 模拟的 ARM 机器上运行以下代码。
#include "math.h"
// Newlib doesn't implement this function.
void _exit(int status) {
while (1);
}
int main() {
float a = 1.25;
float b = sinf(a);
return 0;
}
使用的工具链:
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.8.3 20131129 (release) [ARM/embedded-4_8-branch revision 205641]
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
代码编译为:
arm-none-eabi-gcc -g -o math.elf math.c -lm
QEMU 机器启动为:
$ qemu-system-arm -M realview-pbx-a9 -cpu cortex-a9 -kernel math.elf -nographic -serial /dev/null -s -S
GDB 会话如下所示:
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x00008104 in _start ()
(gdb) set $pc = 0x822c
(gdb) break *0x8240
Breakpoint 1 at 0x8240: file math.c, line 10.
(gdb) break *0x824c
Breakpoint 2 at 0x824c: file math.c, line 11.
(gdb) c
Continuing.
Breakpoint 1, main () at math.c:10
10 float b = sinf(a);
(gdb) c
Continuing.
断点 2 设置在最后一行(返回 0)。从 GDB 会话日志中可以看出,永远不会到达第二个断点。计算只是停留在 sinf 函数中。知道为什么吗?
我正在试验直接用 ARM 汇编编写的类似代码,结果是一样的。