After the initial copyright and
configuration information, GDB returns its own prompt,
(gdb).
The following is a sample debugging session:
To set a breakpoint, type:
The following output displays:
Breakpoint 1 at 0x132: file hello.c, line 15. |
Note the exact address and line number may vary, depending upon the
target architecture being debugged and the exact layout of the C code
in the hello.c file.
To run the program, type:
The following output displays (when the program stops at a breakpoint):
Starting program: hello
Breakpoint 1, main () at hello.c:15
15 a = 3; |
Again note that the exact line number and instruction displayed is
dependent upon the source code layout.
To print the value of variable, a, type:
The following output displays:
To execute the next command, type next:
The following output displays:
To display the value of a again, type:
The following output displays:
To display the program being debugged, type:
The following output displays:
12 int
13 main (void)
14 {
15 int b;
16
17 a = 3;
18 b = 4;
19
20 printf ("Hello, world!\n");
21
22 foo (b);
23
24 return 0;
25 } |
To list a specific function code, use the list command with the name
of the function to be display. For example, type:
The following output displays:
1 #include <stdio.h>
2
3 int a, c;
4
5 static void
6 foo (int b)
7 {
8 c = a + b;
9 printf ("%d + %d = %d\n", a, b, c);
10 } |
To set a breakpoint at line seven,
enter the following input (set a
breakpoint at any line by entering
break linenumber, where linenumber
is the specific line number to break):
The following output displays:
Breakpoint 2 at 0xf4: file hello.c, line 8. |
To resume normal execution of the program until the next breakpoint,
type:
The following output displays:
Continuing.
Hello, world!
Breakpoint 2, foo (b=4) at hello.c:8
8 c = a + b; |
To step to the next instruction and execute it, type:
The following output displays:
9 printf ("%d + %d = %d\n", a, b, c); |
To display the value of c, type:
The following output displays:
To see how you got to where you are, type:
The following output displays:
#0 foo (b=4) at hello.c:9
#1 0x15c in main () at hello.c:18 |
To exit the program and quit the debugger, type: