How to set breakpoint on a particular file in Perl program?

前端 未结 2 907
南旧
南旧 2021-02-02 10:23

My Perl program looks like:

foo/
foo/bar/
for/bar/test.pm
foo.pm
foo/bar.pm
test.pl

and use perl test.pl to start the program. I

相关标签:
2条回答
  • 2021-02-02 10:51

    To debug a perl script, use the -d switch to invoke the debugger.

    perl -d test.pl
    

    Within the debugger you can use b <line no> to set a breakpoint in the current file. Sometimes it is a hassle to set a breakpoint in a file that hasn't been loaded yet or that was loaded a long time ago, so you can also put the line

    $DB::single = 1;
    

    anywhere in any perl program, and the debugger will break immediately after it executes that line. This is also a good way (the only way?) to set a breakpoint in code that will be run at compile time.

    0 讨论(0)
  • 2021-02-02 10:58

    Just use the fully qualified name of the sub as the argument to b:

    b foo::bar::test::subname
    

    Example:

    $ perl -d -e'use CGI; CGI->new'
    ...
    main::(-e:1):   use CGI; CGI->new
      DB<1> b CGI::new
      DB<2> r
    CGI::new(.../CGI.pm:337):
    337:      my($class,@initializer) = @_;
      DB<2> q
    
    0 讨论(0)
提交回复
热议问题