Debugging Octave: Difference between revisions

612 bytes added ,  27 November 2012
no edit summary
No edit summary
Line 34: Line 34:
Octave will start up. To load the symbol table the function needs to be executed, for example by invoking the help function
Octave will start up. To load the symbol table the function needs to be executed, for example by invoking the help function


<syntaxhighlight lang="matlab">
<syntaxhighlight lang="octave">
octave:1> help file
octave:1> help file
</syntaxhighlight>  
</syntaxhighlight>  
Line 46: Line 46:
by typing c the execution of octave will continue and you can run your oct-file directly or via an m-script.
by typing c the execution of octave will continue and you can run your oct-file directly or via an m-script.


<syntaxhighlight lang="matlab">
<syntaxhighlight lang="octave">
octave:1> x = file(y)
octave:1> x = file(y)
</syntaxhighlight>  
</syntaxhighlight>  
Line 58: Line 58:
# 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>
# 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>
# Run octave<br/><syntaxhighlight lang="bash">(gdb) r</syntaxhighlight>
# From octave request loading of your oct-file by calling function<br/><syntaxhighlight lang="matlab">octave> x = file(y)</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>
# 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>
# Resume execution of octave by<br/><syntaxhighlight lang="bash">(gdb) c</syntaxhighlight>
Line 69: Line 69:
     cd /octave/build/tree
     cd /octave/build/tree
     ./run-octave -g
     ./run-octave -g
== Producing a stack trace ==
Sometimes Octave will crash, meaning, it terminates abruptly and returns control to the operating system shell. In these cases, it is very helpful to produce a stack trace to reproduce the problem. To do so, you need to (re)compile Octave with debugging symbols as explained above and run the debugger, as explained above. Then, run Octave:
<syntaxhighlight lang="bash">
gdb> run
</syntaxhighlight>
execute whatever commands you think are necessary to produce the crash. When Octave crashes, you will be back in a gdb session. Type <code>bt</code> here to obtain a stack trace.


=== Most used commands ===
=== Most used commands ===