Adding a command to aid in debugging Octave

"John W. Eaton" <[email protected]>
Newsgroups gmane.comp.gnu.octave.maintainers
Message-ID <[email protected]>
When trying to debug an already running Octave session I often get the 
pid and run "gdb -p PID" in a separate terminal window.  That works for 
me on Linux systems.  I've also sometimes used a command like

   system (sprintf ("gnome-terminal -- gdb -p %d", getpid ()),
           false, "async");

at the Octave prompt.

I never expected something like that to work on Windows, but I recently 
discovered that gdb can also connect to running processes on Windows. 
Am I the only one who didn't know?  Until that discovery, I didn't know 
any easy way to debug Octave on Windows.  But it still required opening 
a command window and starting gdb.  Then I also found that it is 
possible to start gdb in a separate window from the Octave prompt using

   system (sprintf ("start gdb -p %d", getpid ()));

Magic!  (Also somewhat surprising to me, passing the "async" parameter 
on Windows seemed to have the opposite effect and Octave did not return 
to the command prompt until the gdb process exited, but I'll worry about 
that later.)

To make debugging Octave even easier, would it be useful to add 
something like the following function?

function __debug_octave__ ()
   [status, ~] = system ("gdb --version");
   if (status != 0)
     error ("__debug_octave__: unable to execute gdb");
   endif
   if (isunix ())
     ## FIXME: Obviously, gnome-terminal is not always available.
     system (sprintf ("gnome-terminal -- gdb -p %d", getpid ()),
             false, "async");
   elseif (ispc ())
     system (sprintf ("start gdb -p %d", getpid ()));
   elseif (ismac ())
      ## FIXME: What works?
   else
      ## FIXME: Is this possible?
   endif
endfunction

What's the right thing for Mac systems?

Unless there is some magic command I don't know about that works on 
Unixy systems, we might need to search for known terminal since we can't 
expect to always find gnome-terminal.

Comments?  Is there a better way?

jwe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.