Can I insert break point into source perl program?

前端 未结 4 1230
臣服心动
臣服心动 2021-02-12 20:00

I want the perl program launch debugger when some condition hit. Some other language has debug() statement supported by library, is there any similar statement in perl?

相关标签:
4条回答
  • 2021-02-12 20:43

    If I understand you correctly, you need to use a specific debugger variable in your code - $DB::single. Setting this to a true value in your code will cause the debugger to stop on that line.

    $x = 1234;
    $DB::single = 1;
    enter_problematic_sub_now();
    

    Your code will then stop at the line with $DB::single set to 1.

    Of course, if you can't actually ensure that your code is running in the debugger then you have another problem entirely. You will need to run your code via perl -d as well.

    0 讨论(0)
  • 2021-02-12 20:57

    Essentially the -d switch allows you to communicate with the perl executable, and allows the perl executable to communicate with you.

    More

    0 讨论(0)
  • 2021-02-12 21:01

    Have you tried adding the -d switch to the shebang line at the top of your script? Something like

    #!/usr/bin/perl -d
    use strict;
    use warnings;
    $|=1;$\="\n";
    
    print "Test";
    

    It really depends exactly how it gets launched, but at least in simple cases this should start the debugger.

    Edit: You can then set a breakpoint on a specific line with a certain condition using

    > b [line] [condition]
    

    and hit

    > c
    

    to continue with running the script - the debugger will stop at the specified line when the condition is met

    0 讨论(0)
  • 2021-02-12 21:02

    Well, there is something which will enable you to do something like breakpoints, but the functionality is wider: Perl Debugger.

    0 讨论(0)
提交回复
热议问题