Calling the Perl Debugger to Run Before the First Breakpoint

When I call my Perl debugger with perl -d myscript.pl , the debugger starts, but it does not execute any code until I press n (next) or c (continue).

Is there anyway to call the debugger and run the default code until it reaches the breakpoint?

If so, is there any statement that I can use in my code as a breakpoint to stop the debugger when it hits it?

Update:

Here is what I have in the .perldb file:

 print "Reading ~/.perldb options.\n"; push @DB::typeahead, "c"; parse_options("NonStop=1"); 

Here is my hello_world.pl file:

 use strict; use warnings; print "Hello world.\n"; $DB::single=1; print "How are you?"; 

Here is a debugging debugging session: perl -d hello_world.pl :

 Reading ~/.perldb options. Hello world main::(hello_world.pl:6): print "How are you?"; auto(-1) DB<1> c Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, hq, h R or ho to get additional info. DB<1> v 9563 9564 9565 sub at_exit { 9566==> "Debugged program terminated. Use `q' to quit or `R' to restart."; 9567 } 9568 9569 package DB; # Do not trace this 1; below! DB<1> 

In other words, my debugger skips the print "How are you?" and instead stops after the program ends, which I don’t want.

I want the debugger to execute my code without stopping anywhere (neither at the beginning nor at the end of my script) , if I explicitly have the $DB::single=1; operator $DB::single=1; , in which case I would like it to stop before starting the next line. Any ways to do this?

For reference, I use:

 $perl --version This is perl 5, version 14, subversion 1 (v5.14.1) built for x86_64-linux 
+6
source share
2 answers

Placed

 $DB::single = 1; 

before any statement, set a constant breakpoint in the code. This also works with compile-time code and may be the only good way to set a breakpoint at compile time.


In order for the debugger to automatically run your code, you can manipulate the @DB::typeahead in the .perldb file or in the compile-time block ( BEGIN ) in the code. For instance:

 # .perldb file push @DB::typeahead, "c"; 

or

 BEGIN { push @DB::typeahead, "p 'Hello!'", "c" } ... $DB::single = 1; $x = want_to_stop_here(); 

There is also the "NonStop" option, which you can set in .perldb or in the PERLDB_OPTS environment PERLDB_OPTS :

 PERLDB_OPTS=NonStop perl -d myprogram.pl 

All this (and much more) is discussed deep in the bowels of perldebug and perl5db.pl

Update:

To fix the issues that were raised in the latest update. In ./perldb do the following:

 print "Reading ~/.perldb options.\n"; push @DB::typeahead, "c"; parse_options("inhibit_exit=0"); 
+12
source

Also check out Enbugger . And while on the topic of debuggers, see Devel :: Trepan , which also works with Enbugger.

+2
source

Source: https://habr.com/ru/post/944153/


All Articles