Linux does not have a defined symbol debugging method. nm command

Source: Internet
Author: User


NM command
[
In the content provided by the gnu c language library, an interface can be used to do this. Run the following command to View Details:

Nm-D/lib/libc. so.6 | grep log
]



The nm command is relatively simple and powerful. It is used to list various symbols in a target file. There are many types of symbols. The following are some common symbol types.
Nm output characters Description
R Read Only symbol. For example, inCodeThere is a const maxdata = 3095; then maxdata is a read only symbol
N This is a debugging symbol
D This is the symbol of an initialized variable. For example, if int I = 1 and char * STR = "hello" in the Code, both I and STR are symbols of this type.
T Text. ChildProgramThese are all such symbols. For example, if a function is implemented in a file, the function is such a symbol.
U Undefined symbol. If the file references a function that does not exist, the undefined function symbols are of this type.
S Uninitialized symbols, such as the global variable int s, are of this type.
For detailed usage and examples of the NM command, see the text. Here is an example of a. C:

# Include <stdio. h>

Static int s_global;
Int I = 1;
Char * STR = "Hello, world ";
Const id = 10;
Extern int e_global;
Void function ()
{
Printf ("hello ");
}


Int get_x ()
{
Int X;
X = 33;
Return X;
}


After "gcc-g-o-c A. C" is executed to generate a. o, the output of "nm-A. O" is:

A. O: 00000000 R ID
A. O: 00000000 t Function
A.o: 00000014 t get_x
A.o: 00000000 d I
A. O: U printf
A. O: 00000000 B s_global
A.o: 00000004 D Str

Usage of Nm

The usage of nm is very simple. The following keywords are commonly used:

1. "-A": the file from which the symbol name is displayed.

This is useful when listing symbols of multiple files (such as a Linked Library) at the same time.

2. "-A" to list all symbols

This will also list the debugging symbols. Debugging symbols are not listed by default.

3. "-l" to list symbols inSource codeCorresponding row number in

After this parameter is specified, Nm uses debugging information to find the file name and the line number of the symbol. For a defined symbol, the row number defined by this symbol is located. For undefined symbols, it is displayed as null.

4. "-n", sorted by the symbol address

By default, it is sorted alphabetically by the symbol name.

5. "-u", only undefined symbols are listed

same as "-- undefined-only ", "-- defined-only" will only list the defined symbols

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.