Linux Porgramming Unleashed--reading digest

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

To print the first memory locations associated with ary, use the following command:
(gdb) print ary@10
$5 = {0xbffffa08, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8
(gdb) print ary[0]@10
$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 <linenum>
(gdb) break <funcname>
(gdb) break <filename:linenum>
(gdb) break <filename:funcname>
(gdb) break <linenum or funcname> if <expr>

(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

file_or_funcname::varname
(gdb) print ‘foo.c::baz
(gdb) print &blat::idx
(gdb) where
#0 number () at callstk.c:33
#1 0x80484cf in make_key () at callstk.c:22
#2 0x804849b in main () at callstk.c:15
(gdb) up
(gdb) down
To specify one or more additional directories, start gdb using one or more -d <dirname> options, as illustrated in the following:
$ gdb -d /source/project1
To locate the next occurrence of a particular string in the current file, use the search <string> command. Usereverse-search <string> to find the previous occurrence.
(gdb) shell <command>
The final advanced procedure I will discuss is how to use gdb to attach to a running process, such as a system daemon. The procedure to accomplish this is very similar to starting gdb, except that the second argument to gdb is the PID (process ID) of the executable to which you want to attach, rather than the name of the core file.
Attaching to a running process automatically halts it so you can inspect its status using the normal gdb commands. When you are done, simply type quit, which will detach from the running process and allow it to continue. If gdb is already running, you can use the attach and file commands to obtain access to the program. First, use the file command to specify the program running in the process and to load its symbol table, as in
the following:
(gdb) file httpd
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.
...
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值