# dbstop

## Purpose

Set breakpoints in an M-file function.

## Synopsis

    dbstop at lineno in mfilename
    dbstop in mfilename
    dbstop if error
    dbstop if naninf
    dbstop if infnan

## Description

The `dbstop` command sets up MATLAB's debugging mode. `dbstop` sets a breakpoint at a specified location in an M-file function or causes a break in case an error occurs during execution. When the specified `dbstop` condition is met, the MATLAB prompt is displayed and you can issue any valid MATLAB command.

`dbstop` `at` `lineno` `in` ``mfilename stops execution just prior to execution of that line of the specified M-file function. `dbstop` `in` `mfilename` stops execution before the first executable line in the M-file function when it is called. `dbstop` `if` `error` stops execution if a runtime error occurs in any M-file function. (The debugger does not handle compile-time syntax errors.) You can examine the local workspace and sequence of function calls leading to the error, but you cannot resume M-file execution after a runtime error. `dbstop` `if` `naninf` or `dbstop` `if` `infnan` stops execution when it detects Not-a-Number (`NaN`) or Infinity (`INF`).

Regardless of the form of the `dbstop` command, when a stop occurs, the line or error condition that caused the stop is displayed. To resume M-file function execution, you can issue a `dbcont` command or step to another line in the file with the `dbstep` command.

Any breakpoints set by the first two forms of the `dbstop` command are cleared if the M-file function is edited or cleared.

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

## Examples

Here is a short example, printed with the `dbtype` command to produce line numbers.

    dbtype buggy
    1   function z = buggy(x)
    2   n = length(x);
    3   z = (1:n)./x;

The statement

    dbstop in buggy

causes execution to stop at line 2, the first executable line. The command

    dbstep

then advances to line 3 and allows the value of `n` to be examined.

The example function only works on vectors; it produces an error if the input `x` is a full matrix. So the statements

    dbstop if error
    buggy(magic(3))

produce

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

Finally, if any of the elements of the input `x` are zero, a division by zero occurs. This can be illustrated with

    dbstop if naninf
    buggy(0:2)

which produces

    Warning: Divide by zero
    NaN/Inf debugging breakpoint hit on line 2. Stopping at
    next line.

    2   n = length(x);
    3   z = (1:n)./x;

## See Also

    dbcont, dbdown, dbstack, dbstatus, dbstep, dbtype, dbup

(c) Copyright 1994 by The MathWorks, Inc.