您没有说您使用什么操作系统。
对于这个例子,我假设您有 Linux 并且想要编写简单的独立 sparc 代码(用于教育目的)。
你会需要binutils
and gdb
为 sparc 编译和qemu-sparc
。
将这个小示例代码保存为test.s
:
.globl _start
_start:
mov %o0, %g0
1:
inc %o0
cmp %o0, 100
bl 1b
nop
b .
nop
Use as
组装和ld
进行链接,如下:
$ sparc-linux-as -g -o test.o test.s
$ sparc-linux-ld -g -o test test.o
应该生成二进制文件test
:
$ file test
test: ELF 32-bit MSB executable, SPARC, version 1 (SYSV), statically linked, not stripped
现在开始qemu-sparc
设置为gdb
远程调试(选择你选择的端口,我用的是1234):
$ qemu-sparc -g 1234 test
它会等待gdb
连接。在另一个终端中,启动gdb
对于二进制文件:
$ sparc-linux-gdb test
GNU gdb (GDB) 7.3.50.20111117-cvs-debian
Copyright (C) 2011 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-unknown-linux-gnu --target=sparc-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /var/tmp/test...done.
(gdb)
附加到qemu
实例:
(gdb) target remote :1234
Remote debugging using :1234
_start () at test.s:3
3 mov %o0, %g0
从这里开始,您可以使用gdb
像往常一样执行代码,检查寄存器和内存。