Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

Perl debugger is very useful tool, but I seldom used it because I can’t quickly edit source code when I found the problems in the debug mode. Is there a way/module to edit source code during debug and automatically save as to another file( maybe xxx.pl.debug). So it’s handy to diff the orig and debug when done.
  • Comment on How edit source code in perl debug mode

Replies are listed 'Best First'.
Re: How edit source code in perl debug mode
by LanX (Saint) on May 04, 2024 at 08:55 UTC
    > quickly edit source code

    Most IDEs offer a debug mode were you step thru the original code while starting the debugger in the background.

    Emacs even offers a second pane were the debugger CLI is seen like from the console.¹

    You can edit the code while debugging, but you'll need to restart the debug run to see an effect.

    > automatically save as to another file( maybe xxx.pl.debug). So it’s handy to diff the orig and debug when done.

    Sounds like an XY question to me. Anyway ....

    You can write a editor macro to

    • rename the current file as XXX.dbg.pl
    • turn on auto-save
    • start debug-mode
    and bind it to F6 or something

    Another macro on F7 runs the diff.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    Updates

    ¹) emacs can also be started inside the console with no-window mode -nw . Like this you could could have a full textual CLI experience, without extra GUI windows.

      There's also realgud which provides a unified emacs interface to several debugging backends (caveat: I've diddled with this very little personally but it's been on my list to use more).

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

      Well, I think you misunderstand me, I know how debug perl code and how set personal macro on IDE. My question is perl debugger is powerful but why many monks choose print for debug, after all,-d is a part of standard perl. To me, not using -d is because it can’t edit in place, it can’t let me make a real debug release.

        My question is perl debugger is powerful but why many monks choose print for debug

        As for why many famous programmers strive to minimize time spent in crack-pipe debugging sessions see : on Debuggers References

        👁️🍾👍🦟
        > many monks choose print for debug, after all,-d is a part of standard perl

        I think I'm one of the main debugger experts here, and I hardly ever use it for debugging.

        My own code is better debugged with tests and conditional warns.

        Mainly because it's easily reproduced while interactive debugger sessions aren't. I prefer sustainable investments.

        Occasionally I use debug or trace if I need to take over complex foreign code.

        But mostly because of bad design, testing or documentation.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

        To me, not using -d is because it can’t edit in place

        That's a really weird statement. A debugger and an editor are two different tools with different user interfaces. Many IDEs integrate them both.

        If debugging from the command line, you can fire up the editor of your choice with e.g. system "nano $0" and then edit in place. Integrating the user interface of any editing capabilities in the debugger looks like a bad idea for me.

        The debugger can't edit files, editors edit files.

        You need to combine² them if you want both.

        Running emacs in the console is IMHO the closest you can do to have that look and feel of the debugger editing files.¹

        Fletch's link to realgud has a screenshot , albeit for Python.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

        ¹) well, IIRC, there is a command to spawn an (configurable) editor on the file debugged. Maybe that's what you want?

        ²) that's very much the meaning of IDE