xref: /openbsd-src/usr.sbin/procmap/procmap.1 (revision 0b7734b3d77bb9b21afec6f4621cae6c805dbd45)
1.\"	$OpenBSD: procmap.1,v 1.21 2016/05/26 17:23:49 stefan 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: May 26 2016 $
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.Sh EXIT STATUS
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.In uvm/uvm_map.h :
224.Bd -literal -offset indent
225VM_MAP_PAGEABLE		0x01	ro: entries are pageable
226VM_MAP_INTRSAFE		0x02	ro: interrupt safe map
227VM_MAP_WIREFUTURE	0x04	rw: wire future mappings
228VM_MAP_BUSY		0x08	rw: map is busy
229VM_MAP_WANTLOCK		0x10	rw: want to write-lock
230.Ed
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.In uvm/uvm_extern.h :
245.\" this column width specifically chosen so that all the header file
246.\" excerpts appear to line up cleanly
247.Bd -literal -offset indent
248PROT_READ	0x01	read allowed
249PROT_WRITE	0x02	write allowed
250PROT_EXEC	0x04	execute allowed
251.Ed
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 namei 9 ,
348.Xr vnode 9
349.Sh HISTORY
350The
351.Nm
352utility first appeared in
353.Ox 3.5 .
354It was derived from the
355.Nx
356utility known as
357.Dq pmap .
358.Sh AUTHORS
359The
360.Nm
361utility and documentation was written by
362.An Andrew Brown Aq Mt atatat@netbsd.org .
363.Sh BUGS
364Very little will work unless
365.Nm
366is reading from the correct kernel in order to retrieve the
367proper symbol information.
368.Pp
369Since processes can change state while
370.Nm
371is running, some of the information printed may be inaccurate.
372This is especially important to consider when examining the kernel's map,
373since merely executing
374.Nm
375will cause some of the information to change.
376.Pp
377The pathnames to files backing certain vnodes (such as the text and
378data sections of programs and shared libraries) are extracted from the
379kernel's namei cache which is considerably volatile.
380If a path is not
381found there in its entirety, as much information as was available
382will be printed.
383In most cases, simply running
384.Xr ls 1
385.\" or
386.\" .Xr stat 1
387with the expected path to the file will cause the information to be
388reentered into the cache.
389.Pp
390The Solaris version
391.Pq Dq pmap
392has some interesting command line flags that would be nice to emulate here.
393In particular, the
394.Fl r
395option that lists a process's reserved addresses, and the
396.Fl x
397option that prints resident/shared/private mapping details for each
398entry.
399.Pp
400Some of the output modes can be or are wider than the standard 80
401columns of a terminal.
402Some sort of formatting might be nice.
403