Debugging Octave: Difference between revisions
(→Emacs) |
|||
Line 51: | Line 51: | ||
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="matlab">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 = |
Revision as of 22:36, 14 November 2012
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 export CXXFLAGS="-ggdb -Wall -O0"
for C++ code or export CFLAGS="-ggdb -Wall -O0"
for C code to suppress optimization. Compile the oct-file with the debug flag -g
which enables debug symbols
mkoctfile -g file.cpp
start now the GNU debugger with octave
gdb octave
and run it
(gdb) run
Octave will start up. To load the symbol table the function needs to be executed, for example by invoking the help function
octave:1> help file
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
(gdb) b file.cpp:40
by typing c the execution of octave will continue and you can run your oct-file directly or via an m-script.
octave:1> x = file(y)
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
> gdb octave
- Catch loading of your oct-file ("file" below is a regex matching name of your oct-file)
(gdb) catch load file
- Run octave
(gdb) r
- From octave request loading of your oct-file by calling function
octave> x = file(y)
- 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.
(gdb) b file.cpp:40
- Resume execution of octave by
(gdb) c
and debugger will stop at the breakpoint defined.
Tools for debugging
GBD
To start Octave under gdb use the script run-octave
at the top level of the source tree and run it with the command-line option -g
like this
cd /octave/build/tree ./run-octave -g
Most used commands
Emacs
In short:
To start Octave in debug mode within emacs type
M-x gud-gdb
then change the command in the minibuffer to
Run gud-gdb (like this): /path/to/octave/build/tree/run-octave -gud
For more info use this
link
to the emacs manual section on debuggers operation
ddd