166Chapter5 • Working with GNU Debugger
this point and start
gdb
in the new window to attach the process. The following command starts
the process which is waiting for the user to enter the first number.
[rr@conformix 5]$ ./sumf
Enter first number :
Open a new terminal window and find out the process ID of the
sumf
process. This can
be easily done using the
ps
command as follows:
[rr@conformix 5]$ ps –a|grep sumf
4272 pts/4 00:00:00 sumf
[rr@conformix 5]$
The process ID for the running process is 4272. After getting this information, you can
start
gdb
and load the
sumf
file that contains the symbol table. This is done using the
file
command. The following sequence of commands shows this process:
[rr@conformix 5]$ gdb
GNU gdb 5.0rh-5 Red Hat Linux 7.1
Copyright 2001 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 "i386-redhat-linux".
(gdb) file sumf
Reading symbols from sumf...done.
(gdb)
Now you can attach to the program with ID 4272. Note that the program is waiting for
user input and there are many functions calls from loaded shared libraries. To come back to this
point in the main source file, you have to make a number of
finish
commands.
(gdb) attach 4272
Attaching to program: /home/rr/5/sumf, process 4272
Reading symbols from /lib/i686/libc.so.6...done.
Loaded symbols for /lib/i686/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
0x40105f44 in __libc_read () from /lib/i686/libc.so.6
(gdb) n
Single stepping until exit from function __libc_read,
which has no line number information.
_IO_file_read (fp=0x401548e0, buf=0x40019000, size=1024) at
fileops.c:764
764 fileops.c: No such file or directory.
in fileops.c