Debugging with GDB Manual HP WDB v6.3 (5900-2180, August 2012)
changed, HP WDB asks if you want to fix the changed source, allowing you to apply repeated
fixes without explicitly entering the fix command.
The Fix and Continue facility enables you to make the following changes:
• Change existing function definitions.
• Disable, reenable, save, and delete redefinitions
• Adding global and file static variables.
• Add new structure fields to the end of a structure type object.
• Set breakpoints in and single-step within redefined code.
NOTE: You must rebuild the program after you use the fix command because the changes you
make are temporarily patched into the executable image. The changes are lost if you load a
different executable and are not re ected in the original executable when you exit the debugger.
14.7.4 Example Fix and Continue session
This example shows how you can make and test changes to a function without leaving the debugger
session.
Here is a short sample C program with an error:
int sum (num) int num;
{
int j, total = 0;
for (j = 0; j <= num; j++)
total += num;
}
main()
{
int num = 10;
printf("The sum from 1 to %d is = %d\n", num, sum(num));
}
1. Compile the program.
cc sum.c -g -o mysum
/usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file
(sum.o) was detected.
The linked output may not run on a PA 1.x system.
2. Run the program.
./mysum
The sum from 1 to 10 is = 0
This result is obviously wrong. We need to debug the program.
3. Run the debugger:
gdb mysum
HP gdb 3.0 for PA-RISC 1.1 or 2.0 (narrow), HP-UX 11.00.
Copyright 1986 - 2001 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest 3.0 (based on GDB ) is covered by the
GNU General Public License. Type "show copying" to see the
conditions to change it and/or distribute copies. Type
"show warranty" for warranty/support.
If the TERM environment variable is not set to hpterm, start the debugger and set the terminal
type for editing in HP WDB with this command (ksh shell):
TERM=hpterm gdb mysum
The problem might be that there is no return for the num function. You can correct this without
leaving the debugger.
14.7 Fix and continue debugging 113