Debugging Octave: Difference between revisions

Jump to navigation Jump to search
2,018 bytes added ,  1 June 2019
m (→‎Most used commands: fixed formating on the previous)
(2 intermediate revisions by the same user not shown)
Line 44: Line 44:
</syntaxhighlight>
</syntaxhighlight>


start now the GNU debugger with octaveOn most Unixy systems, you can start gdb from within an Octave session by evaluating a command like
In next step you will use GNU debugger or gdb. The symbols from your oct-file will only be available to gdb once the oct-file is loaded in OctaveTo do that without executing any functions from the oct-file, you can ask Octave to display the help for the oct-file:


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


at the Octave promptThis 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
start now the GNU debugger with octaveOn most Unixy systems, you can start gdb from within an Octave session by evaluating a command like


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


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:
at the Octave prompt.  This command will open a terminal window running gdb attached to the Octave processAt this point, Octave will be stopped. 
 
<syntaxhighlight lang="bash">
octave> 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
Now you can set a breakpoint in the line of interest of your oct-file in gdb prompt:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 79: Line 75:
== Producing a stack trace ==
== 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 diagnose the problem. To do so, you need to (re)compile Octave with debugging symbols and run the debugger, as explained above.  Then execute whatever commands are necessary to cause Octave to crash.  At that point, you will be back in a gdb session. Type <code>where</code> at the gdb prompt to obtain 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 diagnose the problem. To do so, you need to (re)compile Octave with debugging symbols , only if you can afford such a huge work, and run the debugger, as explained above.  Then execute whatever commands are necessary to cause Octave to crash.  At that point, you will be back in a gdb session. Type <code>where</code> at the gdb prompt to obtain a stack trace.
 
But if you can't or don't want to recompile octave ,which is totally normal, then you can get some help from your system tools. In most GNU/Linux systems whenever a crash happens in a software, a <i>core dump</i> will be generated. These core dumps are handled by a registered component of the system and finally can be stored somewhere in the directory tree. You should find them, view them and inspect them.
 
=== Where are core dumps stored? ===
It differs on each system. First you should see what does handle core dumps on your system. to do so, type this in a shell terminal:
<syntaxhighlight lang="bash">
$ cat /proc/sys/kernel/core_pattern
</syntaxhighlight>
This may print a file name pattern along with a path, where all core dumps will be saved <b>ONLY</b> if it does not start by a pipe or '|'. If it does, <i>the kernel will treat the rest of the pattern as a command to run.  The core dump will be written to the standard input of that program instead of to a file</i>, and you need to consult that program's help or manual.
 
=== How to view a core dump? ===
To do this you should use gdb. Core dumps are saved under root user, so you may need to change owner of the core dump you are interested in if you are not logged in as root. After that type in the terminal:
<syntaxhighlight lang="bash">
gdb octave -c <Path to core dump>
</syntaxhighlight>
 
Always expect some warnings from gdb in a few first times of doing this. Most likely gdb will tell you that:
 
1. The core dump file is not in the correct format. It is the case if the core dump handler of your system compresses core dumps before storing them, and you need to decompress the core dump first.
 
2. Core dump was generated by a-path-to/octave-gui. Then quit gdb and start it again by:
<syntaxhighlight lang="bash">
gdb octave-gui -c <Path to core dump>
</syntaxhighlight>
 
3. Some debug info are missing. In this case gdb itself will tell you how to install them. Install them and start gdb again.
 
If everything worked fine, you can use 'where' command in gdb prompt to see a full stack trace of the crash.


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

Navigation menu