<html lang="en"> <head> <title>Breakpoints - Untitled</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="Untitled"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Debugging.html#Debugging" title="Debugging"> <link rel="prev" href="Leaving-Debug-Mode.html#Leaving-Debug-Mode" title="Leaving Debug Mode"> <link rel="next" href="Debug-Mode.html#Debug-Mode" title="Debug Mode"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Breakpoints"></a> <p> Next: <a rel="next" accesskey="n" href="Debug-Mode.html#Debug-Mode">Debug Mode</a>, Previous: <a rel="previous" accesskey="p" href="Leaving-Debug-Mode.html#Leaving-Debug-Mode">Leaving Debug Mode</a>, Up: <a rel="up" accesskey="u" href="Debugging.html#Debugging">Debugging</a> <hr> </div> <h3 class="section">13.3 Breakpoints</h3> <p>Breakpoints can be set in any Octave function, using the <code>dbstop</code> function. <!-- debug.cc --> <p><a name="doc_002ddbstop"></a> <div class="defun"> — Loadable Function: <var>rline</var> = <b>dbstop</b> (<var>func, line, <small class="dots">...</small></var>)<var><a name="index-dbstop-693"></a></var><br> <blockquote><p>Set a breakpoint in a function <dl> <dt><code>func</code><dd>String representing the function name. When already in debug mode this should be left out and only the line should be given. <br><dt><code>line</code><dd>Line number you would like the breakpoint to be set on. Multiple lines might be given as separate arguments or as a vector. </dl> <p>The rline returned is the real line that the breakpoint was set at. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002ddbclear.html#doc_002ddbclear">dbclear</a>, <a href="doc_002ddbstatus.html#doc_002ddbstatus">dbstatus</a>, <a href="doc_002ddbstep.html#doc_002ddbstep">dbstep</a>. </p></blockquote></div> <p class="noindent">Note that breakpoints cannot be set in built-in functions (e.g., <code>sin</code>, etc.) or dynamically loaded function (i.e., 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 <pre class="example"> dbstop ("asind", 1) ⇒ 27 </pre> <p class="noindent">Note that the return value of <code>27</code> means that the breakpoint was effectively set to line 27. The status of breakpoints in a function can be queried with the <code>dbstatus</code> function. <!-- debug.cc --> <p><a name="doc_002ddbstatus"></a> <div class="defun"> — Loadable Function: lst = <b>dbstatus</b> (<var>func</var>)<var><a name="index-dbstatus-694"></a></var><br> <blockquote><p>Return a vector containing the lines on which a function has breakpoints set. <dl> <dt><code>func</code><dd>String representing the function name. When already in debug mode this should be left out. </dl> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002ddbclear.html#doc_002ddbclear">dbclear</a>, <a href="doc_002ddbwhere.html#doc_002ddbwhere">dbwhere</a>. </p></blockquote></div> <p class="noindent">Taking the above as an example, <code>dbstatus ("asind")</code> should return 27. The breakpoints can then be cleared with the <code>dbclear</code> function <!-- debug.cc --> <p><a name="doc_002ddbclear"></a> <div class="defun"> — Loadable Function: <b>dbclear</b> (<var>func, line, <small class="dots">...</small></var>)<var><a name="index-dbclear-695"></a></var><br> <blockquote><p>Delete a breakpoint in a function <dl> <dt><code>func</code><dd>String representing the function name. When already in debug mode this should be left out and only the line should be given. <br><dt><code>line</code><dd>Line number where you would like to remove the breakpoint. Multiple lines might be given as separate arguments or as a vector. </dl> 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. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002ddbstop.html#doc_002ddbstop">dbstop</a>, <a href="doc_002ddbstatus.html#doc_002ddbstatus">dbstatus</a>, <a href="doc_002ddbwhere.html#doc_002ddbwhere">dbwhere</a>. </p></blockquote></div> <p class="noindent">These functions can be used to clear all the breakpoints in a function. For example, <pre class="example"> dbclear ("asind", dbstatus ("asind")); </pre> <p>A breakpoint can be set in a subfunction. For example if a file contains the functions <pre class="example"> function y = func1 (x) y = func2 (x); endfunction function y = func2 (x) y = x + 1; endfunction </pre> <p class="noindent">then a breakpoint can be set at the start of the subfunction directly with <pre class="example"> dbstop (["func1", filemarker(), "func2"]) ⇒ 5 </pre> <p>Note that <code>filemarker</code> returns a character that marks the subfunctions from the file containing them. <p>Another simple way of setting a breakpoint in an Octave script is the use of the <code>keyboard</code> function. <!-- input.cc --> <p><a name="doc_002dkeyboard"></a> <div class="defun"> — Built-in Function: <b>keyboard</b> ()<var><a name="index-keyboard-696"></a></var><br> — Built-in Function: <b>keyboard</b> (<var>prompt</var>)<var><a name="index-keyboard-697"></a></var><br> <blockquote><p>This function is normally used for simple debugging. When the <code>keyboard</code> 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 if necessary. To leave the prompt and return to normal execution type ‘<samp><span class="samp">return</span></samp>’ or ‘<samp><span class="samp">dbcont</span></samp>’. The <code>keyboard</code> function does not return an exit status. <p>If <code>keyboard</code> is invoked without arguments, a default prompt of ‘<samp><span class="samp">debug> </span></samp>’ is used. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002ddbcont.html#doc_002ddbcont">dbcont</a>, <a href="doc_002ddbquit.html#doc_002ddbquit">dbquit</a>. </p></blockquote></div> <p class="noindent">The <code>keyboard</code> 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. </body></html>