[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / components / crash / tools / dmp2minidump.py
blob7823d483681aeaf74dda9814389556f8cacb6c2a
1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """A tool to extract minidumps from dmp crash dumps."""
8 import os
9 import sys
10 from cgi import parse_multipart
13 def ProcessDump(dump_file, minidump_file):
14 """Extracts the part of the dump file that minidump_stackwalk can read.
16 The dump files generated by the breakpad integration multi-part form data
17 that include the minidump as file attachment.
19 Args:
20 dump_file: the dump file that needs to be processed.
21 minidump_file: the file to write the minidump to.
22 """
23 try:
24 dump = open(dump_file, 'rb')
25 boundary = dump.readline().strip()[2:]
26 data = parse_multipart(dump, {'boundary': boundary})
27 except:
28 print 'Failed to read dmp file %s' % dump_file
29 return
31 if not 'upload_file_minidump' in data:
32 print 'Could not find minidump file in dump.'
33 return
35 f = open(minidump_file, 'w')
36 f.write("\r\n".join(data['upload_file_minidump']))
37 f.close()
40 def main():
41 if len(sys.argv) != 3:
42 print 'Usage: %s [dmp file] [minidump]' % sys.argv[0]
43 print ''
44 print 'Extracts the minidump stored in the crash dump file'
45 return 1
47 ProcessDump(sys.argv[1], sys.argv[2])
50 if '__main__' == __name__:
51 sys.exit(main())