[CRIU] [PATCH 4/3] crit: The 'mems' explorer

Pavel Emelyanov xemul at parallels.com
Mon Dec 14 06:14:38 PST 2015


This one prints the /proc/pid/maps-like output, but with slightly more
details. Like this

1
	exe                                     /zdtm/live/static/maps00
	00400000-00406000                   r-x /zdtm/live/static/maps00
	00605000-00606000                   r-- /zdtm/live/static/maps00 + 0x5000
	00606000-00607000                   rw- /zdtm/live/static/maps00 + 0x6000
	7f4037845000-7f40379f9000           r-x /lib64/libc.so.6
	7f40379f9000-7f4037bf8000           --- /lib64/libc.so.6 + 0x1b4000
	7f4037bf8000-7f4037bfc000           r-- /lib64/libc.so.6 + 0x1b3000
	7f4037bfc000-7f4037bfe000           rw- /lib64/libc.so.6 + 0x1b7000
	7f4037bfe000-7f4037c03000           rw-
	7f4037c03000-7f4037c23000           r-x /lib64/ld-linux-x86-64.so.2
	7f4037e1e000-7f4037e22000           rw-
	7f4037e22000-7f4037e23000           r-- /lib64/ld-linux-x86-64.so.2 + 0x1f000
	7f4037e23000-7f4037e24000           rw- /lib64/ld-linux-x86-64.so.2 + 0x20000
	7f4037e24000-7f4037e25000           rw-
	7fff34652000-7fff34699000           rw- [stack?]
	7fff346e2000-7fff346e4000           r--
	7fff346e4000-7fff346e6000           r-x [vdso]
	ffffffffff600000-ffffffffff601000   r-x [vsyscall] *


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 crit | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 62 insertions(+), 2 deletions(-)

diff --git a/crit b/crit
index 518bfad..93cbc98 100755
--- a/crit
+++ b/crit
@@ -152,7 +152,67 @@ def explore_fds(opts):
 		print "\t%7s: %s" % ('root', get_file_str(opts, {'type': 'REG', 'id': fdi['root_id']}))
 
 
-explorers = { 'ps': explore_ps, 'fds': explore_fds }
+class vma_id:
+	def __init__(self):
+		self.__ids = {}
+		self.__last = 1
+
+	def get(self, iid):
+		ret = self.__ids.get(iid, None)
+		if not ret:
+			ret = self.__last
+			self.__last += 1
+			self.__ids[iid] = ret
+
+		return ret
+
+def explore_mems(opts):
+	ps_img = pycriu.images.load(dinf(opts, 'pstree.img'))
+	vids = vma_id()
+	for p in ps_img['entries']:
+		pid = p['pid']
+		mmi = pycriu.images.load(dinf(opts, 'mm-%d.img' % pid))['entries'][0]
+
+		print "%d" % pid
+		print "\t%-36s    %s" % ('exe', get_file_str(opts, {'type': 'REG', 'id': mmi['exe_file_id']}))
+
+		for vma in mmi['vmas']:
+			st = vma['status']
+			if st & (1 << 10):
+				fn = ' ' + 'ips[%lx]' % vids.get(vma['shmid'])
+			elif st & (1 << 8):
+				fn = ' ' + 'shmem[%lx]' % vids.get(vma['shmid'])
+			elif st & (1 << 11):
+				fn = ' ' + 'packet[%lx]' % vids.get(vma['shmid'])
+			elif st & ((1 << 6) | (1 << 7)):
+				fn = ' ' + get_file_str(opts, {'type': 'REG', 'id': vma['shmid']})
+				if vma['pgoff']:
+					fn += ' + %#lx' % vma['pgoff']
+				if st & (1 << 7):
+					fn += ' (s)'
+			elif st & (1 << 1):
+				fn = ' [stack]'
+			elif st & (1 << 2):
+				fn = ' [vsyscall]'
+			elif st & (1 << 3):
+				fn = ' [vdso]'
+			elif vma['flags'] & 0x0100: # growsdown
+				fn = ' [stack?]'
+			else:
+				fn = ''
+
+			if not st & (1 << 0):
+				fn += ' *'
+
+			prot = vma['prot'] & 0x1 and 'r' or '-'
+			prot += vma['prot'] & 0x2 and 'w' or '-'
+			prot += vma['prot'] & 0x4 and 'x' or '-'
+
+			astr = '%08lx-%08lx' % (vma['start'], vma['end'])
+			print "\t%-36s%s%s" % (astr, prot, fn)
+
+
+explorers = { 'ps': explore_ps, 'fds': explore_fds, 'mems': explore_mems }
 
 def explore(opts):
 	explorers[opts['what']](opts)
@@ -198,7 +258,7 @@ def main():
 	# Explore
 	x_parser = subparsers.add_parser('x', help = 'explore image dir')
 	x_parser.add_argument('dir')
-	x_parser.add_argument('what', choices = [ 'ps', 'fds' ])
+	x_parser.add_argument('what', choices = [ 'ps', 'fds', 'mems' ])
 	x_parser.set_defaults(func=explore)
 
 	# Show
-- 
1.9.3




More information about the CRIU mailing list