Skip to content

Debugger

Neal Beeken edited this page Sep 16, 2019 · 1 revision

dashmips Debugger!

If you haven't checked it out already Visual Studio Code is a really neat open source code editor. When you come to the point in your mips development that you need to debug your programs, there is a vscode extension for you!

Find the extension here or search dashmips in the extension tab in vscode.

Usage

You need to create a folder for your current mips project regardless of the number of files you are working with. Now you'll want to File > Open Folder... to the new folder with your mips files in it.

By the way, vscode requires you to work on folders for projects that use the debugger since the settings for the debugger get put in a folder named .vscode in the current working directory.

Debugging

Follow these steps:

  • Navigate to the debug tab (looks like a bug with an X on it).
  • In the menu box with a play button you will see "No Configurations". Click the menu box and select "Add Configuration..."
  • "Dashmips" should be among the options displayed in a pop up.
    • Two default "debug configurations" will be generated into a file .vscode/launch.json
    • Notice in the first of the configurations the line "program": "${file}", This will run the debugger with the file that is currently in focus. (For example .vscode/launch.json is probably in focus / foreground for you right now) We recommend changing this to your mips file with the main function label in it just to make debugger runnable no matter what file is in focus. (Right click the tab of said mips file and select Copy Relative Path to ensure you have the correct filename).
  • Going back to the debugger tab, you should see "dashmips (Run Current File)" in the menu box (or whatever is in the name property of the configuration)
  • Press play! You should see the dashmips command appear in a terminal built in to the editor appear.
    • The debugger will always stop at the first instruction in your program.
    • Use step and continue buttons (Hover your mouse of the newly appeared buttons panel to see which one is which).
    • Set breakpoints by clicking ahead of the line number.
    • Inspect register and memory values in the variables section.

Troubleshooting

Below are common or known issues, we apologize for potentially inconvenient behavior but hope that at least the debugger is helpful despite minor issues.

"I pressed stop but the program is still running..."

This is a silly error relating to python event loops and we hope to have it fixed soon. Please click on the terminal where the debugger is running and press ctrl-C to exit it.

  • "Do I have an infinite loop in my program?"
    • Workaround: place a breakpoint before your exit syscall and ensure you make it there. Also test with dashmips run.
  • "How can I confirm the exit code of my program after it has actually exited?"
    • Workaround: same as above and check the $a0 register. Also test with dashmips run.

"I see the dashmips debug command pop up but nothing happens..."

This is a bug that has been annoying to reproduce as it happens occasionally on some OSes and not others. Sorry if you are unfortunate to be on such a setup. Luckily, there is a solution!

When you generated the debug configuration, you may have noticed a second configuration that looked something like the one below:

{
  "type": "dashmips",
  "request": "attach",
  "name": "dashmips (Attach)",
  "registerFormat": "dec",
  "host": "localhost",
  "port": 2390
}

Notice the "request": "attach", line, this tells vscode to attach to an already running debugger instance rather than attempting to run one.

  • Open your own terminal (this can be the terminal program from your OS or ctrl+` for vscode's built in one).
  • Run dashmips debug FILE where FILE is the full name of your mips file with the main function label.
  • On the debug tab of vscode select the attach configuration in the menu box.
  • Press Play!
    • You will need to launch your own dashmips debug instance each time you want to debug.