Next: Debug Mode, Previous: Entering Debug Mode, Up: Debugging

### 14.2 Breakpoints

Breakpoints can be set in any Octave function, using the `dbstop` function.

— Loadable Function: rline = dbstop (func, line, ...)

> Set a breakpoint in a function

> `func`
>   String representing the function name. When already in debug mode this should be left out and only the line should be given.
> `line`
>   Line you would like the breakpoint to be set on. Multiple lines might be given as seperate arguments or as a vector.

> The rline returned is the real line that the breakpoint was set at.

> See also: dbclear, dbstatus, dbnext.

Note that breakpoints can not be set in built-in functions (eg. `sin`, etc) or dynamically loaded function (ie. oct-files). To set a breakpoint immediately on entering a function, the breakpoint should be set to line 1. The leading comment block will be ignored and the breakpoint will be set to the first executable statement in the function. For example

         dbstop ("asind", 1)
         => 27

Note that the return value of `27` means that the breakpoint was effectively set to line 27. The status of breakpoints in a function can be queried with the `dbstatus` function.

— Loadable Function: lst = dbstatus ([func])

> Return a vector containing the lines on which a function has breakpoints set.

> `func`
>   String representing the function name. When already in debug mode this should be left out.

> See also: dbclear, dbwhere.

Taking the above as an example, `dbstatus ("asind")` should return 27. The breakpoints can then be cleared with the `dbclear` function

— Loadable Function: dbclear (func, line, ...)

> Delete a breakpoint in a function

> `func`
>   String representing the function name. When already in debug mode this should be left out and only the line should be given.
> `line`
>   Line where you would like to remove the breakpoint. Multiple lines might be given as seperate arguments or as a vector.
> No checking is done to make sure that the line you requested is really a breakpoint. If you get the wrong line nothing will happen.

> See also: dbstop, dbstatus, dbwhere.

To clear all of the breakpoints in a function the recommended means, following the above example, is then

         dbclear ("asind", dbstatus ("asind"));

Another simple means of setting a breakpoint in an Octave script is the use of the `keyboard` function.

— Built-in Function: keyboard (prompt)

> This function is normally used for simple debugging. When the `keyboard` function is executed, Octave prints a prompt and waits for user input. The input strings are then evaluated and the results are printed. This makes it possible to examine the values of variables within a function, and to assign new values to variables. No value is returned from the `keyboard` function, and it continues to prompt for input until the user types ``quit`', or ``exit`'.

> If `keyboard` is invoked without any arguments, a default prompt of ``debug>` ' is used.

The `keyboard` function is typically placed in a script at the point where the user desires that the execution is stopped. It automatically sets the running script into the debug mode.