Debugging Octave: Difference between revisions

Jump to navigation Jump to search
→‎Tools for debugging: Add more comments
(→‎Tools for debugging: Add basic instructions for running gdb with Octave - Put necessity of re-compiling Octave into perspective)
(→‎Tools for debugging: Add more comments)
Line 79: Line 79:
Alternatively, you can attach <code>gdb</code> to a running Octave. For this, execute <code>gdb</code> in a shell. (On Windows, use the msys2 shell that can be started with the file <code>cmdshell.bat</code> in Octave's installation folder). Find the PID of the running Octave process and attach to it from the <code>(gdb)</code> prompt with <code>attach *PID*</code> (replace <code>*PID*</code> with the actual PID).
Alternatively, you can attach <code>gdb</code> to a running Octave. For this, execute <code>gdb</code> in a shell. (On Windows, use the msys2 shell that can be started with the file <code>cmdshell.bat</code> in Octave's installation folder). Find the PID of the running Octave process and attach to it from the <code>(gdb)</code> prompt with <code>attach *PID*</code> (replace <code>*PID*</code> with the actual PID).


Yet another possibility is to start <code>gdb</code> using the <code>system</code> command at the Octave prompt. Depending on the used Linux shell, the command might look similar to:
Yet another possibility is to start <code>gdb</code> using the <code>system</code> command at the Octave prompt. Depending on the used Linux shell, the command might look similar to (see the above comments wrt running this from the GUI in some distributions):
  system (sprintf ("gnome-terminal -- gdb -p %d", getpid ()), false, "async");
  system (sprintf ("gnome-terminal -- gdb -p %d", getpid ()), false, "async");
On Windows, you can issue:
On Windows, you can issue:
  system (sprintf ("start gdb -p %d", getpid ()));
  system (sprintf ("start gdb -p %d", getpid ()));
The last approach might not be useful for debugging some kinds of errors. The OS might kill the shell that runs gdb as soon as the spawning process (i.e. Octave) crashes.


Independent of how <code>gdb</code> was started and Octave was attached to it, it is now possible to issue gdb commands on the <code>(gdb)</code> prompt. See e.g. the [https://sourceware.org/gdb/download/onlinedocs/gdb/index.html gdb documentation]. To return to Octave while gdb is still attached to it, execute <code>continue</code> (or <code>c</code>) at the <code>(gdb)</code> prompt.
Independent of how <code>gdb</code> was started and Octave was attached to it, it is now possible to issue gdb commands on the <code>(gdb)</code> prompt. See e.g. the [https://sourceware.org/gdb/download/onlinedocs/gdb/index.html gdb documentation]. To return to Octave while gdb is still attached to it, execute <code>continue</code> (or <code>c</code>) at the <code>(gdb)</code> prompt.
238

edits

Navigation menu