| Previous | Contents | Index |
The pop command removes one or more execution frames from the call stack. The pop command undoes the work already done by the removed execution frames. It does not, however, reverse side effects such as changes to global variables. You may need to use the assign command to restore the values of global variables.
The pop command is useful when execution has already passed an error that needs to be corrected.
The following fragment of a debugger session shows the use of the pop command:
Reading symbolic information ...done
(ladebug) bp factorial
[#1: stop in int factorial(int) ]
(ladebug) r
Factorial time has begun.
[1] stopped at [factorial:30 0x120001524]
30 printf("entered factorial\n");
(ladebug) where
>0 0x120001524 in factorial(ii=1) c_listfunc_factorial.c:30
#1 0x12000140c in main() c_listfunc.c:41
(ladebug) pop
[1] stopped at [main:41 0x120001410]
41 f = factorial(i);
(ladebug) c
[1] stopped at [factorial:30 0x120001524]
30 printf("entered factorial\n");
|
To attach or detach a running process, choose Commands:Attach to Process... or Detach from Process... and select the process.
From the command interface, use the attach command followed by the process ID and image file name.
After Ladebug attaches to a process, control is returned to the debugger when the process stops (for example, after having received a signal). You can also manually return control to the debugger by pressing Ctrl/C or by setting the debugger variable $stoponattach to 1 to stop the attached process.
Use the detach command to detach the debugger from the previously attached process, based on the process ID you specify. Ladebug only detaches the specified process and removes all the user-specified breakpoints from that process.
The following restrictions apply when you debug an attached process:
See Chapter 9 for more information about multiple processes.
3.3 Setting Breakpoints to Suspend Execution
This section is divided into the following parts:
A breakpoint is a location in your program at which you want execution to stop so that you can perform some action such as checking the current value of a variable, stepping into a routine, etc. You can set breakpoints on:
A breakpoint with no condition associated with it can be set by using the Break menu, but it is often simpler to click on the toggle push button in the source display.
You can also qualify breakpoints as follows:
You can set a breakpoint that is both a conditional and an action
breakpoint. The following sections explain these breakpoint options.
3.3.1 Identifying Currently Set Breakpoints
There are three ways to determine which breakpoints are currently set:
Figure 3-1 Breakpoint View with Action and Condition
Example 3-9 uses the status command to display active breakpoints in a COBOL program.
| Example 3-9 Using the status Command to Display Breakpoints |
|---|
(ladebug) status
#1 PC==0x120001e14 in testa "testa.cob":2 {break}
#2 PC==0x120001ba4 in TESTB "testa.cob":47 {break}
#3 PC==0x120001c1c in TESTB "testa.cob":50
{print CHARS of HOLD-CHARS; print SUB-1; ; cont ; ; }
|
You can set a breakpoint on any source line that has a toggle button to its left in the source pane. These are the lines for which the compiler has generated executable code (for example, routine declarations, assignment statements).
To set a breakpoint on a source line:
Figure 3-2 shows that a breakpoint has been set on the start of line 14.
Figure 3-2 Setting a Breakpoint on a Source Line
To set a breakpoint in the Instruction View:
Table 3-1 lists the commands you can use in the command interface for setting breakpoints.
| Command | Description |
|---|---|
| stop | Without a variable argument, suspends program execution and returns to the prompt. With a variable argument, suspends program execution when a variable changes. |
| stop at | Suspends execution when a specific line number is encountered. |
| stop in | For C++ programming; see the Command Reference for specific forms of this command. |
| stop if | Suspends execution when an expression evaluates to true. |
| stopi, stopi if, stopi at | For machine-level debugging; suspends program execution when the specified variable value changes, when an expression evaluates to true, or when a specified address is encountered. |
The stopi, stopi if, and stopi at commands are specifically used for machine-level debugging. As such, breakpoints are set based on machine instruction addresses rather than line numbers. For more information on machine-level debugging, see Chapter 15. |
Example 3-10 shows how to set a breakpoint on a variable.
| Example 3-10 Setting a Breakpoint on a Variable |
|---|
(ladebug) stop i
[#2: stop if i changes ]
(ladebug) run
[1] stopped at [main:4 0x120000b14]
4 for (i=1 ; i<3 ; i++) {
(ladebug) print i
0
(ladebug) cont
Value of i changed before "sample.c":13
Old value = 0
New value = 1
[2] stopped at [factorial:13 0x120000bb8]
13 if (i<=1)
(ladebug) print i
1
(ladebug)
|
Example 3-11 sets a breakpoint at line number 13 of the current source file.
| Example 3-11 Setting a Breakpoint at a Line in C Source Code |
|---|
(ladebug) stop at 13
[#1: stop at "sample.c":13 ]
(ladebug) run
[1] stopped at [factorial:13 0x120001224]
13 if (i<=1)
(ladebug)
|
| Example 3-12 Setting a Breakpoint at an Address in the Source Code |
|---|
(ladebug) stopi at 0x120000b14
[#1: stopi at 4831841044 ]
(ladebug) run
[1] stopped at [main:4 0x120000b14]
4 for (i=1 ; i<3 ; i++) {
(ladebug)
|
Example 3-13 shows how to set a breakpoint in a function.
| Example 3-13 Setting a Breakpoint in a Function |
|---|
(ladebug) stop in factorial
[#1: stop in factorial ]
(ladebug) run
[1] stopped at [factorial:13 0x120001224]
13 if (i<=1)
(ladebug)
|
In Example 3-14 the stop in command sets a breakpoint at the beginning of an Ada program procedure named add_integers.
| Example 3-14 Setting a Breakpoint at the Start of an Ada Procedure |
|---|
(ladebug) stop in add_integers
[2] stop in add_integers
(ladebug)run
[2] stopped at [add_integers:3 +0x20002a69,0x120002a68]
procedure add_integers is
|
With Version 4.0 (or higher) of the debugger, the stopi in command is no longer valid, and results in an error message. Replace stopi in in your code with stopi at for an address or stop in for a routine. |
Example 3-15 shows how to set a breakpoint with a user-defined expression.
| Example 3-15 Setting a Conditional Breakpoint |
|---|
(ladebug) stop if (iter==2)
[#1: stop if iter==2 ]
(ladebug) run
[1] stopped at [doit:20 0x120000e14]
20 ++iter;
(ladebug) print iter
2
(ladebug)
|
In this example, the breakpoint is activated only when the program variable iter equals 2.
Example 3-16 creates a breakpoint that stops only if the program is executing the factorial function and the program variable i is equal to 2.
| Example 3-16 Setting a Conditional Breakpoint in a Function |
|---|
(ladebug) stop in factorial if (i==2)
[#1: stop in factorial if i==2 ]
(ladebug) run
1! = 1
[1] stopped at [factorial:13 0x120000bb8]
13 if (i<=1)
(ladebug) print
2
(ladebug)
|
Within the debugger, the terms deactivate and activate are synonymous with disable and enable. Deactivate and activate are used in the GUI; disable and enable are used in the command interface.
Deactivating a breakpoint causes the debugger to ignore the breakpoint during program execution. However, the debugger keeps the breakpoint listed in the Breakpoint View so that you can activate it at a later time, for example, when you rerun the program (see Section 1.6.6). The following are procedures to deactivate or activate breakpoints:
You can enter commands in the command interface to enable and disable breakpoints, tracepoints, (see Section 3.4) and watchpoints (see Section 3.5). It is written in terms of breakpoints but all of these commands are also applicable to tracepoints and watchpoints.
To list all the breakpoints known to the debugger, enter the status command.
To delete, disable, or enable a breakpoint, identify the breakpoint by its reference number. When breakpoints are created, they are associated with a reference number. This reference number is shown when:
When you disable a breakpoint, the debugger ignores the breakpoint during program execution. A disabled breakpoint does not cause the program to suspend execution.
You can use the disable and enable commands in the command interface to disable and enable breakpoints.
The disabled breakpoint is still displayed by the status command, but it is listed as disabled. Example 3-17 shows breakpoints being disabled.
| Example 3-17 Disabling Breakpoints |
|---|
(ladebug) status
#1 PC==0x120000b14 in main "sample.c":4 { break }
#2 PC==0x120000bb8 in factorial "sample.c":13 { break }
#3 PC==0x120000b14 in main "sample.c":4 { break }
(ladebug) disable 1
(ladebug) status
#1 PC==0x120000b14 in main "sample.c":4 { break } Disabled
#2 PC==0x120000bb8 in factorial "sample.c":13 { break }
#3 PC==0x120000b14 in main "sample.c":4 { break }
(ladebug) disable 2,3
(ladebug) status
#1 PC==0x120000b14 in main "sample.c":4 { break } Disabled
#2 PC==0x120000bb8 in factorial "sample.c":13 { break } Disabled
#3 PC==0x120000b14 in main "sample.c":4 { break } Disabled
(ladebug)
|
Disabled breakpoints remain disabled until you enter the enable command to enable the breakpoint.
Example 3-18 shows the breakpoints that were disabled earlier and then reactivated with the enable command.
| Example 3-18 Enabling Breakpoints |
|---|
(ladebug) status
#1 PC==0x4001b8 in main "sample.c":4 { break } Disabled
#2 PC==0x400250 in factorial "sample.c":13 { break } Disabled
#3 PC==0x4001b8 in main "sample.c":4 { break } Disabled
(ladebug) enable 2
(ladebug) status
#1 PC==0x4001b8 in main "sample.c":4 { break } Disabled
#2 PC==0x400250 in factorial "sample.c":13 { break }
#3 PC==0x4001b8 in main "sample.c":4 { break } Disabled
(ladebug) enable all
(ladebug) status
#1 PC==0x4001b8 in main "sample.c":4 { break }
#2 PC==0x400250 in factorial "sample.c":13 { break }
#3 PC==0x4001b8 in main "sample.c":4 { break }
(ladebug)
|
A breakpoint that has been reactivated with the enable command appears as an active breakpoint
in the status list. Note that the last status list in this example is
the same as the first status list in the preceding example (except for
the PC values), showing three active breakpoints.
3.3.3 Setting Breakpoints on Routines
The Browse Source dialog box displays hierarchical information about all the binary files in your application. For each binary file, it displays information about the modules contained in the binary. For each module, you can display a list of routines in that module.
Setting a breakpoint on a routine enables you to move execution directly to the routine and inspect the local environment.
To set a breakpoint on a routine:
In the source pane, the toggle button to the left of the source line that contains the start of the routine is now filled in, confirming that the breakpoint is set. (If the Instruction Window is open, the breakpoint will also display for the corresponding instruction.)
Figure 3-3 Setting a Breakpoint on a Routine
A conditional breakpoint suspends execution only when a specified expression is evaluated as true. For example, you can specify that a breakpoint take effect when the value of a variable in your program is 4. The breakpoint is ignored if the value is other than 4.
The debugger evaluates the conditional expression when the breakpoint triggers during execution of your program.
To set a conditional breakpoint:
at line 10 in factorial.c in routine seven at address 0x01024b |
Figure 3-4 Setting a Conditional Breakpoint
The following procedure modifies a conditional breakpoint; it can be used to change the location or condition associated with an existing conditional breakpoint, or to change an unqualified breakpoint into a conditional breakpoint:
You can enter the when and wheni commands in the command interface to set breakpoints at function entry points that execute debugger commands, (rather than suspend program execution) when the specified conditions are satisfied.
Example 3-19 creates a breakpoint that prints a stack trace when line 16 is reached.
| Example 3-19 Setting a Breakpoint That Executes a Stack Trace |
|---|
(ladebug) when at 16 {where}
[#1: when at "sample.c":16 { where } ]
(ladebug) run
1! = 1
[1] when [factorial:16 0x12000123c]
>0 0x12000123c in factorial(i=2) sample.c:16
#1 0x120001194 in main() sample.c:5
2! = 2
Thread has finished executing
(ladebug)
|
Example 3-20 creates a breakpoint that displays the contents of the expression HOLD-CHARS and SUB-1 in a COBOL program when line 50 is reached and then resumes execution.
| Example 3-20 Setting a Breakpoint That Executes Multiple Commands |
|---|
(ladebug) when at 50 {print chars of hold-chars; print SUB-1; cont;}
[#3 when at "testa.cob":50 ( print CHARS of HOLD-CHARS; print SUB-1; ; cont ; } ]
|
| Previous | Next | Contents | Index |