Introducing Devel::Nopeep, Devel::GDB::Breakpoint, and Devel::GDB::Parser::Breakpoint

I've created 3 new modules to help me out when working on the Perl core; I'm sharing them in the event others find them useful.

They are:

Devel::Nopeep

This module disables the peephole optimiser so that you can see what the op tree would look like before it works its magic (and benchmark the differences, if you like).

For example:

$ perl -MO=Concise -e 'if ($a && $b) {}'
8  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 3 -e:1) v:{ ->3
-     <1> null vK/1 ->8
6        <|> and(other->7) vK/1 ->8
-           <1> null sK/1 ->6
4              <|> and(other->5) sK/1 ->8
->                  <1> ex-rv2sv sK/1 ->4
3                    <$> gvsv(*a) s ->4
-                 <1> ex-rv2sv sK/1 ->-
5                    <$> gvsv(*b) s ->6
-           <@> scope vK ->-
7              <0> stub v ->8
-e syntax OK

Versus:

$ perl -MDevel::Nopeep -MO=Concise -e 'if ($a && $b) {}'
a  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 3 -e:1) v:{ ->3
-     <1> null vK/1 ->a
8        <|> and(other->9) vK/1 ->-
-           <1> null sK/1 ->8
5              <|> and(other->6) sK/1 ->-
4                 <1> rv2sv sK/1 ->5
3                    <$> gv(*a) s ->4
7                 <1> rv2sv sK/1 ->-
6                    <$> gv(*b) s ->7
-           <@> scope vK ->-
9              <0> stub v ->-
-e syntax OK

Devel::GDB::Breakpoint

This module lets you set breakpoints in your Perl code that you can easily match up to with gdb. If you have a large program and you want to break in different places, you can:

use Devel::GDB::Breakpoint;

breakpoint 3;
breakpoint 4;

And then with gdb:

$ gdb --args perl prog.pl
(gdb) b bp if val == 3
(gdb) b bp if val == 4
(gdb) run

Each Perl call to breakpoint sets up a call to the C function void bp(int val); that will be called at runtime.

Devel::GDB::Parser::Breakpoint

This module builds off of Devel::GDB::Breakpoint and allows you to set breakpoints that will be triggered when perl parses the code in question, way before it ever runs it (think BEGIN {}).

For example:

use Devel::GDB::Parser::Breakpoint;

if ($a && $b && parser_breakpoint 42 && $c) { }

And then like above:

$ gdb --args prog.pl
(gdb) b bp if val == 42
(gdb) run

I'll be spending a lot more time playing with Perl and might have some more things to share in the near future.

Cheers,

-- Matthew Horsfall (alh)

Leave a comment

About Matthew Horsfall (alh)

user-pic I blog about Perl.