MATLAB-extension-for-vscode icon indicating copy to clipboard operation
MATLAB-extension-for-vscode copied to clipboard

Local variables not always correct when changing depth of call stack in Debugger

Open robertoffmoura opened this issue 1 year ago • 1 comments

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
  1. Save this file as function1.m
  2. Set a breakpoint in line 7 (out = []).
  3. type b in the terminal
  4. Click function1 in the call stack, then click function2 in the call stack, then type b in the terminal
  5. 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

robertoffmoura avatar Feb 27 '25 17:02 robertoffmoura

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.

philipb314 avatar Mar 12 '25 17:03 philipb314