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.4Example 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 WDB with this command (ksh shell):

TERM=hpterm gdb mysum

148 HP-UX Configuration-Specific Information

Page 148
Image 148
HP gnu source-level debugger 5992-4701 manual Example Fix and Continue session, Compile the program, Run the program