Linux/proc/maps File Analysis

Source: Internet
Author: User
Tags ranges

Collect/proc/maps file analysis in Linux
From: http://blog.csdn.net/wenxy1/archive/2008/12/23/3591243.aspx
/Proc/<pid>/maps
View how the virtual address space of a process is used.
The file has six columns:
Address: Library address range in the process
Permission: Virtual Memory permission, r = read, W = write, x =, S = share, P = private;
Offset: address range of the database in the process
Device: the master and secondary device numbers of the image file;
Node: the node number of the image file;
Path: Path of the image file
Each item corresponds to a vm_area_struct structure member,
Example:
The application body segment (permission: R-XP) ranges from 0x08048000 to 0x08049000, And the size is 4096; the data segment ranges from 0x08049000 to 0x0804a000, And the size is 1 kb. The application uses two libraries: Lib and libc. The libc Text Segment ranges from 0x00391000 to 0x004b4000, with the size of 1164kb. The data segment ranges from 0x004b5000 to 0x004b8000, And the size is 12kb.
The body segment of the LD ranges from 00378000 to 0038d000, with the size of 84kb. The data segment ranges from 0x0038e000 to 0x0038f000, with the size of 4kb. The size of the virtual space occupied by the library used by the application ranges from 0x4b8000 to 0x378000, And the size is 1280kb. In fact, the actual size is vmlib (1251kb), because it is allocated by page, the size of each page is 4 kb.
[Root @ localhost ~] # Cat/proc/7114/maps
08047000-080dc000 R-XP 00000000 884901/bin/bash
080dc000-080e3000 rwxp 00094000 884901/bin/bash
080e3000-08129000 rwxp 080e3000 00:00 0 [heap]
4d575000-4d58a000 R-XP 00000000 0:06 736549/lib/ld-2.3.4.so
4d58a000-4d58b000 R-XP 00015000 0:06 736549/lib/ld-2.3.4.so
4d58b000-4d58c000 rwxp 00016000 0:06 736549/lib/ld-2.3.4.so
4d58e000-4d6b1000 R-XP 00000000 0:06 736550/lib/tls/libc-2.3.4.so
4d6b1000-4d6b2000 R-XP 00123000 0:06 736550/lib/tls/libc-2.3.4.so
4d6b2000-4d6b5000 rwxp 00124000 0:06 736550/lib/tls/libc-2.3.4.so
4d6b5000-4d6b7000 rwxp 4d6b5000 00:00 0
4d6de000-4d6e0000 R-XP 00000000 0:06 736552/lib/libdl-2.3.4.so
4d6e0000-4d6e2000 rwxp 00001000 0:06 736552/lib/libdl-2.3.4.so
4d807000-4d80a000 R-XP 00000000 0:06 736567/lib/libtermcap. so.2.0.8
4d80a000-4d80b000 rwxp 00002000 0:06 736567/lib/libtermcap. so.2.0.8
B7bf2000-b7c1e000 R-XP 00000000 0:06 881337/usr/lib/gconv/gb18030.so
B7c1e000-b7c20000 rwxp 0002b000 0:06 881337/usr/lib/gconv/gb18030.so
B7c20000-b7c26000 R-xs 00000000 0:06 881502/usr/lib/gconv/gconv-modules.cache
B7c26000-b7d2f000 R-XP 02197000 0:06 852489/usr/lib/locale-Archive
B7d2f000-b7f2f000 R-XP 00000000 0:06 852489/usr/lib/locale-Archive
B7f2f000-b7f38000 R-XP 00000000 0:06 734450/lib/libnss_files-2.3.4.so
B7f38000-b7f3a000 rwxp 00008000 0:06 734450/lib/libnss_files-2.3.4.so
B7f3a000-b7f3c000 rwxp b7f3a000 00:00 0
B7f51000-b7f52000 rwxp b7f51000 00:00 0
Bfc3d000-bfc52000 RW-P bfc3d000 0 [[color = Red] Stack] [/color]
Ffffe000-fffff000 --- P 00000000 00:00 0 [[color = Red] vdso [/color]
[Root @ localhost ~] #
Parameter description
Address: The address space occupied by the start and end address files of the 0085d000-00872000 virtual memory area
Perms: RW-P permission: r = read, W = write, x = execute, S = shared, P = private (copy on write)
Offset: 00000000 offset of the virtual memory area in the mapped file
Dev: Master and sub-device numbers of File
Inode: the node number of the device. 0 indicates that no node corresponds to the memory.
Name:/lib/File Name of the ld-2.3.4.so mapped file
The code segment of each shared library stores binary executable machine commands. The kernel map the code segment of the ELF file of the Library to the virtual storage space;
The data segment of each shared database stores the global variables required for program execution. The data segment of the ELF file is mapped to the virtual storage space by the kernel;
The user code segment stores executable machine commands in binary form. It is used by the kernel to map the code segment of the ELF file to the virtual storage space;
The user data segment is a code segment that stores the global variables required for program execution. The data segment of the ELF file is mapped to the virtual storage space by the kernel;
The user data segment is under heap. If it exists only when malloc is called, the kernel maps the anonymous memory to the virtual storage space, the heap does not exist when malloc is not called in the program;
The user data segment is a stack. As a temporary data zone of a process, the kernel maps the anonymous memory to the virtual storage space. The growth direction of the stack space is from high address to low address.
[Root @ localhost ~] # LDD/bin/bash
Linux-gate.so.1 => (0xffffe000)
Libtermcap. so.2 =>/lib/libtermcap. so.2 (0x4d807000)
Libdl. so.2 =>/lib/libdl. so.2 (0x4d6de000)
Libc. so.6 =>/lib/tls/libc. so.6 (0x4d58e000)
/Lib/ld-linux.so.2 (0x4d575000)
[Root @ localhost ~] #
This so-called "linux-gate.so.1" content is the kernel ing code, the system does not actually have such a link library file, its name is from the LDD own, 0xffffe400 is a piece of code here, which is the system call entry code mapped by the kernel. Mapped is the size of the virtual space of the application. The value here is 4 kb larger than that of top or PS, that is, the code for 0xffffe400-0xffffffffff; shared provides the shared virtual space.

Maps can only be viewed with Cat. When VI or Vim is used, all maps are blank.
Maps can help find the location where the bug is located, that is, the EPC location in debug can be found based on maps. so or other documents. Then, the NM decomassembles the documents to find the position of the relative offset to find the line where the problem occurs.

Related Article

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.