Debugging with GDB (September 2007)
Chapter 14: HP-UX Configuration-Specific Information 123
}
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
The problem might be that there is no return for the num function. You can correct
this without leaving the debugger.
4. Set a break point at main:
(gdb) b main
Breakpoint 1 at 0x23f8: file sum.c, line 11.
5. Run the program:
(gdb) run
Starting program: /tmp/hmc/mysum
Breakpoint 1, main () at sum.c:11
11 int num = 10;
6. When the program stops at the break point, use the edit command to make changes
to the source file.