paulo-fernando-silva / vscOctaveDebugger

MIT License
35 stars 4 forks source link
debugger octave vscode

VS Code Octave Debugger

This extension provides debugging support for Octave code. This is done by interfacing with octave-cli via stdin/stdout. Support for running Matlab code is also done through octave-cli. Make sure octave-cli is in your path environment variable. Note that octave-cli must be installed on your system. You can download it here. If you're using windows or scripts with UI elements such as plots and widgets, using octave-gui is recommended. For more details on plots check this page. You can use

    h = figure();
    plot();
    % ...
    waitfor(h);

to prevent the script from exiting, allowing continuous debugging of plots. Another option is to put while(waitforbuttonpress()==0) pause(1) end at the end of your script. See here for more details.

Do read the changelog to know what's new in this version. This extension has been tested with octave-5.1 and octave-6.1, so everything in between and perhaps more recent versions should also work. If it doesn't, or if a variable is not shown properly, etc, please do let me know over here. Additionally, please check the known issues on this page.

Though the following is not necessary to use this extension, I recommend the Octave extension for syntax highlighting. I prefer it over Matlab. Nicer colors. The following language extension supports code outline for the focused file Octave Hacking. We're still missing is the F12 "jump to definition" code navigation. If someone has time and wants to implement it here's a place to start.

Octave Debugger This extension supports actions:

The following types are currently supported:

If a type isn't supported, request it on the project repository.

Demo

If you want to edit the value of a variable be it scalar, array, or structure, you can double click on it in the VARIABLES view, and type in the new value. That expression will be evaluated and if successful the variable will be updated with the new value. You can also submit any command you like through the debug console as if you were typing directly into Octave.

More information about debugging with Octave can be found here.

Using Octave Debugger

    "type": "OctaveDebugger",
    "request": "launch",
    "name": "Execute selected file.",
    "program": "${file}"

Interactive Mode

In this mode octave will continue to execute beyond the script execution. Therefore, the "program" field can be empty as follows:

    "type": "OctaveDebugger",
    "request": "launch",
    "name": "Interactive Mode",
    "program": "",
    "octave": "octave-cli",
    "autoTerminate": false

Commands can be sent via the DEBUG CONSOLE. To enter this mode set "autoTerminate": false in the launch configuration. Note that octave will terminate only when either the stop □ button is pressed, or when an error occurs after the end of the script. To continue executing even on error, use the octave option "octaveArguments": [ "--interactive" ],. The main point of this mode is that variables will continue to be displayed in the VARIABLES and WATCHES view beyond the end of the script.

Debug Session Configuration Variables

    "type": "OctaveDebugger",
    "request": "launch",
    "name": "My Debug Config - free text",
    "program": "${file}",
    "octave": "/path/to/octave-cli",
    "sourceFolder": "${workspaceFolder}:/usr/local/matlab/code:/opt/local/matlab/more_code",
    "workingDirectory": "${workspaceFolder}"

For example:

    "program": "foo",
    "sourceFolder": "${workspaceFolder}/A/B/C/"

is equivalent to

"program": "${workspaceFolder}/A/B/C/foo.m"

    "program": "foo",
    "sourceFolder": "${workspaceFolder}"
    "workingDirectory": "${workspaceFolder}/A/B/C/"

Environment Variables and Octave Arguments

    "type": "OctaveDebugger",
    "request": "launch",
    "name": "Environment Check",
    "program": "env.m",
    "octave": "octave-cli",
    "octaveEnvironment": { "FOO": "bar", "VAR": "XPTO" },
    "workingDirectory": "${workspaceFolder}"
    printf('FOO: "%s"\n', getenv('FOO'));
    printf('VAR: "%s"\n', getenv('VAR'));
    printf('PATH: "%s"\n', getenv('PATH'));
    "type": "OctaveDebugger",
    "request": "launch",
    "name": "Environment Check",
    "program": "env.m",
    "octave": "export FOO=bar; octave-cli",
    "shell": true,
    "workingDirectory": "${workspaceFolder}"
    "type": "OctaveDebugger",
    "request": "launch",
    "name": "Execute foo in bar",
    "program": "foo.m",
    "octave": "octave-cli",
    "octaveArguments": [ "--path", "bar" ],
    "workingDirectory": "${workspaceFolder}"

Project Homepage

Source available here. Please submit bugs there too.

Known Issues

The following issues will likely not be fixed. For other open issues see here.

History and Acknowledgements

I started this project back in December 2017 or January 2018, not quite sure anymore, when I was going through the exercises from the Andrew Ng's machine learning class, and other ML resources such as Stanford Machine Learning, Caltech Learning from Data, Deep Learning tutorial, and more from MIT and others.

Since vscode is the best editor around, but unfortunately there was no Octave debugger at the time, and since I had a long commute to work, I decided to use that time to develop this plugin. It was an on and off development process, but I would say that about 80% of it was done on the train while commuting to work or flying around the world. I really would like to thank Andrew and all the openclassroom and other similar projects (e.g. OpenCourseWare), and of course the people behind Octave and vscode.