如何交互式调试MIPS [英] How to Debug MIPS Interactively
问题描述
我正在上一门有关计算机组织和组装的课程.
I'm taking a course on Computer Organization and Assembly.
在课堂上,我们正在学习MIPS.这是为了介绍诸如流水线之类的基本概念.我们正在为课堂编写一些简单的MIPS程序.
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.
我习惯于gdb进行调试和学习,我们在课堂上使用的调试器是SPIM. SPIM很烂.它允许我单步执行程序,但不允许我在任意执行点以交互方式执行MIPS指令.我立即厌倦了不得不退出SPIM,编辑源代码并再次运行SPIM,导航到所需的执行点,却发现我不得不再次执行此操作,因为我犯了另一个错误.
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.
或者也许我弄错了,SPIM确实允许这样做.我的老师说不支持此功能,所以我不接受他说的话.我在Google上搜索了一下,却没有找到解决方法.
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.
我曾尝试使用gdb等交互式MIPS调试器进行谷歌搜索,但没有找到任何工具.我知道gdb可以调试MIPS程序,但是我没有MIPS机器可以在其上运行MIPS程序.
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.
我在VMware中运行Ubuntu.如何使用gdb或其他方式交互式调试MIPS程序?
I run Ubuntu in VMware. How can I interactively debug MIPS programs, using gdb or otherwise?
编辑:在 Mips.com 推荐使用他们的Linux工具链.
Edit: found some reference material on Mips.com on their recommended Linux Toolchain.
推荐答案
您可以将qemu
用作仿真器,将gdb
用作调试器,将gcc
用作编译器.它是研究不同体系结构的通用工具集.
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.
对于Ubuntu,您可以使用以下命令安装依赖项(可能,系统列表不完整-完全由您决定):
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
现在您可以将gcc
用作编译器.
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
并使用调试会话在qemu
中开始仿真:
And start emulation in qemu
with debug session:
$ qemu-mips64 -g 1234 ./a.out
在gdb-multiarch
中,使用以下例程:
symbol-file a.out
set arch mips:isa64
target remote :1234
b main
c
这是您的目标:
(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
我相信,您可以根据自己的任务进行调整.如您在gdb
set arch
命令中所见,MIPS
拱是如此多样.
I believe, you can adapt it for your tasks. And MIPS
arch is so various, as you can see in gdb
set arch
command.
这篇关于如何交互式调试MIPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!