Perl | Line Action Commands in a Debugger
Last Updated :
11 Nov, 2019
Debugger in Perl provides us the feature of Line Action Commands, but before going deep into them lets first talk what actually actions are: so an action is basically an instruction that is given to the debugger to execute it whenever it reaches a particular line. The reason behind getting these actions performed is to make the debugging easy.
For example
$i = 0;
for ( $i = 0; $i <= 9; $i ++)
{
}
print ( $i );
|
Above is a basic program of for loop. Now if we specify a line action at line 4 asking the debugger to print the value of i after each iteration then we could check that whether the loop is executing correctly or not. So in this way, they help in debugging.
Thus to specify these line actions Perl Debugger provides you the feature of Line Action Commands. These commands help in specifying the line actions. The Line Action Commands are the statements that we specify to be executed whenever the program execution reaches a specified line. The most common line actions are printing the value of a variable and resetting an incorrect value of the variable to the desired value.
The following are the line action commands:
- ‘a’ command
- ‘A’ command
- ‘<‘ command
- ‘>’ command
‘a’ Command
The 'a' command
specifies an action for a particular line of code. This action can be any valid Perl command. The specified action will be performed every time the specified line is executed.
Syntax
a line no. command to be executed [condition]
If no line is specified, then by default the action is performed every time the current line is executed.
Example:

Output:

Explanation:
In the above example, the debugger executes the above line as soon as it reaches the ninth line. Thus the above statement will be displayed by the debugger.
To create line actions with multiple lines just specify the statements one after the other. In case you need more than one line to write the complete action to be performed use ‘\’ at the end of first-line.
Example:

Output:

You can also specify a condition(It is optional) for the execution of the action. Firstly this condition will be evaluated and then if the result is true then only action will be performed for the specified line, else no action will be performed.
In default cases, when there is no condition, it is considered by the debugger that the condition is already TRUE. Hence, the action is performed every time the execution reaches the specified line.
Note:
There can be only one action per line.
‘A’ Command
The 'A' command
is used to delete line actions that were previously specified using 'a' command
. It deletes the line action for the line specified in the command.
Syntax:
A lineno.;
Example:

In above example, the line action specified for line 11 will be deleted.
Please note that in versions of Perl prior to 5.6.1, the 'A' command
deletes all the specified line action.
In version Perl 5.6.1 and after, all the actions are deleted only when the asterisk is given as an argument.
Example

< and > commands
The < and > commands
are useful when you know that one of the variables has the wrong value, but you don’t have any idea about which statement assigns the wrong value to the variable. Thus, by using the < and > command
you can print the value of a variable before and after the execution of a statement.
< command
The '<' command
is used to specify a line action to be performed after the Perl debugger has finished executing statements and before the debugger further demands for more debugging statements.
Syntax:
< action to be performed;
Example:

Output:

The command given in the above example tells the Perl Debugger to print the specified statement before it again halts the execution of the program and starts debugging.
> command
The '>' command
is used to specify an action to be performed before executing further statements of the code. Thus, the action will be performed after a certain line of code is executed,
Syntax:
> action to be performed;
Example:

Output

To delete an action specified using < and > command
, just re-enter the command used to specify the action.
DB<8> < ;
This will delete the action specified using < command
.
DB<9> > ;
This will delete the action specified using > command
.
Displaying Line Actions Using the ‘L’ Command
The 'L' command
is used to display breakpoints, actions and watchpoints. Thus helping the user to see what all actions, breakpoints, and watchpoints are there in the code. Let us now learn how it is used to display the actions.
Example:
DB<3> L a;

The use of 'L' command
to display action benefits in debugging. For example: If you want to delete a specific action but you don’t know which line it corresponds to. So, you can use the first 'L' command
to display all the actions and then use the 'A' command
to delete the desired action.
Similar Reads
Perl | Breakpoints of a Debugger
Controlling program execution in Perl can be done by telling the debugger to execute up to a certain specified point in the program, called a breakpoint. These breakpoints enable the user to divide the program into sections and look for the errors. Following are some commands in a debugger which are
7 min read
What is Command Line Interface (CLI)?
Command Line Interface is used to communicate with a computer program, you can input text into a by typing command lines. In this article, we will understand the workings of the command line interface, features of the command line interface, and more. What is the Command Line Interface?Command line
6 min read
bind command in Linux with Examples
bind command is a Bash shell builtin command. It is used to set Readline key bindings and variables. The keybindings are the keyboard actions that are bound to a function. So it can be used to change how the bash will react to keys or combinations of keys, being pressed on the keyboard. Here, weâll
4 min read
addr2line command in Linux with Examples
'addr2line' command in Linux is used to convert addresses into file names and line numbers. When the executable files/object files are run with the 'objdump' command, the file is de-assembled and the machine code is displayed. These machine instructions for the executable are displayed along with th
4 min read
Is there a TRY CATCH command in Bash?
Bash is a powerful scripting language used in the Unix and Linux environments, primarily for automating tasks and scripting. While Bash doesn't have a built-in 'TRY CATCH' command like some other programming languages, you can achieve similar functionality using a combination of 'trap', the '-x' fla
4 min read
Command Pattern | C++ Design Patterns
The Command Pattern is a behavioral design pattern that focuses on encapsulating a request as an object, thereby decoupling the sender of the request from the receiver. This pattern allows you to parameterize objects with commands, delay or queue a request's execution, and support undoable operation
7 min read
Gedit Command in Linux
In the world of Linux, efficient text editing is paramount for developers, system administrators, and everyday users alike. One of the most versatile and user-friendly text editors available is Gedit. Gedit, short for GNOME Editor, is a powerful text editor that comes pre-installed on many Linux dis
4 min read
Command Line Arguments in Objective-C
In Objective-C, command-line arguments are strings of text that are passed to a command-line program when it is launched. They can be used to specify options or parameters that control the behavior of the program or to provide input data that the program can process. To access command-line arguments
2 min read
Perl - Introduction to Debugger
Sure, here's an introduction to the debugger in Perl: The Perl debugger is a tool that helps you find and fix bugs in your Perl programs. It allows you to step through your code one line at a time, examine variables and expressions, set breakpoints, and much more. The debugger can be used in both co
9 min read
How to Use Cloud Debugger For Debugging Applications On GCP?
Application debugging is a crucial step in the development process since it enables developers to quickly find and fix problems. Developers can debug their applications running on the Google Cloud Platform (GCP) with the help of a potent tool called Cloud Debugger without interfering with their regu
4 min read