Home ........ Travels ........ Web 3D ........ Socials

Wednesday, August 05, 2015

Debugging Perl Debugger: Part 3 - Automation

We have Perl debugging integrated with Notepad++. We fixed variable values so they show up in watch lists. Now we want to automate the use of Perl debugging directly from Notepad++ while editing a Perl script.

NppExec is a plugin with powerful automation features for Notepad++. The documentation showed it had all I needed to get this to work.

I needed to dynamically create the environment variables in a volatile environment so they wouldn't conflict with normal operations. Specifically, the PERL5LIB variable which we used to find "perl5db.pl". Perl locates the "perl5db.pl" script by searching @INC. It's not a problem to have a few "perl5db.pl" scripts laying around for different activities - the normal command-line Perl debugger, the Notepad++ integration, the old Perl-specific IDE I used to use - they just can't all be in @INC (via PERL5LIB environment variable, or otherwise) at the same time. Otherwise, you may not be using the right one and get unexpected results.

NppExec allows you to create and modify environment variables which do not stay permanent on exit (volatile), so I saw the automation steps as:

  1. Save the current file
  2. Change to the current working directory
  3. Ensure the DBGp plugin is enabled
  4. Set required environment variables
  5. Prompt for input (command line input that may be needed when running the script)
  6. Start the Perl debugger

If you don't have the NppExec plugin, add it with Notepad++ menu commands "Plugins"=>"Plugin Manager"=>"Show Plugin Manager". From there, find "NppExec" in the "Available" tab, select its chechbox and press "Install". Once installed, launch NppExec with Notepad++ menu commands "Plugins"=>"NppExec"=>"Execute..." or simply use "F6" key if you haven't mapped that to something else.

In the pop-up window, select "<temporary script>" and enter the following:

INPUTBOX "Command Line Arguments: "
cmd /c start "Perl Debug" cmd /c perl.exe -d "$(FILE_NAME)" $(INPUT)

Press the "Save..." button and enter the "Script name:" as "Perl - Debug", without the double-quotes.

NppExec also allows you to add menu items to the "Macro" menu of Notepad++.

Select "Plugins"=>"NppExec"=>"Advanced Options...". Ensure the "Place to the Macros submenu" checkbox is checked. In the "Menu item" section, enter the "Item name" as "Perl - Debug", without the double-quotes. In the "Associated script" pulldown, select "Perl - Debug". Press the "Add/Modify" button and then press "OK".

Now, when you're having issues with a Perl script you're writing in Notepad++ and you need to debug, simply select the Notepad++ menu "Macro"=>"Perl - Debug". You'll be prompted with a window to enter command line options to run your program. This is where you'd enter options for the script itself - perhaps an input file, maybe some switches that you've specified if you're using Getopt::Long, for example. If there are none, just press the "OK" button.

You can set breakpoints, add watches and step through your script. When you're done or to start over, just press the "Turn OFF" button in the DBGp plugin console window in Notepad++. It will change to "Turn ON", which you'll need to press if you want to restart debugging.

Happy debugging!

No comments :


Copyright © VinsWorld. All Rights Reserved.