Main Content

dbup

Shift current workspace to workspace of caller in debug mode

Description

dbup changes the current workspace and function context to the workspace and function context of the calling function or script in debug mode. Then you can examine the calling MATLAB® function or script to determine what caused the arguments to be passed to the called function.

Each dbup command changes the workspace and function context to an earlier calling function or script on the stack until the base workspace and function context is reached. You do not need to return to the line at which MATLAB is paused to continue execution or to step to the next line.

example

dbup n changes the current workspace and function context to the workspace and function context of the calling function or script that is n levels higher on the stack. Running dbup n is equivalent to running the dbup command n times.

example

Examples

collapse all

Use the dbup command to view the calling function workspace of a function.

Create a file myfile.m that contains these statements.

function n = myfile(x)
n = myfunc(x-1);

function z = myfunc(y)
z = 2/y;

Set a breakpoint at myfunc and run myfile with an input of 1. MATLAB pauses in the function myfunc, at the line z = 2/y.

dbstop in myfile>myfunc
myfile(1);
5   z = 2/y;

Call whos to view the variables in the current workspace.

whos
  Name      Size            Bytes  Class     Attributes

  y         1x1                 8  double          

The workspace contains the variable y, which is in the workspace context for myfunc.

Run the dbup command to switch to the workspace of the calling function, myfile. Then, call whos.

dbup
whos
In workspace belonging to myfile (line 2)
  Name      Size            Bytes  Class     Attributes

  x         1x1                 8  double  

The workspace contains the variable x, which is in the workspace context for myfile.

Use the dbup command to change the current workspace to the base workspace with one step.

Create a file myfile.m that contains these statements.

function n = myfile(x)
n = myfunc1(x-1);

function m = myfunc1(y)
m = myfunc2(2/y);

function p = myfunc2(z)
p = (z-1)/3;

Set a breakpoint at myfunc2 and run myfile with an input of 1. MATLAB pauses in the function myfunc2, at the line p = (z-1)/3.

dbstop in myfile>myfunc2
myfile(1);
8   p = (z-1)/3;

Call whos to view the variables in the current workspace.

whos
  Name      Size            Bytes  Class     Attributes

  z         1x1                 8  double    

The workspace contains the variable z, which is in the workspace context for myfunc2.

Run the dbup command to switch to the base workspace and then call whos.

dbup 2
whos
In workspace belonging to myfile (line 2)
  Name      Size            Bytes  Class     Attributes

  x         1x1                 8  double              

The workspace contains the variable x, which is in the workspace context for myfile.

Input Arguments

collapse all

Number of levels to move on the call stack, specified as a positive integer scalar.

Tips

  • If you receive an error message such as the following, it means that the parent workspace is under construction so that the value of x is unavailable:

    ??? Reference to a called function result under construction x

Version History

Introduced before R2006a