Debugging Octave: Difference between revisions

Jump to navigation Jump to search
601 bytes removed ,  4 April 2014
Line 19: Line 19:
</syntaxhighlight>
</syntaxhighlight>


start now the GNU debugger with octave
start now the GNU debugger with octave.  On most Unixy systems, you can start gdb from within an Octave session by evaluating a command like


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
gdb octave
octave> system (sprintf ("gnome-terminal --command 'gdb -p %d'", getpid ()), "async");
</syntaxhighlight>
</syntaxhighlight>


and run it
at the Octave prompt.  This command will open a terminal window running gdb attached to the Octave process.  At this point, Octave will be stopped.  To tell Octave to continue, type


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
(gdb) run
(gdb) continue
</syntaxhighlight>
</syntaxhighlight>


Octave will start up. To load the symbol table the function needs to be executed, for example by invoking the help function
at the gdb prompt.  The symbols from your oct-file will only be available to gdb once the oct-file is loaded in Octave. To do that without executing any functions from the oct-file, you can ask Octave to display the help for the oct-file:


<syntaxhighlight lang="octave">
<syntaxhighlight lang="bash">
octave:1> help file
octave> help file
</syntaxhighlight>  
</syntaxhighlight>


Now halt execution of Octave by typing ctrl+c, you'll see again the gdb prompt. Set now a breakpoint in the line of interest
Now halt execution of Octave by typing ctrl+c, you'll see again the gdb prompt. Set now a breakpoint in the line of interest
Line 46: Line 46:


<syntaxhighlight lang="octave">
<syntaxhighlight lang="octave">
octave:1> x = file(y)
octave> x = file(y)
</syntaxhighlight>  
</syntaxhighlight>  


the debugger will stop on the above defined line and you can start debugging according to the manual of GNU debugger.
the debugger will stop on the above defined line and you can start debugging according to the manual of GNU debugger.
If you encounter problem with interrupting octave (i.e. "^C" is only
printed when you press ctrl+c and control is not transferred to gdb)
then you might follow following steps (which should work always).
# Start gdb<br/><syntaxhighlight lang="bash">> gdb octave</syntaxhighlight>
# Catch loading of your oct-file ("file" below is a regex matching name of your oct-file)<br/><syntaxhighlight lang="bash">(gdb) catch load file</syntaxhighlight>
# Run octave<br/><syntaxhighlight lang="bash">(gdb) r</syntaxhighlight>
# From octave request loading of your oct-file by calling function<br/><syntaxhighlight lang="octave">octave> x = file(y)</syntaxhighlight>
# Control will switch to gdb just after oct-file is loaded and at this point all symbols from oct-file are available so you can either set up a breakpoint at particular line or at function entry.<br/><syntaxhighlight lang="bash">(gdb) b file.cpp:40</syntaxhighlight>
# Resume execution of octave by<br/><syntaxhighlight lang="bash">(gdb) c</syntaxhighlight>
and debugger will stop at the breakpoint defined.


= Tools for debugging =
= Tools for debugging =

Navigation menu