chapter 24
1. nm [options] file
The nm command lists all of the symbols encoded in an object or binary file.
Table 24.1 nm OPTIONS
Option Description
-C|-demangle Convert symbol names into user-level names, especially useful for making C++ function names readable.
-s|-print-armap When used on archive (.a) files, also print the index that maps symbol names to the modules or member names in which the symbol is defined.
-u|-undefined-only Only display undefined symbols, symbols defined externally to the file being examined.
-l|-line-numbers Use debugging information to print the line number where each symbol is defined, or the relocation entry if the symbol is undefined.
2. ar {dmpqrtx} [member] archive files...
ar creates, modifies, or extracts archives. It is most commonly used to create static libraries—files that contain one or more object files, called members, of subroutines in precompiled format. ar also creates and maintains a table that cross-references symbol names to the members in which they are defined. Table 24.2 describes the most commonly used ar options.
Table 24.2 ar OPTIONS
Option Description
-c Create archive if it doesn’t exist from files, suppressing the warning ar would emit if archive doesn’t exist.
-s Create or update the map linking symbols to the member in which they are defined.
-r Insert files into the archive, replacing any existing members whose name matches that being added. New members are added at the end of the archive.
-q Add files to the end of archive without checking for replacements.
ranlib [-v|-V] file == ar -s
3. ldd [options] file
ldd prints the names of the shared libraries required by file.
Table 24.3 ldd OPTIONS
Option Description
-d Perform relocations and report any missing functions
-r Perform relocations for both function and data objects and report any missing functions or data objects
4. ldconfig [options] [libs]
ldconfig determines the runtime links required by shared libraries that are located in /usr/lib and /lib, specified in libs on the command-line, and stored in /etc/ld.so.conf. ldconfig works in conjunction with ld.so, the dynamic
linker/loader, to create and maintain links to the most current versions of shared libraries.
Table 24.4 ldconfig OPTIONS
Option Description
-p Merely print the contents of /etc/ld.so.cache, the current list of shared libraries about which ld.so knows.
-v Verbosely update /etc/ld.so.cache, listing each library’s version number, the directory scanned, and any links that are created or updated.
chapter 36
The $1 and $2 refer to entries in the value history. If you want to access these values in the future, use these aliases rather than retyping the command. For example, the command $1-1 produces:
(gdb) print $1-1
$4 = 381
(gdb) print ary@10
$5 = {0xbffffa08, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8
$9 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
gdb also can tell you the types of variables using the whatis command:
(gdb) whatis i
type = int
(gdb) whatis ary
type = int *
(gdb) whatis index_to_the_moon
type = void (int *)
(gdb) break <filename:funcname>
(gdb) set variable varname = value
Table 36.1 COMMANDS FOR WORKING WITH FUNCTIONS
Command Description
call name(args) Call and execute the function named name with the arguments args
finish Finish running the current function and print its return value, if applicable
return value Stop executing the current function and return value to the caller
#0 number () at callstk.c:33
#1 0x80484cf in make_key () at callstk.c:22
#2 0x804849b in main () at callstk.c:15
the following:
Reading symbols from httpd...(no debugging
➥symbols found)...done.
(gdb) attach 386
Attaching to program `/usr/sbin/httpd’, Pid 386
Reading symbols from /lib/libm.so.6...done.
Reading symbols from /lib/libcrypt.so.1...done.
Reading symbols from /lib/libdb.so.2...done.
Reading symbols from /lib/libdl.so.2...done.
Reading symbols from /lib/libc.so.6...done.
Reading symbols from /lib/ld-linux.so.2...done.
...