Debugging with GDB Manual (5900-1473; WDB 6.2; January 2011)

Table Of Contents
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.
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.
Because you are going to edit the current file, you do not need to specify a source
file name.
(gdb) edit
The edit command opens a new terminal session using your environment variable
settings for terminal and editor. The debugger automatically loads the source file.
7. Make the necessary changes. In this case, add:
return total;
to the function named num.
8. Save the edited source file and exit the editor. This saves the changes in the actual
source file for the program.
9. Use the fix command to recompile the program to see the results of the changes:
(gdb) fix
142 HP-UX Configuration-Specific Information