I have a question about the output that I'm getting from a simple custom Perl debugger.
If I have a simple Perl debugger like this example:
package DB
{
sub DB {}
sub sub
{
my ($package, $filename, $line_num, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) = caller(0);
print "$package $DB::sub\n";
&$DB::sub;
}
}
1;
And I run it on a simple program like the following (invoked via perl -d test.pl):
#!/usr/bin/env perl
use strict;
use warnings;
sub hello
{
print "hello world\n";
}
&hello;
And the output is along the lines of the following:
main CODE(0x1431a90)
main strict::import
main strict::bits
main CODE(0x1431be0)
main warnings::import
main::hello
hello world
My question is:
What does the "CODE(0x1431a90)" part represent? It seems to represent the main body of the program - since there is no subroutine at the topmost level, this seems to be a memory reference to the main execution of the program.
What assumptions can I make about what "CODE(...)" means when I see it being printed out by my debugger? Is it always this "main" code path? Are there any other special Perl variables that I can use to interpret where the program is at that point?
Thanks!
EDIT - revised example 1:
In reference to the discussion in the comments, adding additional example:
#!/usr/bin/env perl
use strict;
use warnings;
sub hello
{
print "hello world\n";
}
&hello;
print "hi from main\n";
And output:
main CODE(0x22f0a90)
main strict::import
main strict::bits
main CODE(0x22f0be0)
main warnings::import
main::hello
hello world
hi from main
It is a code reference, and probably an anonymous one. See the coderef2text method in B::Deparse to get at (an approximation of) the actual source code, and display the file and linenumber (which you are already extracting from caller) to find where the sub is called from.
Running B::Deparse::coderef2text on your sample script, the code references resolve to
require strict;
do {
'strict'->import
};
and
use strict 'refs';
require warnings;
do {
'warnings'->import
};
meaning they are generated and called by perl from your use strict and use warnings statement.
CODE(0x1431a90) is stringification of code reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With