Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a perl program starting from a specific line?

Environment: Linux CentOS 7 @HPC Interface: command interface, no GUI

My PERL scripts have a logic error. It does not go through in a "foreach" loop. I use debugger command below:

perl -d /scripts_location/perlscripts.pl

However, it is run step by step. My scripts have almost thousand lines. Here is my questions:

  1. How to debug my scripts from specific line?

  2. How to figure out the loop cannot be run? And why the loop cannot be run?

  3. Is there any resource to show debugger skills in a whole process?

    I searched online. Most of them explain the commands. But few introduce the debug from the very beginning. I mean that first a simple program is given, set breakpoint or other label in the program, check output or trace error, and so on. After viewing websites, I am unable to know how to start debugging using PERL debugger. I used to debugging my program using output at specific lines to check the output is correct or not. However, current logic error cannot be figured out in this way.

  4. Any further suggestion and help would be highly appreciated.

like image 470
Leon Avatar asked Nov 16 '18 17:11

Leon


1 Answers

  1. After starting the debugger, you can tell it to continue until it reaches a given line, e.g.

    c 124
    
  2. To figure out why a foreach loop isn't entered, check the loop's list before entering it. You can tell the debugger to evaluate the expression like this:

    x @values
    

    if the loop is something like foreach my $value (@values). It will probably tell you

    empty array
    

    To discover why the array is emtpy, you can try to "watch" the array

    w @values
    

    and then run the script with r. It will stop once any watched value changes.

  3. Use h to view the help.

like image 82
choroba Avatar answered Oct 05 '22 11:10

choroba