Lines Matching full:self

36     def __init__(self, filename):  argument
37 self.filename = filename
38 self.file = open(self.filename, "rb")
40 def read64(self): argument
41 return int.from_bytes(self.file.read(8), byteorder='big', signed=False)
43 def read32(self): argument
44 return int.from_bytes(self.file.read(4), byteorder='big', signed=False)
46 def read16(self): argument
47 return int.from_bytes(self.file.read(2), byteorder='big', signed=False)
49 def read8(self): argument
50 return int.from_bytes(self.file.read(1), byteorder='big', signed=True)
52 def readstr(self, len = None): argument
53 return self.readvar(len).decode('utf-8')
55 def readvar(self, size = None): argument
57 size = self.read8()
60 value = self.file.read(size)
62 raise Exception("Unexpected end of %s at 0x%x" % (self.filename, self.file.tell()))
65 def tell(self): argument
66 return self.file.tell()
68 def seek(self, a, b): argument
69 return self.file.seek(a, b)
73 def read_migration_debug_json(self): argument
77 entrypos = self.file.tell()
80 self.file.seek(0, os.SEEK_END)
81 endpos = self.file.tell()
82 self.file.seek(max(-endpos, -10 * 1024 * 1024), os.SEEK_END)
83 datapos = self.file.tell()
84 data = self.file.read()
86 self.file = open(self.filename, "rb")
94 self.file.seek(datapos + jsonpos - 5, 0)
95 if self.read8() != QEMU_VM_VMDESCRIPTION:
98 jsonlen = self.read32()
101 self.file.seek(entrypos, 0)
106 def close(self): argument
107 self.file.close()
120 def __init__(self, file, version_id, ramargs, section_key): argument
124 self.file = file
125 self.section_key = section_key
126 self.TARGET_PAGE_SIZE = ramargs['page_size']
127 self.dump_memory = ramargs['dump_memory']
128 self.write_memory = ramargs['write_memory']
129 self.ignore_shared = ramargs['ignore_shared']
130 self.sizeinfo = collections.OrderedDict()
131 self.data = collections.OrderedDict()
132 self.data['section sizes'] = self.sizeinfo
133 self.name = ''
134 if self.write_memory:
135 self.files = { }
136 if self.dump_memory:
137 self.memory = collections.OrderedDict()
138 self.data['memory'] = self.memory
140 def __repr__(self): argument
141 return self.data.__repr__()
143 def __str__(self): argument
144 return self.data.__str__()
146 def getDict(self): argument
147 return self.data
149 def read(self): argument
152 addr = self.file.read64()
153 flags = addr & (self.TARGET_PAGE_SIZE - 1)
154 addr &= ~(self.TARGET_PAGE_SIZE - 1)
156 if flags & self.RAM_SAVE_FLAG_MEM_SIZE:
159 namelen = self.file.read8()
160 self.name = self.file.readstr(len = namelen)
161 len = self.file.read64()
163 self.sizeinfo[self.name] = '0x%016x' % len
164 if self.write_memory:
165 print(self.name)
166 mkdir_p('./' + os.path.dirname(self.name))
167 f = open('./' + self.name, "wb")
170 self.files[self.name] = f
171 if self.ignore_shared:
172 mr_addr = self.file.read64()
173 flags &= ~self.RAM_SAVE_FLAG_MEM_SIZE
175 if flags & self.RAM_SAVE_FLAG_COMPRESS:
176 if flags & self.RAM_SAVE_FLAG_CONTINUE:
177 flags &= ~self.RAM_SAVE_FLAG_CONTINUE
179 self.name = self.file.readstr()
180 fill_char = self.file.read8()
182 if self.write_memory and fill_char != 0:
183 self.files[self.name].seek(addr, os.SEEK_SET)
184 self.files[self.name].write(chr(fill_char) * self.TARGET_PAGE_SIZE)
185 if self.dump_memory:
186self.memory['%s (0x%016x)' % (self.name, addr)] = 'Filled with 0x%02x' % fill_char
187 flags &= ~self.RAM_SAVE_FLAG_COMPRESS
188 elif flags & self.RAM_SAVE_FLAG_PAGE:
189 if flags & self.RAM_SAVE_FLAG_CONTINUE:
190 flags &= ~self.RAM_SAVE_FLAG_CONTINUE
192 self.name = self.file.readstr()
194 if self.write_memory or self.dump_memory:
195 data = self.file.readvar(size = self.TARGET_PAGE_SIZE)
197 self.file.file.seek(self.TARGET_PAGE_SIZE, 1)
199 if self.write_memory:
200 self.files[self.name].seek(addr, os.SEEK_SET)
201 self.files[self.name].write(data)
202 if self.dump_memory:
204 self.memory['%s (0x%016x)' % (self.name, addr)] = hexdata
206 flags &= ~self.RAM_SAVE_FLAG_PAGE
207 elif flags & self.RAM_SAVE_FLAG_XBZRLE:
209 elif flags & self.RAM_SAVE_FLAG_HOOK:
211 if flags & self.RAM_SAVE_FLAG_MULTIFD_FLUSH:
215 if flags & self.RAM_SAVE_FLAG_EOS:
221 def __del__(self): argument
222 if self.write_memory:
223 for key in self.files:
224 self.files[key].close()
230 def __init__(self, file, version_id, device, section_key): argument
234 self.file = file
235 self.section_key = section_key
237 def read(self): argument
239 header = self.file.read32()
251 index = self.file.read32()
252 n_valid = self.file.read16()
253 n_invalid = self.file.read16()
258 self.file.readvar(n_valid * self.HASH_PTE_SIZE_64)
260 def getDict(self): argument
270 def __init__(self, file, version_id, device, section_key): argument
274 self.file = file
275 self.section_key = section_key
277 def read(self): argument
280 addr_flags = self.file.read64()
283 if flags & self.STATTR_FLAG_DONE:
284 pos = self.file.tell()
286 elif flags & self.STATTR_FLAG_EOS:
292 self.file.seek(pos, os.SEEK_SET)
296 if (flags & self.STATTR_FLAG_ERROR):
298 count = self.file.read64()
299 self.file.readvar(count)
301 def getDict(self): argument
306 def __init__(self, file, desc): argument
307 self.file = file
308 self.desc = desc
309 self.caps = []
311 def parse_capabilities(self, vmsd_caps): argument
316 self.caps = vmsd_caps.data['capabilities']
318 if type(self.caps) != list:
319 self.caps = [self.caps]
321 if len(self.caps) != ncaps:
325 def has_capability(self, cap): argument
326 return any([str(c) == cap for c in self.caps])
328 def read(self): argument
329 if self.desc:
330 version_id = self.desc['version']
331 section = VMSDSection(self.file, version_id, self.desc,
334 self.parse_capabilities(
339 name_len = self.file.read32()
340 name = self.file.readstr(len = name_len)
343 def __init__(self, desc, file): argument
344 self.file = file
345 self.desc = desc
346 self.data = ""
348 def __repr__(self): argument
349 return str(self.__str__())
351 def __str__(self): argument
352 return " ".join("{0:02x}".format(c) for c in self.data)
354 def getDict(self): argument
355 return self.__str__()
357 def read(self): argument
358 size = int(self.desc['size'])
359 self.data = self.file.readvar(size)
360 return self.data
363 def __init__(self, desc, file): argument
364 self.file = file
365 self.desc = desc
366 self.data = ""
368 def __repr__(self): argument
369 return self.data
371 def __str__(self): argument
372 return self.data
374 def read(self): argument
375 len = self.file.read8()
376 self.data = self.file.readstr(len)
380 def __init__(self, desc, file): argument
381 super(VMSDFieldInt, self).__init__(desc, file)
382 self.size = int(desc['size'])
383 self.format = '0x%%0%dx' % (self.size * 2)
384 self.sdtype = '>i%d' % self.size
385 self.udtype = '>u%d' % self.size
387 def __repr__(self): argument
388 if self.data < 0:
389 return ('%s (%d)' % ((self.format % self.udata), self.data))
391 return self.format % self.data
393 def __str__(self): argument
394 return self.__repr__()
396 def getDict(self): argument
397 return self.__str__()
399 def read(self): argument
400 super(VMSDFieldInt, self).read()
401 self.sdata = int.from_bytes(self.data, byteorder='big', signed=True)
402 self.udata = int.from_bytes(self.data, byteorder='big', signed=False)
403 self.data = self.sdata
404 return self.data
407 def __init__(self, desc, file): argument
408 super(VMSDFieldUInt, self).__init__(desc, file)
410 def read(self): argument
411 super(VMSDFieldUInt, self).read()
412 self.data = self.udata
413 return self.data
416 def __init__(self, desc, file): argument
417 super(VMSDFieldIntLE, self).__init__(desc, file)
418 self.dtype = '<i%d' % self.size
423 def __init__(self, desc, file): argument
424 super(VMSDFieldNull, self).__init__(desc, file)
426 def __repr__(self): argument
434 def __str__(self): argument
435 return self.__repr__()
437 def read(self): argument
438 super(VMSDFieldNull, self).read()
439 assert(self.data == self.NULL_PTR_MARKER)
440 return self.data
443 def __init__(self, desc, file): argument
444 super(VMSDFieldBool, self).__init__(desc, file)
446 def __repr__(self): argument
447 return self.data.__repr__()
449 def __str__(self): argument
450 return self.data.__str__()
452 def getDict(self): argument
453 return self.data
455 def read(self): argument
456 super(VMSDFieldBool, self).read()
457 if self.data[0] == 0:
458 self.data = False
460 self.data = True
461 return self.data
466 def __init__(self, desc, file): argument
467 super(VMSDFieldStruct, self).__init__(desc, file)
468 self.data = collections.OrderedDict()
470 if 'fields' not in self.desc['struct']:
471 raise Exception("No fields in struct. VMSD:\n%s" % self.desc)
475 for field in self.desc['struct']['fields']:
487 self.desc['struct']['fields'] = new_fields
489 def __repr__(self): argument
490 return self.data.__repr__()
492 def __str__(self): argument
493 return self.data.__str__()
495 def read(self): argument
496 for field in self.desc['struct']['fields']:
502 field['data'] = reader(field, self.file)
517 if fname not in self.data:
518 self.data[fname] = fdata
519 elif type(self.data[fname]) == list:
520 self.data[fname].append(fdata)
522 tmp = self.data[fname]
523 self.data[fname] = [tmp, fdata]
525 if 'subsections' in self.desc['struct']:
526 for subsection in self.desc['struct']['subsections']:
527 if self.file.read8() != self.QEMU_VM_SUBSECTION:
528 …se Exception("Subsection %s not found at offset %x" % ( subsection['vmsd_name'], self.file.tell()))
529 name = self.file.readstr()
530 version_id = self.file.read32()
535 self.data[name] = VMSDSection(self.file, version_id, subsection, (name, 0))
536 self.data[name].read()
538 def getDictItem(self, value): argument
545 return self.getDictOrderedDict(value)
548 return self.getDictArray(value)
555 def getDictArray(self, array): argument
558 r.append(self.getDictItem(value))
561 def getDictOrderedDict(self, dict): argument
564 r[key] = self.getDictItem(value)
567 def getDict(self): argument
568 return self.getDictOrderedDict(self.data)
598 def __init__(self, file, version_id, device, section_key): argument
599 self.file = file
600 self.data = ""
601 self.vmsd_name = ""
602 self.section_key = section_key
605 self.vmsd_name = device['vmsd_name']
608 super(VMSDSection, self).__init__({ 'struct' : desc }, file)
625 def __init__(self, filename): argument
626 self.section_classes = {
631 self.filename = filename
632 self.vmsd_desc = None
633 self.vmsd_json = ""
635 def read(self, desc_only = False, dump_memory = False, argument
638 file = MigrationFile(self.filename)
639 self.vmsd_json = file.read_migration_debug_json()
643 if data != self.QEMU_VM_FILE_MAGIC:
648 if data != self.QEMU_VM_FILE_VERSION:
651 self.load_vmsd_json(file)
654 self.sections = collections.OrderedDict()
660 ramargs['page_size'] = self.vmsd_desc['page_size']
664 self.section_classes[('ram',0)][1] = ramargs
668 if section_type == self.QEMU_VM_EOF:
670 elif section_type == self.QEMU_VM_CONFIGURATION:
671 config_desc = self.vmsd_desc.get('configuration')
675 … elif section_type == self.QEMU_VM_SECTION_START or section_type == self.QEMU_VM_SECTION_FULL:
681 classdesc = self.section_classes[section_key]
683 self.sections[section_id] = section
685 … elif section_type == self.QEMU_VM_SECTION_PART or section_type == self.QEMU_VM_SECTION_END:
687 self.sections[section_id].read()
688 elif section_type == self.QEMU_VM_SECTION_FOOTER:
696 def load_vmsd_json(self, file): argument
697 self.vmsd_desc = json.loads(self.vmsd_json,
699 for device in self.vmsd_desc['devices']:
704 self.section_classes[key] = value
706 def getDict(self): argument
708 for (key, value) in self.sections.items():
716 def default(self, o): argument
719 return json.JSONEncoder.default(self, o)