Main Content

dbup

在调试模式下,从当前工作区切换到调用方的工作区

说明

示例

在调试模式下,dbup 将当前工作区和函数上下文更改为调用函数或脚本的工作区和函数上下文。然后您可以检查执行调用的 MATLAB® 函数或脚本,以确定是什么导致参数被传递给被调用的函数。

每个 dbup 命令都会将工作区和函数上下文更改为堆栈上较早的调用函数或脚本,直到达到基础工作区和函数上下文为止。要继续执行或步进到下一行,并不需要返回到 MATLAB 暂停时所在的行。

示例

dbup n 将当前工作区和函数上下文更改为在堆栈中高 n 个级别的调用方函数或脚本的工作区和函数上下文。运行 dbup n 等效于运行 dbup 命令 n 次。

示例

全部折叠

使用 dbup 命令查看函数的调用方函数工作区。

创建文件 myfile.m,其中包含以下语句。

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

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

myfunc 处设置一个断点,并通过输入 1 来运行 myfile。MATLAB 将在运行函数 myfunc 时在第 z = 2/y 行暂停。

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

调用 whos 以查看当前工作区中的变量。

whos
  Name      Size            Bytes  Class     Attributes

  y         1x1                 8  double          

工作区包含变量 y,它位于 myfunc 的工作区上下文中。

运行 dbup 命令,以切换到调用函数 myfile 的工作区。然后调用 whos

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

  x         1x1                 8  double  

工作区包含变量 x,它位于 myfile 的工作区上下文中。

使用 dbup 命令只需一步即可将当前工作区更改为基础工作区。

创建文件 myfile.m,其中包含以下语句。

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

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

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

myfunc2 处设置一个断点,并通过输入 1 来运行 myfile。MATLAB 将在运行函数 myfunc2 时在第 p = (z-1)/3 行暂停。

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

调用 whos 以查看当前工作区中的变量。

whos
  Name      Size            Bytes  Class     Attributes

  z         1x1                 8  double    

工作区包含变量 z,它位于 myfunc2 的工作区上下文中。

运行 dbup 命令切换到基础工作区,然后调用 whos

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

  x         1x1                 8  double              

工作区包含变量 x,它位于 myfile 的工作区上下文中。

输入参数

全部折叠

要在调用堆栈上移动的级别数,指定为正整数标量。

提示

  • 如果您收到类似下面的错误消息,这表示父工作区正在构建中,因此 x 值不可用:

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

版本历史记录

在 R2006a 之前推出

另请参阅

| |