<?xml version="1.0" encoding="UTF-8"?>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
          xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
          xml:lang="en" xml:id="debug">
    <refnamediv>
        <refname>debug</refname>
        <refpurpose>Debugging environment in Scilab</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
            debug()
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Description</title>
        <para>
            Use to debug Scilab script.
            After call of <literal>debug()</literal>, you enter in debug mode.
            This mode allows you to manage <literal>breakpoints</literal>,
            launch execution with stop on error, execute script step by step, ...

            In debugging mode, the prompt is <literal>debug> </literal>.
        </para>
        <term>Commands: </term>
        <variablelist>
            <varlistentry>
                <term>h: </term>
                <para>
                  Show always the debuger help in the console, whatever is the Scilab
                  running mode.
                 </para>
            </varlistentry>
            <varlistentry>
                <term>help: </term>
                <para>
                    In Scilab standard running mode (with GUIs), displays the debug() help page in
                    the help browser. Otherwise, displays the help in the console (as with "h").
                </para>
            </varlistentry>
            <varlistentry>
                <term>(q)uit: </term>
                <para>Leave debug mode to return to normal mode of Scilab.</para>
            </varlistentry>
            <varlistentry>
                <term>(w)here or bt: </term>
                <para>Display callstack.</para>
            </varlistentry>
            <varlistentry>
                <term>(e)xec or (r)un: </term>
                <para>Execute command.</para>
            </varlistentry>
            <varlistentry>
                <term>(d)isp var, or (p)rint var: </term>
                <para>
                    Display variable <literal>var</literal>.
                </para>
            </varlistentry>
            <varlistentry>
                <term>(c)ontinue: </term>
                <para>Continue execution.</para>
            </varlistentry>
            <varlistentry>
                <term>(a)bort: </term>
                <para>Abort execution.</para>
            </varlistentry>
            <varlistentry>
                <term>step(n)ext or next: </term>
                <para>Continue execution to next expression.</para>
            </varlistentry>
            <varlistentry>
                <term>step(i)n or in: </term>
                <para>Continue execution to next expression in sub function.</para>
            </varlistentry>
            <varlistentry>
                <term>step(o)ut or out: </term>
                <para>Continue execution to next expression in previous function.</para>
            </varlistentry>
            <varlistentry>
                <term>(b)reakpoint or break: </term>
                <synopsis>breakpoint function [line [condition]]</synopsis>
                <para>
                    Add a breakpoint in a function at line <literal>line</literal>
                </para>
                <para>
                    If a condition is specified, the breakpoint is enabled only if the condition
                    is <literal>%t</literal>
                </para>
            </varlistentry>
            <varlistentry>
                <term>(del)ete [n]: </term>
                <para>Remove all breakpoints.</para>
                <para>If n is specified, remove breakpoint #n</para>
            </varlistentry>
            <varlistentry>
                <term>enable [n]: </term>
                <para>Enable all breakpoints.</para>
                <para>If n is specified, enable breakpoint #n</para>
            </varlistentry>
            <varlistentry>
                <term>disable [n]: </term>
                <para>Disable all breakpoints.</para>
                <para>If n is specified, disable breakpoint #n</para>
            </varlistentry>
            <varlistentry>
                <term>(s)how [n]: </term>
                <para>Show all breakpoints information.</para>
                <para>If n is specified, show breakpoint #n</para>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
//function to overload cosine on string
function v = %c_cos(val)
    printf("val : %s\n", val);
    v = cos(evstr(val));
endfunction

//caller
function a = test_debug()
    b = cos("%pi");
    a = b * 3;
endfunction

debug
break test_debug
exec test_debug
where
stepin
disp val
continue
quit
 ]]></programlisting>
        <programlisting role="example"><![CDATA[
function v = compute(val)
    v = 1;
    for i=1:val
        v = v * i;
    end
endfunction

debug
break compute 4 "i == 5"
exec compute(10)
disp val
disp i
disp v
continue
quit
 ]]></programlisting>
    </refsection>

    <refsection>
        <title>History</title>
        <revhistory>
            <revision>
                <revnumber>6.0.0</revnumber>
                <revremark>New version: console interface to Scilab 6 debugger.</revremark>
            </revision>
        </revhistory>
    </refsection>
</refentry>
