238Chapter7 • Miscellaneous Tools
2 main()
3 {
4 printf ("Hello world\n");
5 }
Now you can display the line number of the source code file corresponding to address
8048466 in the object file with the following command:
[root@boota]# addr2line -e a.out 8048466
/root/chap-07/ltrace/a.c:4
[root@boota]#
This is the line where the
printf
function is called in
a.c
file. The
add2line
com-
mand is useful in debuggers where you need to map addresses to a line in source code file.
7.8Using the ldd Utility
The
ldd
utility is very useful in finding out the dependencies of an executable on shared librar-
ies. This is necessary when you are copying executable files from one computer to another to
make sure that required libraries are present on the destination computer also. The following
command shows that
libc.so.6
must be present to execute
a.out
file on a computer.
[root@boota]# ldd a.out
libc.so.6 => /lib/i686/libc.so.6 (0x4002c000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
[root@boota]#
So if you copy
a.out
to another computer, make sure that this library is also present on
the destination computer.
7.9References and Resources
1.
GNU web site at http://www.gnu.org/
2.
The
cbrowser
home page at http://cbrowser.sourceforge.net
3.
The
cscope
home page at http://cscope.sourceforge.net
Next Page >>
<< Previous Page
Back to the Table of Contents