Your skill will accomplish what the force of many cannot |
|
PerlMonks |
How to perldebug a Term::ReadLine applicationby LanX (Saint) |
on Dec 01, 2014 at 14:42 UTC ( [id://1108836]=CUFP: print w/replies, xml ) | Need Help?? |
the problemI recently heard monks complaining that applications using Term::ReadLine can't be debugged within the perldebugger b/c it's interface relies on Term::Readline.
the trickhere one solution (at least for linux) I wanted to have documented (before I forget it again ;)call the script you want to debug (here calc_TRL.pl ) from a shell with PERLDB_OPTS="TTY=`tty` ReadLine=0" xterm -e perl -d ./calc_TRL.pl and a second xterm will be opened running the program.
how it worksa second xterm is started running the debugger, but b/c of the TTY setting in PERLDB_OPTS all debugger communication goes via the parent xterm , while the calc app normally displays in the child xterm . ReadLine=0 tells the debugger not to rely on a working Term::ReadLine. NB: It's important that calling the second xterm blocks the execution in the first xterm till it's finished. Like this keystrokes aren interpreted by two applications in the first xterm. Just put an & at the end to see how things get messed up otherwise if the shell tries to step in.
how it looks like
first xtermbecomes the front end for the debugger
as you see I get the lines from the app in the second xterm listed can set a breakpoint at the end of the loop and tell twice to continue till next breakpoint.
second xtermruns the application, I'm asked to enter a calculation which is evaluated, interupted twice by a breakpoint at line 9.
the test script
tested with Term::ReadLine::Gnu installed.
generalisationyou can use this approach whenever you want the debugger communication separated into a separate term. e.g. Curses::UI comes to mind
discussionthe solution is not "perfect", of course you need to arrange the windows and switch with Alt-Tab between them. (maybe screen could solve this or an emacs inegration) Furthermore you won't have a history with arrow navigation within the debugger, cause TRL was disabled. another approach is to communicate via sockets with a debugger run within emacs, since emacs has it's own TRL-emulation this shouldn't interfere. see also Re: Testing terminal programs within emacs (SOLVED) for an approach to handle all this automatically, by restarting a script with altered environment and different terminal.
TIMTOWTDIsee perldebguts , perldebtut and perldeb, Also "Pro Perl Debugging" book and various TK tools on CPAN.
Cheers Rolf (addicted to the Perl Programming Language and ☆☆☆☆ :)
Back to
Cool Uses for Perl
|
|