Editing Debugging Octave
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
= Preliminaries = | = Preliminaries = | ||
Since compilation of all the source from scratch can take long it is good to have a source folder where most of the source has been compiled. To do this ... | |||
== Workflow == | |||
# Clone the repository. | |||
# Regenerate the scripts. | |||
# Configure. | |||
# Compile the code. | |||
# Start debugging. | |||
= Basic debugging processes = | |||
== Error & trace the stack == | |||
= Debugging oct-files = | |||
To debug oct-files, avoid making any optimization during compilation. Use <code>export CXXFLAGS="-ggdb -Wall -O0"</code> for C++ code or <code>export CFLAGS="-ggdb -Wall -O0"</code> for C code to suppress optimization. Compile the oct-file with the debug flag <code>-g</code> which enables debug symbols | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
mkoctfile -g file.cpp | |||
</syntaxhighlight> | </syntaxhighlight> | ||
start now the GNU debugger with octave | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
gdb octave | |||
</syntaxhighlight> | </syntaxhighlight> | ||
and run it | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
(gdb) run | |||
</syntaxhighlight> | </syntaxhighlight> | ||
start | Octave will start up. To load the symbol table the function needs to be executed, for example by invoking the help function | ||
Now you | <syntaxhighlight lang="octave"> | ||
octave:1> help file | |||
</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 | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
Line 61: | Line 47: | ||
<syntaxhighlight lang="octave"> | <syntaxhighlight lang="octave"> | ||
octave> x = file(y) | octave:1> 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 = | |||
== GDB == | |||
To start Octave under gdb use the script <code> run-octave </code> at the top level of the source tree and run it with the command-line option <code> -g </code>like this | |||
cd /octave/build/tree | |||
./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 and run the debugger, as explained above. Then, run Octave: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
gdb> run | |||
</syntaxhighlight> | </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 === | |||
[http://www.gnu.org/software/gdb/documentation gdb documentation] | |||
gdb | |||
== Emacs == | |||
In short: | |||
To start Octave in debug mode within emacs type | |||
<code> | |||
M-x gud-gdb | |||
<code> | |||
then change the command in the minibuffer to | |||
<code> | |||
Run gud-gdb (like this): /path/to/octave/build/tree/run-octave -gud | |||
</code> | |||
[http://www.gnu.org/software/ | For more info use this | ||
[http://www.gnu.org/software/emacs/manual/html_node/emacs/Debuggers.html#Debuggers link] | |||
to the emacs manual section on debuggers operation | |||
== ddd == | == ddd == | ||
[http://www.gnu.org/software/ddd gui for gdb] | |||
[http://www.gnu.org/software/ddd | |||
[[Category:Development]] | [[Category:Development]] |