Debguts and Perl

So I’m working on a bugfix for some code of mine, and I really need to see why something is happening, and I pull it up in the Perl debugger. as I’m stepping through a very long set of actions, validation all the different data at various points, I come to a fork that explains a lot of my problems. Great, now I want to continue along this branch and verify things are happening, but the first part of this fork is a method call that I really don’t want to do. Now it’s safe, I’m running in a sandbox and I can screw up the data all I want, but it took quite a while to get to the point that I’m at, I haven’t saved out all by watches and breakpoints yet, and I really just want to continue, without running this first piece of code. It’ll just make me spend more time than I want to at that point.

Anybody else ever wanted to ‘Skip’ in your debugger? Well, I presented this question to a few coworkers who all agreed that they didn’t know of a way to do it, when suddenly Paul mentioned, “Well, if you could just change the symbol tree”. “Harleypig’s”: eyes then lit up thinking about the possibilities there.

So I made the suggestion to try on the fly replacing the subroutine in the object’s namespace with a new one, and Harleypig was already pulling up a terminal to start playing.

I think he’ll be posting his test code here very shortly, but suffice it to say, it works well. Inside the debugger we just dropped a new anonymous sub in the namespace, in that case clobbering the routine we wanted to modify. (*Namespace::Sub = sub { … }; ) It would be just as easy to move the old one, substitute the new routine, then move it back afterwards.

All sorts of insidious evil. A day in the life of a programmer. I love languages that allow you to dynamically rewrite a running program.

This entry was posted in Geeky.