Programming in C

(Barry) #1

402 Chapter 18 Debugging Programs


newdate->day = 15;
newdate->year = 2004;

today = foo (today);

free (newdate);

return 0;
}

In the sample session for Program 18.5, your output might be slightly different, depend-
ing on which version and on what system you are running gdb.

Program 18.5 gdbSession
$ gcc -g p18-5.c
$ gdb a.out
GNU gdb 5.3-20030128 (Apple version gdb-309) (Thu Dec 4 15:41:30 GMT 2003)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "powerpc-apple-darwin".
Reading symbols for shared libraries .. done
(gdb) list main
14
15 return x;
16 }
17
18 int main (void)
19 {
20 struct date today = {10, 11, 2004};
21 int array[5] = {1, 2, 3, 4, 5};
22 struct date *newdate, foo ();
23 char *string = "test string";
(gdb) break main Set breakpoint in main
Breakpoint 1 at 0x1ce8: file p18-5.c, line 20.
(gdb) run Start program execution
Starting program: /Users/stevekochan/MySrc/c/a.out
Reading symbols for shared libraries. done

Breakpoint 1, main () at p18-5.c:20
20 struct date today = {10, 11, 2004};
(gdb) step Execute line 20

Program 18.5 Continued
Free download pdf