Featured post
In perl, what is the difference between $DB::single = 1 and 2? -
what difference between putting $db::single=1
, $db::single=2
in code? both seem have identical effect of halting execution @ statement following assignment when 'c' on perl debugger command line.
perldebug
says value of 1 equivalent having pressed 's' next statement, , 2 same 'n', difference make how got statement?
from perldebug
:
if set $db::single
2
, it's equivalent having typed n
command (which executes on subroutine calls), whereas value of 1
means s
command (which enters subroutine calls).
that know already.
from user point of view, i'm pretty sure there no difference. base on examination of actual db.pm
source code.
let's follow logically. may want refer source code. i've simplified of code remove unnecessary detail should able idea descriptions.
when executing code in debugger, there (at least) 2 important variables, running
, single
. combination of these decides whether code run:
running single description ------- ------ ----------- 0 ? not running 1 0 running flat-out 1 1 single stepping, execute function 1 2 single stepping, execute on function
the db()
function executed every single line, , contains following snippet stop running if single
has been set (it executes current line regardless):
if ($db::single) { $db::single = 0; $running = 0; }
that's why, if set variable in perl code, break (by break, mean "stop running code", not "damage somehow") debugger @ next line.
when running
0
, db()
function enters little loop:
# sit in event loop until sets $running { $c->idle; # call client event loop; must not block } until $running;
in other words, waits on user command sets running
1
. can done 1 of following 3 functions:
sub next { $db::single = 2; $running = 1; } sub step { $db::single = 1; $running = 1; } sub cont { $db::single = 0; $running = 1; }
you can see these 3 commands set different combination of single
, running
used while executing next perl line (see earlier table see these combinations mean).
the ability use either 1
or 2
in perl code direct result of fact you're using sneaky clever trick break execution perl code itself, setting variable set debugger command.
that's why it's not value matters fact you're forcing debugger particular state.
- Get link
- X
- Other Apps
Comments
Post a Comment