Reputation: 1901
I'm taking a course on Computer Organization and Assembly.
In class, we're learning MIPS. This is for the purpose of introducing basic concepts, like pipelining. We're writing a handful of simple MIPS programs for class.
I'm used to gdb for debugging and learning, and the debugger we use in class is SPIM. SPIM sucks. It allows me to step through a program, but it doesn't allow me to interactively execute MIPS instructions at an arbitrary point of execution. I am immediately tired of having to exit SPIM, edit the source, and run SPIM again, navigating to the desired point of execution, only to see I have to do it again because I made yet another mistake.
Or perhaps I am mistaken and SPIM does allow this. My instructor said that this feature is not supported, so I'm going off what he said. I googled around a bit and didn't find a workaround.
I have tried googling for interactive MIPS debuggers like gdb but I haven't found any. I'm aware that gdb can debug MIPS programs, but I don't have a MIPS machine to run MIPS programs on.
I run Ubuntu in VMware. How can I interactively debug MIPS programs, using gdb or otherwise?
Edit: found some reference material on Mips.com on their recommended Linux Toolchain.
Upvotes: 5
Views: 6454
Reputation: 361
You can use qemu
as an emulator, gdb
as a debugger and gcc
as a compiler. It's universal tool-set to investigate different architectures.
For Ubuntu you can install dependencies with followed command (probably, list is not full for your system - it's up to you there):
sudo apt install gdb-multiarch qemu qemu-user gcc-multilib gcc-multilib-mips64-linux-gnuabi64
Now you can use gcc
as a compiler.
$ cat code.c
#include<stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
$ mips64-linux-gnuabi64-gcc code.c -static -g3
And start emulation in qemu
with debug session:
$ qemu-mips64 -g 1234 ./a.out
In gdb-multiarch
use the following routine:
symbol-file a.out
set arch mips:isa64
target remote :1234
b main
c
And here is your goal:
(gdb) x/5i main
0x120003850 <main>: daddiu sp,sp,-32
0x120003854 <main+4>: sd ra,24(sp)
0x120003858 <main+8>: sd s8,16(sp)
0x12000385c <main+12>: sd gp,8(sp)
0x120003860 <main+16>: move s8,sp
I believe, you can adapt it for your tasks. And MIPS
arch is so various, as you can see in gdb
set arch
command.
Upvotes: 4