HP gnu source-level debugger 5992-4701 manual Gdb b main, Gdb run, Gdb edit, Gdb fix

Models: gnu source-level debugger 5992-4701

1 369
Download 369 pages 58.54 Kb
Page 149
Image 149

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

Compiling /dev/src/sum.c...

Linking...

Applying code changes to sum.c. Fix succeeded.

The fix command creates a new executable that includes the changes you made to the source file.

The debugger automatically uses the new executable and picks up the debugging session where you stopped before using the edit command.

For example, you can continue stepping through the program and you will nd the new return total; statement in the source view. You can print the value of total, and see that the result is 110.

14.7 Fix and continue debugging 149

Page 149
Image 149
HP gnu source-level debugger 5992-4701 manual Gdb b main, Gdb run, Gdb edit, Gdb fix