HP-UX HB v13.00 Ch-11 - Software Development

HP-UX Handbook Rev 13.00 Page 57 (of 101)
Chapter 11 Software Development
October 29, 2013
Starting program: /var/tmp/HelloWorld
Breakpoint 1, main () at HelloWorld.c:4
4 printf("Hello World!\n");
(gdb)
When invoking gdb, it loads the program but does not execute it yet. First we print out the source
program to check where we are. Then we tell gdb to stop execution when entering main() by
setting a breakpoint there, and run the program. gdb will stop execution at the first executable
statement of main(). When gdb stops execution, it always prints the statement to be executed
next.
(gdb) step
Hello World!
5 }
(gdb) continue
Continuing.
Program exited with code 013.
(gdb)
Now we make a step to the next line of source code. If we had the sources of printf(3S) and a
debuggable libc, the step command would jump into printf(3S) and display the first
executable statement of it. But we haven't, so we find ourselves at the end of main() after
returning from printf(3S). The program has not exited yet, so we tell gdb to continue program
execution. If there was another breakpoint it would stop there, but there is none so the program
exits. Finally gdb prints the exit code of the program.
Many debugger commands can be abbreviated. Pressing <enter> on an empty prompt repeats the
last command.
Let's set another breakpoint in printf(3S):
(gdb) break printf
Breakpoint 2 at 0x7f7a5360
(gdb) r
warning: Temporarily disabling shared library breakpoints:
warning: breakpoint #2
Starting program: /var/tmp/HelloWorld
Breakpoint 1, main () at HelloWorld.c:4
4 printf("Hello World!\n");
(gdb) c
Continuing.