Local variables not always correct when changing depth of call stack in Debugger
Using the debugger, when changing the context to a function that is higher up in the call stack, the local variables defined in that function are accessible via the terminal (e.g. they can be printed). However, when switching context back to a function that is deeper down in the call stack, the local variables are not accessible anymore.
To Reproduce
Let's say function2 defines a variable b, and function1 calls function2:
function function1()
function2();
end
function out = function2()
b = 2;
out = [];
end
- Save this file as
function1.m - Set a breakpoint in line 7 (
out = []). - type
bin the terminal - Click
function1in the call stack, then clickfunction2in the call stack, then typebin the terminal - See error
Unrecognized function or variable 'b'.
Expected behavior
b should be accessible since we changed the context back to function2, where it was defined.
Useful Information
- OS Version: "Red Hat Enterprise Linux" VERSION="8.10 (Ootpa)"
- VS Code Version: 1.96.2
Thanks for reporting this! I can reproduce this issue on my end and this is something we will be fixing in an upcoming release. In the meantime, as a workaround, you can manually run ">> dbup" and ">> dbdown" to change the workspace of the MATLAB Terminal.