01.09.2014 Views

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CH05.fm Page 166 Monday, October 7, 2002 9:00 PM<br />

166 Chapter 5 • Working with GNU Debugger<br />

this point <strong>and</strong> start gdb in the new window to attach the process. <strong>The</strong> following comm<strong>and</strong> starts<br />

the process which is waiting for the user to enter the first number.<br />

[rr@conformix 5]$ ./sumf<br />

Enter first number :<br />

Open a new terminal window <strong>and</strong> find out the process ID of the sumf process. This can<br />

be easily done using the ps comm<strong>and</strong> as follows:<br />

[rr@conformix 5]$ ps –a|grep sumf<br />

4272 pts/4 00:00:00 sumf<br />

[rr@conformix 5]$<br />

<strong>The</strong> process ID for the running process is 4272. After getting this information, you can<br />

start gdb <strong>and</strong> load the sumf file that contains the symbol table. This is done using the file<br />

comm<strong>and</strong>. <strong>The</strong> following sequence of comm<strong>and</strong>s shows this process:<br />

[rr@conformix 5]$ gdb<br />

GNU gdb 5.0rh-5 Red Hat <strong>Linux</strong> 7.1<br />

Copyright 2001 Free Software Foundation, Inc.<br />

GDB is free software, covered by the GNU General Public<br />

License, <strong>and</strong> you are<br />

welcome to change it <strong>and</strong>/or distribute copies of it under<br />

certain conditions.<br />

Type "show copying" to see the conditions.<br />

<strong>The</strong>re is absolutely no warranty for GDB. Type "show warranty"<br />

for details.<br />

This GDB was configured as "i386-redhat-linux".<br />

(gdb) file sumf<br />

Reading symbols from sumf...done.<br />

(gdb)<br />

Now you can attach to the program with ID 4272. Note that the program is waiting for<br />

user input <strong>and</strong> there are many functions calls from loaded shared libraries. To come back to this<br />

point in the main source file, you have to make a number of finish comm<strong>and</strong>s.<br />

(gdb) attach 4272<br />

Attaching to program: /home/rr/5/sumf, process 4272<br />

Reading symbols from /lib/i686/libc.so.6...done.<br />

Loaded symbols for /lib/i686/libc.so.6<br />

Reading symbols from /lib/ld-linux.so.2...done.<br />

Loaded symbols for /lib/ld-linux.so.2<br />

0x40105f44 in __libc_read () from /lib/i686/libc.so.6<br />

(gdb) n<br />

Single stepping until exit from function __libc_read,<br />

which has no line number information.<br />

_IO_file_read (fp=0x401548e0, buf=0x40019000, size=1024) at<br />

fileops.c:764<br />

764 fileops.c: No such file or directory.<br />

in fileops.c

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!