Thursday, July 30, 2009

dbstop

Set breakpoints in M-file function

Syntax

  • dbstop in mfile
    dbstop in mfile at lineno
    dbstop in mfile at subfun
    dbstop if error
    dbstop if all error
    dbstop if warning
    dbstop if naninf
    dbstop if infnan

Description

dbstop in mfile temporarily stops execution of mfile when you run it, at the first executable line, putting MATLAB in debug mode. mfile must be in a directory that is on the search path or in the current directory. If you have graphical debugging enabled, the MATLAB Debugger opens with a breakpoint at the first executable line of mfile. You can then use the debugging utilities, review the workspace, or issue any valid MATLAB function. Use dbcont or dbstep to resume execution of mfile. Use dbquit to exit from the Debugger.

dbstop in mfile at lineno temporarily stops execution of mfile when you run it, just prior to execution of the line whose number is lineno, putting MATLAB in debug mode. mfile must be in a directory that is on the search path or in the current directory. If you have graphical debugging enabled, the MATLAB Debugger opens mfile with a breakpoint at line lineno. If that line is not executable, execution stops and the breakpoint is set at the next executable line following lineno. When execution stops, you can use the debugging utilities, review the workspace, or issue any valid MATLAB function. Use dbcont or dbstep to resume execution of mfile. Use dbquit to exit from the Debugger.

dbstop in mfile at subfun temporarily stops execution of mfile when you run it, just prior to execution of the subfunction subfun, putting MATLAB in debug mode. mfile must be in a directory that is on the search path or in the current directory. If you have graphical debugging enabled, the MATLAB Debugger opens mfile with a breakpoint at the subfunction specified by subfun. You can then use the debugging utilities, review the workspace, or issue any valid MATLAB function. Use dbcont or dbstep to resume execution of mfile. Use dbquit to exit from the Debugger.

dbstop if error stops execution when any M-file you subsequently run produces a run-time error, putting MATLAB in debug mode, paused at the line that generated the error. The M-file must be in a directory that is on the search path or in the current directory. The errors that stop execution do not include run-time errors that are detected within a try...catch block. You cannot resume execution after an error. Use dbquit to exit from the Debugger.

dbstop if all error is the same as dbstop if error, except that it stops execution on any type of run-time error, including errors that are detected within a try...catch block.

dbstop if warning stops execution when any M-file you subsequently run produces a run-time warning, putting MATLAB in debug mode, paused at the line that generated the warning. The M-file must be in a directory that is on the search path or in the current directory. Use dbcont or dbstep to resume execution.

dbstop if naninf or dbstop if infnan stops execution when any M-file you subsequently run encounters an infinite value (Inf) or a value that is not a number (NaN), putting MATLAB in debug mode, paused at the line where Inf or NaN was encountered. For convenience, you can use either naninf or infnan--they perform in exactly the same manner. The M-file must be in a directory that is on the search path or in the current directory. Use dbcont or dbstep to resume execution. Use dbquit to exit from the Debugger.

Remarks

The at, in, and if keywords, familiar to users of the UNIX debugger dbx, are optional.

Examples

The file buggy, used in these examples, consists of three lines.

  • function z = buggy(x)
    n = length(x);
    z = (1:n)./x;

Stop at First Executable Line

The statements

  • dbstop in buggy
    buggy(2:5)

stop execution at the first executable line in buggy

  • n = length(x);

The function

  • dbstep

advances to the next line, at which point you can examine the value of n.

Stop if Error

Because buggy only works on vectors, it produces an error if the input x is a full matrix. The statements

  • dbstop if error
    buggy(magic(3))

produce

  • ??? Error using ==> ./
    Matrix dimensions must agree.
    Error in ==> c:\buggy.m
    On line 3 ==> z = (1:n)./x;

and put MATLAB in debug mode.

Stop if InfNaN

In buggy, if any of the elements of the input x is zero, a division by zero occurs. The statements

  • dbstop if naninf
    buggy(0:2)

produce

  • Warning: Divide by zero.
    > In c:\buggy.m at line 3

and put MATLAB in debug mode.

No comments:

Post a Comment