Graphics Programs Reference
In-Depth Information
reader@hacking:~/booksrc $ gcc -g convert2.c
reader@hacking:~/booksrc $ gdb -q ./a.out
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) run test
Starting program: /home/reader/booksrc/a.out test
Program received signal SIGSEGV, Segmentation fault.
0xb7ec819b in ?? () from /lib/tls/i686/cmov/libc.so.6
(gdb) where
#0 0xb7ec819b in ?? () from /lib/tls/i686/cmov/libc.so.6
#1 0xb800183c in ?? ()
#2 0x00000000 in ?? ()
(gdb) break main
Breakpoint 1 at 0x8048419: file convert2.c, line 14.
(gdb) run test
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/reader/booksrc/a.out test
Breakpoint 1, main (argc=2, argv= 0xbffff894 ) at convert2.c:14
14 count = atoi(argv[2]); // convert the 2nd arg into an integer
(gdb) cont
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0xb7ec819b in ?? () from /lib/tls/i686/cmov/libc.so.6
(gdb) x/3xw 0xbffff894
0xbffff894: 0xbffff9b3 0xbffff9ce 0x00000000
(gdb) x/s 0xbffff9b3
0xbffff9b3: "/home/reader/booksrc/a.out"
(gdb) x/s 0xbffff9ce
0xbffff9ce: "test"
(gdb) x/s 0x00000000
0x0: <Address 0x0 out of bounds>
(gdb) quit
The program is running. Exit anyway? (y or n) y
r eader@hacking:~/booksrc $
The program is executed with a single command-line argument of test
within GDB, which causes the program to crash. The where command will
sometimes show a useful backtrace of the stack; however, in this case, the
stack was too badly mangled in the crash. A breakpoint is set on main and
the program is re-executed to get the value of the argument vector (shown in
bold). Since the argument vector is a pointer to list of strings, it is actually a
pointer to a list of pointers. Using the command x/3xw to examine the first
three memory addresses stored at the argument vector's address shows that
they are themselves pointers to strings. The first one is the zeroth argument,
the second is the test argument, and the third is zero, which is out of bounds.
When the program tries to access this memory address, it crashes with a
segmentation fault.
Search WWH ::




Custom Search