1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/google-breakpad/src/processor/minidump_dump.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,213 @@ 1.4 +// Copyright (c) 2006, Google Inc. 1.5 +// All rights reserved. 1.6 +// 1.7 +// Redistribution and use in source and binary forms, with or without 1.8 +// modification, are permitted provided that the following conditions are 1.9 +// met: 1.10 +// 1.11 +// * Redistributions of source code must retain the above copyright 1.12 +// notice, this list of conditions and the following disclaimer. 1.13 +// * Redistributions in binary form must reproduce the above 1.14 +// copyright notice, this list of conditions and the following disclaimer 1.15 +// in the documentation and/or other materials provided with the 1.16 +// distribution. 1.17 +// * Neither the name of Google Inc. nor the names of its 1.18 +// contributors may be used to endorse or promote products derived from 1.19 +// this software without specific prior written permission. 1.20 +// 1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.32 + 1.33 +// minidump_dump.cc: Print the contents of a minidump file in somewhat 1.34 +// readable text. 1.35 +// 1.36 +// Author: Mark Mentovai 1.37 + 1.38 +#include <stdio.h> 1.39 +#include <string.h> 1.40 + 1.41 +#include "common/scoped_ptr.h" 1.42 +#include "google_breakpad/processor/minidump.h" 1.43 +#include "processor/logging.h" 1.44 + 1.45 +namespace { 1.46 + 1.47 +using google_breakpad::Minidump; 1.48 +using google_breakpad::MinidumpThreadList; 1.49 +using google_breakpad::MinidumpModuleList; 1.50 +using google_breakpad::MinidumpMemoryInfoList; 1.51 +using google_breakpad::MinidumpMemoryList; 1.52 +using google_breakpad::MinidumpException; 1.53 +using google_breakpad::MinidumpAssertion; 1.54 +using google_breakpad::MinidumpSystemInfo; 1.55 +using google_breakpad::MinidumpMiscInfo; 1.56 +using google_breakpad::MinidumpBreakpadInfo; 1.57 + 1.58 +static void DumpRawStream(Minidump *minidump, 1.59 + uint32_t stream_type, 1.60 + const char *stream_name, 1.61 + int *errors) { 1.62 + uint32_t length = 0; 1.63 + if (!minidump->SeekToStreamType(stream_type, &length)) { 1.64 + return; 1.65 + } 1.66 + 1.67 + printf("Stream %s:\n", stream_name); 1.68 + 1.69 + if (length == 0) { 1.70 + printf("\n"); 1.71 + return; 1.72 + } 1.73 + std::vector<char> contents(length); 1.74 + if (!minidump->ReadBytes(&contents[0], length)) { 1.75 + ++*errors; 1.76 + BPLOG(ERROR) << "minidump.ReadBytes failed"; 1.77 + return; 1.78 + } 1.79 + size_t current_offset = 0; 1.80 + while (current_offset < length) { 1.81 + size_t remaining = length - current_offset; 1.82 + // Printf requires an int and direct casting from size_t results 1.83 + // in compatibility warnings. 1.84 + uint32_t int_remaining = remaining; 1.85 + printf("%.*s", int_remaining, &contents[current_offset]); 1.86 + char *next_null = reinterpret_cast<char *>( 1.87 + memchr(&contents[current_offset], 0, remaining)); 1.88 + if (next_null == NULL) 1.89 + break; 1.90 + printf("\\0\n"); 1.91 + size_t null_offset = next_null - &contents[0]; 1.92 + current_offset = null_offset + 1; 1.93 + } 1.94 + printf("\n\n"); 1.95 +} 1.96 + 1.97 +static bool PrintMinidumpDump(const char *minidump_file) { 1.98 + Minidump minidump(minidump_file); 1.99 + if (!minidump.Read()) { 1.100 + BPLOG(ERROR) << "minidump.Read() failed"; 1.101 + return false; 1.102 + } 1.103 + minidump.Print(); 1.104 + 1.105 + int errors = 0; 1.106 + 1.107 + MinidumpThreadList *thread_list = minidump.GetThreadList(); 1.108 + if (!thread_list) { 1.109 + ++errors; 1.110 + BPLOG(ERROR) << "minidump.GetThreadList() failed"; 1.111 + } else { 1.112 + thread_list->Print(); 1.113 + } 1.114 + 1.115 + MinidumpModuleList *module_list = minidump.GetModuleList(); 1.116 + if (!module_list) { 1.117 + ++errors; 1.118 + BPLOG(ERROR) << "minidump.GetModuleList() failed"; 1.119 + } else { 1.120 + module_list->Print(); 1.121 + } 1.122 + 1.123 + MinidumpMemoryList *memory_list = minidump.GetMemoryList(); 1.124 + if (!memory_list) { 1.125 + ++errors; 1.126 + BPLOG(ERROR) << "minidump.GetMemoryList() failed"; 1.127 + } else { 1.128 + memory_list->Print(); 1.129 + } 1.130 + 1.131 + MinidumpException *exception = minidump.GetException(); 1.132 + if (!exception) { 1.133 + BPLOG(INFO) << "minidump.GetException() failed"; 1.134 + } else { 1.135 + exception->Print(); 1.136 + } 1.137 + 1.138 + MinidumpAssertion *assertion = minidump.GetAssertion(); 1.139 + if (!assertion) { 1.140 + BPLOG(INFO) << "minidump.GetAssertion() failed"; 1.141 + } else { 1.142 + assertion->Print(); 1.143 + } 1.144 + 1.145 + MinidumpSystemInfo *system_info = minidump.GetSystemInfo(); 1.146 + if (!system_info) { 1.147 + ++errors; 1.148 + BPLOG(ERROR) << "minidump.GetSystemInfo() failed"; 1.149 + } else { 1.150 + system_info->Print(); 1.151 + } 1.152 + 1.153 + MinidumpMiscInfo *misc_info = minidump.GetMiscInfo(); 1.154 + if (!misc_info) { 1.155 + ++errors; 1.156 + BPLOG(ERROR) << "minidump.GetMiscInfo() failed"; 1.157 + } else { 1.158 + misc_info->Print(); 1.159 + } 1.160 + 1.161 + MinidumpBreakpadInfo *breakpad_info = minidump.GetBreakpadInfo(); 1.162 + if (!breakpad_info) { 1.163 + // Breakpad info is optional, so don't treat this as an error. 1.164 + BPLOG(INFO) << "minidump.GetBreakpadInfo() failed"; 1.165 + } else { 1.166 + breakpad_info->Print(); 1.167 + } 1.168 + 1.169 + MinidumpMemoryInfoList *memory_info_list = minidump.GetMemoryInfoList(); 1.170 + if (!memory_info_list) { 1.171 + ++errors; 1.172 + BPLOG(ERROR) << "minidump.GetMemoryInfoList() failed"; 1.173 + } else { 1.174 + memory_info_list->Print(); 1.175 + } 1.176 + 1.177 + DumpRawStream(&minidump, 1.178 + MD_LINUX_CMD_LINE, 1.179 + "MD_LINUX_CMD_LINE", 1.180 + &errors); 1.181 + DumpRawStream(&minidump, 1.182 + MD_LINUX_ENVIRON, 1.183 + "MD_LINUX_ENVIRON", 1.184 + &errors); 1.185 + DumpRawStream(&minidump, 1.186 + MD_LINUX_LSB_RELEASE, 1.187 + "MD_LINUX_LSB_RELEASE", 1.188 + &errors); 1.189 + DumpRawStream(&minidump, 1.190 + MD_LINUX_PROC_STATUS, 1.191 + "MD_LINUX_PROC_STATUS", 1.192 + &errors); 1.193 + DumpRawStream(&minidump, 1.194 + MD_LINUX_CPU_INFO, 1.195 + "MD_LINUX_CPU_INFO", 1.196 + &errors); 1.197 + DumpRawStream(&minidump, 1.198 + MD_LINUX_MAPS, 1.199 + "MD_LINUX_MAPS", 1.200 + &errors); 1.201 + 1.202 + return errors == 0; 1.203 +} 1.204 + 1.205 +} // namespace 1.206 + 1.207 +int main(int argc, char **argv) { 1.208 + BPLOG_INIT(&argc, &argv); 1.209 + 1.210 + if (argc != 2) { 1.211 + fprintf(stderr, "usage: %s <file>\n", argv[0]); 1.212 + return 1; 1.213 + } 1.214 + 1.215 + return PrintMinidumpDump(argv[1]) ? 0 : 1; 1.216 +}