有没有办法在通过 JTAG 连接的远程目标上调用函数?目前,我已将 OpenOCD 连接到一个目标,并附加了 gdb,并且我知道要调用的函数的地址及其签名。
使用普通的二进制文件和 gdb,以下(有点令人惊讶)有效。假设我有一个类似的功能:
static int f(int x) {
printf("The value of x is %d\n", x);
return x*2;
}
我可以在 gdb 下运行该函数,即使是在剥离的二进制文件中,只要我知道它的地址:
cosimo:~ moyix$ gdb -q --args ./hello
Reading symbols from ./hello...(no debugging symbols found)...done.
(gdb) break *0x100000ee0
Breakpoint 1 at 0x100000ee0
(gdb) r
Starting program: /Users/moyix/hello
Breakpoint 1, 0x0000000100000ee0 in _mh_execute_header ()
(gdb) call (0x100000f20)(10)
The value of x is 10
$1 = 20
但是尝试对连接到 OpenOCD 的 gdb 做类似的事情给了我:
moyix@dev:~/git/openocd-code$ arm-none-eabi-gdb -q
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0x8006b06c in ?? ()
(gdb) call (0xC0066E08)(0x10000, 4, 0, 0, 0)
Entry point address is not known.
(gdb)
我从谷歌搜索中收集到,这是因为gdb 想要在某个地方放置它的虚拟堆栈帧,并且由于它没有符号信息,甚至没有二进制文件的入口点,它不知道将它放在哪里。有什么方法可以手动为其虚拟框架指定一个位置(希望它在函数执行后将事情恢复原状......)?