xref: /openbsd-src/usr.sbin/procmap/procmap.1 (revision 2b0358df1d88d06ef4139321dd05bd5e05d91eaf)
1.\"	$OpenBSD: procmap.1,v 1.12 2009/01/19 09:46:59 sobrado Exp $
2.\"	$NetBSD: pmap.1,v 1.6 2003/01/19 21:25:43 atatat Exp $
3.\"
4.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Andrew Brown.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29.\" POSSIBILITY OF SUCH DAMAGE.
30.\"
31.Dd $Mdocdate: January 19 2009 $
32.Dt PROCMAP 1
33.Os
34.Sh NAME
35.Nm procmap
36.Nd display process memory map
37.Sh SYNOPSIS
38.Nm
39.Op Fl AadlmPsv
40.Op Fl D Ar number
41.Op Fl M Ar core
42.Op Fl N Ar system
43.Op Fl p Ar pid
44.Op Ar pid ...
45.Sh DESCRIPTION
46The
47.Nm
48utility lists the virtual memory mappings underlying the given
49process.
50The start address of each entry is always given, and,
51depending on the options given, other information such as the end
52address, the underlying file's device and inode numbers, and various
53protection information will be displayed, along with the path to the
54file, if such data is available.
55.Pp
56By default,
57.Nm
58displays information for its parent process, so that when run from a
59shell prompt, the shell's memory information is displayed.
60If other
61PIDs are given as arguments on the command line, information for those
62processes will be printed also.
63If the special PID of 0 is given,
64then information for the kernel's memory map is printed.
65.Pp
66The options are as follows:
67.Bl -tag -width XXXnumberXX
68.It Fl A
69Print more detailed information on anonymous map usage.
70.It Fl a
71Display
72.Dq all
73information from the process's memory map.
74This output
75mode is an amalgam of the contents of the Solaris, Linux, and
76.Ox
77style output modes.
78.It Fl D Ar number
79Enable various debug facilities.
80The
81.Ar number
82is a bit mask of the values:
83.Pp
84.Bl -tag -width flag -compact
85.It Cm 1
86dump the process's vmspace structure
87.It Cm 2
88dump the process's vm_map structure
89.It Cm 4
90dump the vm_map.header structure
91.It Cm 8
92dump each vm_map_entry in its entirety
93.It Cm 16
94dump the namei cache as it is traversed
95.El
96.It Fl d
97Dumps the vm_map and vm_map_entry structures in a style similar to
98that of
99.Xr ddb 4 .
100When combined with the
101.Fl v
102option, the device number, inode number, name, vnode addresses, or
103other identifying information from the vm_map_entry fields will be
104printed.
105.It Fl l
106Dumps information in a format like the contents of the maps
107pseudo-file under the
108.Pa /proc
109file system which was, in turn, modeled after the similarly named entry
110in the Linux
111.Pa /proc
112file system.
113When combined with the
114.Fl v
115option, identifiers for all entries are printed.
116.It Fl M Ar core
117Extract values associated with the name list from the specified core
118instead of the default
119.Pa /dev/kmem .
120.It Fl m
121Dumps information in the same format as the map pseudo-file of the
122.Pa /proc
123file system.
124When the
125.Fl v
126option is also given, device number, inode number, and filename
127or other identifying information is printed.
128.It Fl N Ar system
129Extract the name list from the specified system instead of the
130running kernel.
131.It Fl P
132Causes
133.Nm
134to print information about itself.
135.It Fl p Ar pid
136Tells
137.Nm
138to print information about the given process.
139If
140.Fl p Ar pid
141occurs last on the command line, the
142.Fl p
143is optional.
144.\" .It Fl R
145.\" Recurse into submaps.
146.\" In some cases, a vm_map_entry in the kernel
147.\" will point to a submap.
148.\" Using this flag tells
149.\" .Nm
150.\" to print the entries of the submap as well.
151.\" The submap output is
152.\" indented, and does not affect any total printed at the bottom of the
153.\" output.
154.It Fl s
155The Solaris style output format, modeled after the Solaris command
156.Dq pmap .
157This is the default output style.
158.It Fl v
159Verbose output.
160When used with
161.Fl d ,
162.Fl l ,
163or
164.Fl m ,
165more information is printed, possibly including device and inode
166numbers, file path names, or other identifying information.
167If specified more than once, a
168.Sq *
169will be printed in between two
170entries that are not adjacent, making the visual identification of
171spaces in the process's map easier to see.
172.El
173.Pp
174The
175.Fl P
176and
177.Fl p
178options override each other, so the last one to appear on the command
179line takes effect.
180If you do wish to see information about
181.Nm
182and another process as the same time, simply omit the
183.Fl p
184and place the extra PID at the end of the command line.
185.Pp
186.Ex -std procmap
187.Sh EXAMPLES
188While the meaning most of the output is self-evident, some pieces of
189it may appear to be a little inscrutable.
190.Pp
191Here a portion of the default output from
192.Nm
193being run at a
194.Xr sh 1
195prompt shows the starting address of the map entry, the size of the
196map entry, the current protection level of the map entry, and either
197the name of the file backing the entry or some other descriptive text.
198.Bd -literal -offset indent
199$ procmap
20008048000    420K read/exec         /bin/sh
201080B1000      8K read/write        /bin/sh
202080B3000     28K read/write          [ anon ]
203080BA000     16K read/write/exec     [ heap ]
204\&...
205.Ed
206.Pp
207When the
208.Xr ddb 4
209output style is selected, the first thing printed is the contents of
210the vm_map structure, followed by the individual map entries.
211.Bd -literal -offset indent
212$ procmap -d
213MAP 0xcf7cac84: [0x0-\*(Gt0xbfbfe000]
214        #ent=8, sz=34041856, ref=1, version=20, flags=0x21
215        pmap=0xcf44cee0(resident=\*(Ltunknown\*(Gt)
216 - 0xcfa3a358: 0x8048000-\*(Gt0x80b1000: obj=0xcf45a8e8/0x0, amap=0x0/0
217        submap=F, cow=T, nc=T, prot(max)=5/7, inh=1, wc=0, adv=0
218\&...
219.Ed
220.Pp
221The value of the flags field (in hexadecimal) is taken from
222the include file
223.Aq Pa uvm/uvm_map.h :
224.Bl -column VM_MAP_WIREFUTURE VM_MAP_WIREFUTURE -offset indent
225.It Dv "VM_MAP_PAGEABLE"   Ta No "0x01   ro: entries are pageable"
226.It Dv "VM_MAP_INTRSAFE"   Ta No "0x02   ro: interrupt safe map"
227.It Dv "VM_MAP_WIREFUTURE" Ta No "0x04   rw: wire future mappings"
228.It Dv "VM_MAP_BUSY"       Ta No "0x08   rw: map is busy"
229.It Dv "VM_MAP_WANTLOCK"   Ta No "0x10   rw: want to write-lock"
230.El
231.Pp
232The
233.Dq submap ,
234.Dq cow ,
235and
236.Dq nc
237fields are true or false, and indicate whether the map is a submap,
238whether it is marked for copy on write, and whether it needs a copy.
239The
240.Dq prot
241(or protection) field, along with
242.Dq max
243(maximum protection allowed) are made up of the following flags from
244.Aq Pa uvm/uvm_extern.h :
245.\" this column width specifically chosen so that all the header file
246.\" excerpts appear to line up cleanly
247.Bl -column VM_MAP_WIREFUTURE VM_MAP_WIREFUTURE -offset indent
248.It Dv "UVM_PROT_READ"  Ta No "0x01   read allowed"
249.It Dv "UVM_PROT_WRITE" Ta No "0x02   write allowed"
250.It Dv "UVM_PROT_EXEC"  Ta No "0x04   execute allowed"
251.El
252.Pp
253The
254.Dq obj
255and
256.Dq amap
257fields are pointers to, and offsets into, the underlying uvm_object or
258vm_amap object.
259The value for resident is always unknown because digging such
260information out of the kernel is beyond the scope of this application.
261.Pp
262The two output styles that mirror the contents of the
263.Pa /proc
264file system
265appear as follows:
266.Bd -literal -offset indent
267$ procmap -m
2680x8048000 0x80b1000 r-x rwx COW NC 1 0 0
2690x80b1000 0x80b3000 rw- rwx COW NC 1 0 0
2700x80b3000 0x80ba000 rw- rwx COW NNC 1 0 0
2710x80ba000 0x80be000 rwx rwx COW NNC 1 0 0
272\&...
273
274$ procmap -l
27508048000-080b1000 r-xp 00000000 00:00 70173     /bin/sh
276080b1000-080b3000 rw-p 00068000 00:00 70173     /bin/sh
277080b3000-080ba000 rw-p 00000000 00:00 0
278080ba000-080be000 rwxp 00000000 00:00 0
279\&...
280.Ed
281.Pp
282Here the protection and maximum protection values are indicated with
283.Sq r ,
284.Sq w ,
285and
286.Sq x
287characters, indicating read permission, write permission, and execute
288permission, respectively.
289The
290.Dq COW ,
291.Dq NC ,
292and
293.Dq NNC
294values that follow indicate, again, that the map is marked for copy on
295write and either needs or does not need a copy.
296It is also possible
297to see the value
298.Dq NCOW
299here, which indicates that an entry will not be copied.
300The three
301following numbers indicate the inheritance type of the map, the wired
302count of the map, and any advice value assigned via
303.Xr madvise 2 .
304.Pp
305In the second form, the permissions indicated are followed by a
306.Sq p
307or
308.Sq s
309character indicating whether the map entry is private or shared (copy
310on write or not), and the numbers are the offset into the underlying
311object, the device and numbers of the object if it is a file, and the
312path to the file (if available).
313.Pp
314As noted above (see section
315.Sx DESCRIPTION ) ,
316the
317.Dq all
318output format is an amalgam of the previous output formats.
319.Bd -literal -offset indent
320$ procmap -a
321Start    End         Size  Offset   rwxpc  RWX  I/W/A ...
32208048000-080b0fff     420k 00000000 r-xp+ (rwx) 1/0/0 ...
323\&...
324.Ed
325.Pp
326In this format, the column labeled
327.Dq rwxpc
328contains the permissions for the mapping along with the shared/private
329flag, and a character indicating whether the mapping needs to be
330copied on write
331.Pq Sq +
332or has already been copied
333.Pq Sq -
334and is followed by a column that indicates the maximum permissions for
335the map entry.
336The column labeled
337.Dq I/W/A
338indicates the inheritance, wired, and advice values for the map entry,
339as previously described.
340.Sh SEE ALSO
341.Xr ls 1 ,
342.\" .Xr stat 1 ,
343.Xr madvise 2 ,
344.Xr mmap 2 ,
345.Xr kvm 3 ,
346.Xr ddb 4 ,
347.Xr mount_procfs 8 ,
348.Xr namei 9 ,
349.Xr vnode 9
350.Sh HISTORY
351The
352.Nm
353utility first appeared in
354.Ox 3.5 .
355It was derived from the
356.Nx
357utility known as
358.Dq pmap .
359.Sh AUTHORS
360The
361.Nm
362utility and documentation was written by
363.An Andrew Brown Aq atatat@netbsd.org .
364.Sh BUGS
365Very little will work unless
366.Nm
367is reading from the correct kernel in order to retrieve the
368proper symbol information.
369.Pp
370Since processes can change state while
371.Nm
372is running, some of the information printed may be inaccurate.
373This is especially important to consider when examining the kernel's map,
374since merely executing
375.Nm
376will cause some of the information to change.
377.Pp
378The pathnames to files backing certain vnodes (such as the text and
379data sections of programs and shared libraries) are extracted from the
380kernel's namei cache which is considerably volatile.
381If a path is not
382found there in its entirety, as much information as was available
383will be printed.
384In most cases, simply running
385.Xr ls 1
386.\" or
387.\" .Xr stat 1
388with the expected path to the file will cause the information to be
389reentered into the cache.
390.Pp
391The Solaris version
392.Pq Dq pmap
393has some interesting command line flags that would be nice to emulate here.
394In particular, the
395.Fl r
396option that lists a process's reserved addresses, and the
397.Fl x
398option that prints resident/shared/private mapping details for each
399entry.
400.Pp
401Some of the output modes can be or are wider than the standard 80
402columns of a terminal.
403Some sort of formatting might be nice.
404