Adding a command to aid in debugging Octave

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding a command to aid in debugging Octave

John W. Eaton
Administrator
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


Reply | Threaded
Open this post in threaded view
|

Re: Adding a command to aid in debugging Octave

Carlo de Falco-2
Hi,

> Il giorno 14 mag 2020, alle ore 19:25, John W. Eaton <[hidden email]> ha scritto:
>
> What's the right thing for Mac systems?

this seems to work for me :

system (sprintf ("osascript -e 'tell application \"Terminal\" to do script \"lldb -p %d\"'", getpid ()))

the escaping looks a bit tricky though so it would be nice if someone else could verify it ...

c.



Reply | Threaded
Open this post in threaded view
|

Re: Adding a command to aid in debugging Octave

Andrew Janke-2


On 5/14/20 3:41 PM, Carlo De Falco wrote:

> Hi,
>
>> Il giorno 14 mag 2020, alle ore 19:25, John W. Eaton <[hidden email]> ha scritto:
>>
>> What's the right thing for Mac systems?
>
> this seems to work for me :
>
> system (sprintf ("osascript -e 'tell application \"Terminal\" to do script \"lldb -p %d\"'", getpid ()))
>
> the escaping looks a bit tricky though so it would be nice if someone else could verify it ...
>
> c.

Works for me in Octave 4.4.1 on macOS 10.14.6.

Cheers,
Andrew