1 # Copyright (C) 2013 Google Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 from webkitpy.common.webkit_finder import WebKitFinder
33 from webkitpy.layout_tests.breakpad.dump_reader import DumpReader
36 _log = logging.getLogger(__name__)
39 class DumpReaderMultipart(DumpReader):
40 """Base class for Linux and Android breakpad dump reader."""
42 def __init__(self, host, build_dir):
43 super(DumpReaderMultipart, self).__init__(host, build_dir)
44 self._webkit_finder = WebKitFinder(host.filesystem)
45 self._breakpad_tools_available = None
47 def check_is_functional(self):
48 return self._check_breakpad_tools_available()
50 def _get_pid_from_dump(self, dump_file):
51 dump = self._read_dump(dump_file)
58 def _get_stack_from_dump(self, dump_file):
59 dump = self._read_dump(dump_file)
62 if not 'upload_file_minidump' in dump:
65 self._generate_breakpad_symbols_if_necessary()
66 f, temp_name = self._host.filesystem.open_binary_tempfile('dmp')
67 f.write("\r\n".join(dump['upload_file_minidump']))
70 cmd = [self._path_to_minidump_stackwalk(), temp_name, self._symbols_dir()]
72 stack = self._host.executive.run_command(cmd, return_stderr=False)
74 _log.warning('Failed to execute "%s"' % ' '.join(cmd))
77 self._host.filesystem.remove(temp_name)
80 def _read_dump(self, dump_file):
81 with self._host.filesystem.open_binary_file_for_reading(dump_file) as f:
82 boundary = f.readline().strip()[2:]
85 data = cgi.parse_multipart(f, {'boundary': boundary})
91 def _check_breakpad_tools_available(self):
92 if self._breakpad_tools_available != None:
93 return self._breakpad_tools_available
95 REQUIRED_BREAKPAD_TOOLS = [
100 for binary in REQUIRED_BREAKPAD_TOOLS:
101 full_path = self._host.filesystem.join(self._build_dir, binary)
102 if not self._host.filesystem.exists(full_path):
104 _log.error('Unable to find %s' % binary)
105 _log.error(' at %s' % full_path)
108 _log.error(" Could not find breakpad tools, unexpected crashes won't be symbolized")
109 _log.error(' Did you build the target blink_tests?')
112 self._breakpad_tools_available = result
113 return self._breakpad_tools_available
115 def _path_to_minidump_stackwalk(self):
116 return self._host.filesystem.join(self._build_dir, "minidump_stackwalk")
118 def _path_to_generate_breakpad_symbols(self):
119 return self._webkit_finder.path_from_chromium_base("components", "breakpad", "tools", "generate_breakpad_symbols.py")
121 def _symbols_dir(self):
122 return self._host.filesystem.join(self._build_dir, 'content_shell.syms')
124 def _generate_breakpad_symbols_if_necessary(self):
125 if self._host.filesystem.exists(self._symbols_dir()):
127 symbols_mtime = self._host.filesystem.mtime(self._symbols_dir())
128 for binary in self._binaries_to_symbolize():
129 full_path = self._host.filesystem.join(self._build_dir, binary)
130 if self._host.filesystem.mtime(full_path) >= symbols_mtime:
135 _log.debug("Regenerating breakpad symbols")
136 self._host.filesystem.rmtree(self._symbols_dir())
138 for binary in self._binaries_to_symbolize():
139 full_path = self._host.filesystem.join(self._build_dir, binary)
141 self._path_to_generate_breakpad_symbols(),
142 '--binary=%s' % full_path,
143 '--symbols-dir=%s' % self._symbols_dir(),
144 '--build-dir=%s' % self._build_dir,
147 self._host.executive.run_command(cmd)
149 _log.error('Failed to execute "%s"' % ' '.join(cmd))
151 def _binaries_to_symbolize(self):
152 """This routine must be implemented by subclasses.
154 Returns an array of binaries that need to be symbolized."""
155 raise NotImplementedError()
158 class DumpReaderLinux(DumpReaderMultipart):
159 """Linux breakpad dump reader."""
161 def _binaries_to_symbolize(self):
162 return ['content_shell', 'libtest_netscape_plugin.so', 'libffmpegsumo.so', 'libosmesa.so']
164 def _file_extension(self):
168 class DumpReaderAndroid(DumpReaderMultipart):
169 """Android breakpad dump reader."""
171 def _binaries_to_symbolize(self):
172 return ['lib/libcontent_shell_content_view.so']
174 def _file_extension(self):