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."""
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.
20 dump_file: the dump file that needs to be processed.
21 minidump_file: the file to write the minidump to.
24 dump
= open(dump_file
, 'rb')
25 boundary
= dump
.readline().strip()[2:]
26 data
= parse_multipart(dump
, {'boundary': boundary
})
28 print 'Failed to read dmp file %s' % dump_file
31 if not 'upload_file_minidump' in data
:
32 print 'Could not find minidump file in dump.'
35 f
= open(minidump_file
, 'w')
36 f
.write("\r\n".join(data
['upload_file_minidump']))
41 if len(sys
.argv
) != 3:
42 print 'Usage: %s [dmp file] [minidump]' % sys
.argv
[0]
44 print 'Extracts the minidump stored in the crash dump file'
47 ProcessDump(sys
.argv
[1], sys
.argv
[2])
50 if '__main__' == __name__
: