Created
March 31, 2012 12:26
-
-
Save Ovid/2263374 to your computer and use it in GitHub Desktop.
How to lie to the debugger about what its lines of code are
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lie to the debugger about what the lines of code are | |
no strict 'refs'; | |
my $line_num = 0; | |
foreach ( @{"::_<$filename"} ) { | |
# uncomment these to blow your f'in mind | |
#if ( not defined ) { | |
# use Devel::Peek; | |
# warn "line number is $line_num"; | |
# Dump($_); | |
#} | |
# The debugger special cases the first value in ::_<$filename. | |
# It's "undef" but sometimes contains some data about the | |
# program. I don't know entirely what it is, but this solves | |
# the "off by one" bug. | |
next unless defined; # thanks Liz! (why does this work?) | |
my $line = $lines->[ $line_num++ ]; | |
next unless defined $line; # happens when $_ = "\n" | |
my $numeric_value = 0 + $_; | |
# Internally, the debugger uses dualvars for each line of | |
# code. If it's numeric value is 0, then the line is not | |
# breakable. If we don't include this, no lines in the | |
# debugger are breakable. | |
$_ = dualvar $numeric_value, $line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment