In today’s tech forum, I locked the doors and started teaching some of the perl developers the basics of the perl debugger.
Traditionally, people avoid using the debugger due to the perception that it’s hard to use. I can sympathise; I avoided it myself for the first ten years of my perl career. My fear was overcome thanks to a couple of employees in the team at the time. They ran a small workshop for the then-small team. I realised that the debugger was not something to be feared, but respected and cherished.
With a growing awareness that many people are still debugging with
warn() statements scattered through the code, I started thinking about how I could share my experiences with this tool. I didn’t want it to be something that people could only learn from if they were stuck in a room with me, but I wasn’t sure what format would suit the information I wanted to share.
After many months, with the idea simmering in the back of my mind, the answer came to me, and it seemed so stupidly simple I kicked myself: use github to host and render Markdown files for the lesson content!
After this revelation, it was fairly easy to start writing lessons that would gradually introduce people to the perl debugger.
Over a series of exercises, you will learn how to use the perl debugger.
You should try to work through the lessons in order. Even if you don’t perform all the exercises, you should read the lesson’s README.md file.
Clone the repository
git clone https://github.com/NET-A-PORTER/perl-debugger-tutorial.git
Change your working directory
Make sure the permissions are correct for the
.perldb files in this cloned
Debugger Configuration Files
Make sure you don’t have your own
.perldb anywhere that might
interfere with the lessons and examples.
The lesson directories all have a local
.perldb file that should override
any configuration in other directories – if things start to behave strangely,
please double check that there are no other files that could be influencing
the debugger’s behaviour.
Taking A Lesson
For each lesson it’s assumed you have changed your current working directory to be that of the lesson. For example:
# change to the directory for the first lesson cd 01.basics/ # read the lesson plan cat README.md # ... some time passes # change to the directory for the second lesson cd ../02.setup/
Viewing Markdown Files
You should be able to view, read and understand the Markdown files in any text editor.
If you’d like to have them rendered for you, check out these links:
Markdown Here (Chrome) with Ubuntu
If you opt to use Chrome with the Markdown Here extension, you can simply
to open the README.md file in the current directory.
If you’d like to use the Chrome file browser
should both work.
Markdown Here (Chrome) with MacOS
You can open files in Chrome from the command line:
open -a "Google Chrome" README.md
If you’d like to use the Chrome file browser:
open -a "Google Chrome" $PWD
Taking the course
You should work through each lesson in order, starting with Lesson 1.
People who are unfamiliar with the debugger take around 45 minutes to work through the first five lessons. This is a good point to stop if you’re working through multiple lessons; you’ll have learned the basic commands and should be able to use the debugger with moderate confidence.
This is a summary of the commands learned in each of the lessons in this series.
perl -d– start debugging
n– step through the script (‘next’) or (ENTER after first n)
q– quit the debugger (‘quit’)
R– start the script from the beginning (‘restart’)
x– examine a variable
p– print the value of a variable
s– step into a function
r– return from a function
c– continue execution
l [line|sub]– list source code
v [line]– view around line
.– list current line
f [file]– view source in a file
b– set a breakpoint (current line)
b [sub]– set a breakpoint (specified function)
b [line]– set a breakpoint (specified line)
B [line]– clear a breakpoint for line
B *– clear all breakpoints
L– list break/watch/actions