Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Notepad++ Integrated Perl Debugging

by VinsWorldcom (Parson)
on Aug 05, 2015 at 10:28 UTC ( #1137488=perlmeditation: print w/replies, xml ) Need Help??

Windows Monks,

Do you use Notepad++ as your preferred editor? Have you done some things with NppExec to move towards an IDE? Do you want integrated debugger support?

I was out of luck on the last one and a myriad of Google-ing didn't help. There was a debugger plugin for Notepad++ (DBGp - http://sourceforge.net/projects/npp-plugins/files/DBGP%20Plugin/) but it was for PHP debugging with XDebug ... originally. I set out to get Perl working with it and lo and behold - I did it!

UPDATE: I'm on Windows 7 x64 and using Strawberry Perl 5.18.1 MSWin32-x64-multi-thread.

The gory details can be found here:

http://vinsworldcom.blogspot.com/2015/08/debugging-perl-debugger-part-1-notepad.html
http://vinsworldcom.blogspot.com/2015/08/debugging-perl-debugger-part-2-variable.html
http://vinsworldcom.blogspot.com/2015/08/debugging-perl-debugger-part-3.html

Essentially, you need:

DBGp plugin

Get it from the SourceForge page at http://sourceforge.net/projects/npp-plugins/files/DBGP%20Plugin/. Get the latest (0.13 beta as of this writing) and you'll only need the DLL. Current file name is: DBGpPlugin_0_13b_dll.zip. Unzip the DLL to your Notepad++\plugins directory.

Perl Debugger for Komodo IDE

We only need this since there isn't a "Perl Debugger for Notepad++ IDE". It essentially supplies the interface via "perl5db.pl" and subdirectory "DB" of various supporting modules. You get it here: http://downloads.activestate.com/Komodo/releases/archive/4.x/4.4.1/remotedebugging/ and you'll want the Komodo-PerlRemoteDebugging-4.4.1-20896-win32-x86.zip file. NOTE: I tried newer releases, but found other issues cropped up in addition to the ones I show you how to fix below, so use this version, or the rest of this won't make much sense.

I created a directory in my Notepad++\plugins directory called "PerlDebug"; so, (...)\Notepad++\plugins\PerlDebug. I unzipped only the "perl5db.pl" file and the entire "DB" directory and its sub directories into that PerlDebug directory.

Getting it to Work

You need to make some edits to the Perl Debugger scripts from the Komodo IDE as well as set some environment variables. First, the edits.

Edit DB\DBgrProperties.pm

Open the Notepad++\plugins\PerlDebug\DB\DBgrProperties.pm file. Line 657-659 is something like:

$res .= sprintf(qq(<value%s><![CDATA[%s]]></value>\n), $encoding ? qq( encoding="$encoding") : "", $encVal);

Change that to:

$res .= sprintf(qq(<![CDATA[%s]]>\n), $encVal);

Also, further up on line 131, you'll see:

context_id="%d"

Change that to:

context="%d"
Edit perl5db.pl

Open the Notepad++\plugins\PerlDebug\perl5db.pl file. On line 1525:

$res .= sprintf(' line="%s"',

change to:

$res .= sprintf(' lineno="%s"',

And, after line 2898, which should read:

my $bpInfo = getBreakpointInfoString($bkptID, function => $bFuncti +on);

add the following three lines:

if ($bpInfo) { $res .= $bpInfo; }
Environment Variables

You'll need some environment variables to get this to work. I wanted them to be volatile so as not to upset normal operations. This where I used NppExec. I'll assume you have it installed as it's an awesome plugin that you should have installed. If not, get if from the Plugin Manager.

The only essential environment variables to set are:

set PERL5LIB=C:\path\to\Notepad++\plugins\PerlDebug set PERLDB_OPTS=RemotePort=127.0.0.1:9000

where "\path\to\Notepad++" is your directory path to Notepad++. I have mine at "C:\usr\bin\npp\plugins\PerlDebug". Yours may be "C:\Program Files\Notepad++\plugins\PerlDebug". Note if your path has a space (like between "Program" and "Files" in the example, you'll probably need to double-quote the entire path assigned to PERL5LIB like: set PERL5LIB="C:\Program Files\Notepad++\plugins\PerlDebug".

I set my variables with an NppExec script:

NPP_SAVE cd "$(CURRENT_DIRECTORY)" NPP_MENUCOMMAND Plugins\DBGp\Debugger ENV_SET PERLDB_OPTS=RemotePort=127.0.0.1:9000 ENV_SET PERL5LIB=$(SYS.PERL5LIB);$(NPP_DIRECTORY)\plugins\PerlDebug INPUTBOX "Command Line Arguments: " cmd /c start "Perl Debug" cmd /c perl.exe -d "$(FILE_NAME)" $(INPUT)

I saved it as "Perl - Debug" and used NppExec to add it to my "Macro" menu in Notepad++. It saves the current file, changes to the working directory, enables the DBGp plugin, sets the environment variables (only temporarily within the Notepad++ context, and careful not to step on a current value that may be in PERL5LIB), prompts for any command-line input to pass to your script to get it to run and finally starts the Perl debugging session - integrated in Notepad++!

Some options I used to tune the DBGp plugin; from the Notepad++ "Plugins" menu, select "DBGp" and then "Config...".

  • Ensure the top checkbox "Bypass all mapping (local windows setup) is checked
  • No configuration in the "Remote Server IP", "IDE KEY" ... window
  • Under the "Misc" section, check:
    • "Break at first line when debugging starts"
    • "Refresh local context on every step"
    • "Refresh global context on every step"

Hope it works for you - happy debugging!

Replies are listed 'Best First'.
Re: Notepad++ Integrated Perl Debugging
by chacham (Prior) on Aug 05, 2015 at 12:35 UTC

      Thanks for the comment. I hadn't thought about that. All the years I've been here I've really only used SOPW to post. I had to do some digging to see this belonged in Meditations (at least to start).

      From Tutorials, it seems I skipped step 1 and forgot "RFC" in my title as per step 2.

      1. Write up your draft tutorial and put it in your scratchpad; broadcast requests for comments in the chatterbox and elsewhere.
        After revising,
      2. Post it as a new Meditation, with "RFC" in the title.
        Later, if it is generally acclaimed to be worthy of Tutorials, but needs more work first, then make the necessary revisions and
      3. Post the final version as a Tutorials node.

        Glad i could be of service. :)

        I do use Notepad++, but not doing much Perl right now. If it comes up again, i'll definitely be interested in your excellent writeup.

Re: Notepad++ Integrated Perl Debugging
by pryrt (Parson) on Feb 26, 2018 at 14:40 UTC

    A few years later... Have you found a 64bit version of the DBGp (or an alternate) to work with the 64bit Notepad++? Or have you stayed with the 32-bit Notepad++ so far? Or have you given up on using Notepad++ for integrated debug?

      I've stayed with 32-bit Notepad++ (now using version 7.5) since many other plugins are only available for 32-bit.

        I thought that might be the case. I'd like to eventually change to 64bit: some things that the author has said in the NPP forums indicate that the 32-bit version might not continue to be maintained, long-term; and on rare occasions, I have a file big enough that the 64-bit can open that 32-bit cannot. For now, I just keep a portable version of 64-bit, but use 32-bit as my daily. I guess if I ever do switch, I could keep an old 32-bit for tasks like this. (Usually, I can debug my scripts with simple print statements, but every once in a while, there are things that are just easier to find single-stepping, and using NPP as my interface is so much easier for me than the raw perl debugger. For those situations, I'm really thankful for your instructions.)

Re: Notepad++ Integrated Perl Debugging
by adefaria (Beadle) on Aug 25, 2015 at 16:36 UTC
    Just use Eclipse and EPIC. You have your debugger. Plus runs on Linux too!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1137488]
Approved by Discipulus
Front-paged by Discipulus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2019-03-20 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How do you Carpe diem?





    Results (101 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!