debugging - Invoking Perl debugger so that it runs until first breakpoint -
when invoke perl debugger perl -d myscript.pl, debugger starts, not execute code until press n (next) or c (continue).
is there anyway invoke debugger , have run through code default until hits breakpoint?
if so, there statement can use in code breakpoint have debugger stop when hits it?
update:
here have in .perldb file:
print "reading ~/.perldb options.\n"; push @db::typeahead, "c"; parse_options("nonstop=1"); here hello_world.pl file:
use strict; use warnings; print "hello world.\n"; $db::single=1; print "how you?"; here debugging session running: perl -d hello_world.pl:
reading ~/.perldb options. hello world main::(hello_world.pl:6): print "how you?"; auto(-1) db<1> c debugged program terminated. use q quit or r restart, use o inhibit_exit avoid stopping after program termination, h q, h r or h o additional info. db<1> v 9563 9564 9565 sub at_exit { 9566==> "debugged program terminated. use `q' quit or `r' restart."; 9567 } 9568 9569 package db; # not trace 1; below! db<1> in other words, debugger skips print "how you?", , instead stops once program finishes, not want.
what want have debugger run code without stopping anywhere (nor @ beginning, nor @ end of script), unless explicitly have $db::single=1; statement, in case stop before running next line. ways this?
for reference, using:
$perl --version perl 5, version 14, subversion 1 (v5.14.1) built x86_64-linux
put
$db::single = 1; before statement set permanent breakpoint in code. works compile-time code, too, , may way set breakpoint during compile phase.
to have debugger automatically start code, can manipulate @db::typeahead array in either .perldb file or in compile-time (begin) block in code. example:
# .perldb file push @db::typeahead, "c"; or
begin { push @db::typeahead, "p 'hello!'", "c" } ... $db::single = 1; $x = want_to_stop_here(); there "nonstop" option set in .perldb or in perldb_opts environment variable:
perldb_opts=nonstop perl -d myprogram.pl all of (and more) discussed deep in bowels of perldebug , perl5db.pl
update:
to address issues raised in recent update. use following in ./perldb:
print "reading ~/.perldb options.\n"; push @db::typeahead, "c"; parse_options("inhibit_exit=0");
Comments
Post a Comment