PageRenderTime 53ms CodeModel.GetById 19ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/breakpad/processor/minidump_dump.cc

http://github.com/tomahawk-player/tomahawk
C++ | 214 lines | 154 code | 25 blank | 35 comment | 29 complexity | 155a85c3da9ef4afb316660d91513cee MD5 | raw file
  1// Copyright (c) 2006, Google Inc.
  2// All rights reserved.
  3//
  4// Redistribution and use in source and binary forms, with or without
  5// modification, are permitted provided that the following conditions are
  6// met:
  7//
  8//     * Redistributions of source code must retain the above copyright
  9// notice, this list of conditions and the following disclaimer.
 10//     * Redistributions in binary form must reproduce the above
 11// copyright notice, this list of conditions and the following disclaimer
 12// in the documentation and/or other materials provided with the
 13// distribution.
 14//     * Neither the name of Google Inc. nor the names of its
 15// contributors may be used to endorse or promote products derived from
 16// this software without specific prior written permission.
 17//
 18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 29
 30// minidump_dump.cc: Print the contents of a minidump file in somewhat
 31// readable text.
 32//
 33// Author: Mark Mentovai
 34
 35#include <stdio.h>
 36#include <string.h>
 37
 38#include "client/linux/minidump_writer/minidump_extension_linux.h"
 39#include "google_breakpad/processor/minidump.h"
 40#include "processor/logging.h"
 41#include "processor/scoped_ptr.h"
 42
 43namespace {
 44
 45using google_breakpad::Minidump;
 46using google_breakpad::MinidumpThreadList;
 47using google_breakpad::MinidumpModuleList;
 48using google_breakpad::MinidumpMemoryInfoList;
 49using google_breakpad::MinidumpMemoryList;
 50using google_breakpad::MinidumpException;
 51using google_breakpad::MinidumpAssertion;
 52using google_breakpad::MinidumpSystemInfo;
 53using google_breakpad::MinidumpMiscInfo;
 54using google_breakpad::MinidumpBreakpadInfo;
 55
 56static void DumpRawStream(Minidump *minidump,
 57                          u_int32_t stream_type,
 58                          const char *stream_name,
 59                          int *errors) {
 60  u_int32_t length = 0;
 61  if (!minidump->SeekToStreamType(stream_type, &length)) {
 62    return;
 63  }
 64
 65  printf("Stream %s:\n", stream_name);
 66
 67  if (length == 0) {
 68    printf("\n");
 69    return;
 70  }
 71  std::vector<char> contents(length);
 72  if (!minidump->ReadBytes(&contents[0], length)) {
 73    ++*errors;
 74    BPLOG(ERROR) << "minidump.ReadBytes failed";
 75    return;
 76  }
 77  size_t current_offset = 0;
 78  while (current_offset < length) {
 79    size_t remaining = length - current_offset;
 80    // Printf requires an int and direct casting from size_t results
 81    // in compatibility warnings.
 82    u_int32_t int_remaining = remaining;
 83    printf("%.*s", int_remaining, &contents[current_offset]);
 84    char *next_null = reinterpret_cast<char *>(
 85        memchr(&contents[current_offset], 0, remaining));
 86    if (next_null == NULL)
 87      break;
 88    printf("\\0\n");
 89    size_t null_offset = next_null - &contents[0];
 90    current_offset = null_offset + 1;
 91  }
 92  printf("\n\n");
 93}
 94
 95static bool PrintMinidumpDump(const char *minidump_file) {
 96  Minidump minidump(minidump_file);
 97  if (!minidump.Read()) {
 98    BPLOG(ERROR) << "minidump.Read() failed";
 99    return false;
100  }
101  minidump.Print();
102
103  int errors = 0;
104
105  MinidumpThreadList *thread_list = minidump.GetThreadList();
106  if (!thread_list) {
107    ++errors;
108    BPLOG(ERROR) << "minidump.GetThreadList() failed";
109  } else {
110    thread_list->Print();
111  }
112
113  MinidumpModuleList *module_list = minidump.GetModuleList();
114  if (!module_list) {
115    ++errors;
116    BPLOG(ERROR) << "minidump.GetModuleList() failed";
117  } else {
118    module_list->Print();
119  }
120
121  MinidumpMemoryList *memory_list = minidump.GetMemoryList();
122  if (!memory_list) {
123    ++errors;
124    BPLOG(ERROR) << "minidump.GetMemoryList() failed";
125  } else {
126    memory_list->Print();
127  }
128
129  MinidumpException *exception = minidump.GetException();
130  if (!exception) {
131    BPLOG(INFO) << "minidump.GetException() failed";
132  } else {
133    exception->Print();
134  }
135
136  MinidumpAssertion *assertion = minidump.GetAssertion();
137  if (!assertion) {
138    BPLOG(INFO) << "minidump.GetAssertion() failed";
139  } else {
140    assertion->Print();
141  }
142
143  MinidumpSystemInfo *system_info = minidump.GetSystemInfo();
144  if (!system_info) {
145    ++errors;
146    BPLOG(ERROR) << "minidump.GetSystemInfo() failed";
147  } else {
148    system_info->Print();
149  }
150
151  MinidumpMiscInfo *misc_info = minidump.GetMiscInfo();
152  if (!misc_info) {
153    ++errors;
154    BPLOG(ERROR) << "minidump.GetMiscInfo() failed";
155  } else {
156    misc_info->Print();
157  }
158
159  MinidumpBreakpadInfo *breakpad_info = minidump.GetBreakpadInfo();
160  if (!breakpad_info) {
161    // Breakpad info is optional, so don't treat this as an error.
162    BPLOG(INFO) << "minidump.GetBreakpadInfo() failed";
163  } else {
164    breakpad_info->Print();
165  }
166
167  MinidumpMemoryInfoList *memory_info_list = minidump.GetMemoryInfoList();
168  if (!memory_info_list) {
169    ++errors;
170    BPLOG(ERROR) << "minidump.GetMemoryInfoList() failed";
171  } else {
172    memory_info_list->Print();
173  }
174
175  DumpRawStream(&minidump,
176                MD_LINUX_CMD_LINE,
177                "MD_LINUX_CMD_LINE",
178                &errors);
179  DumpRawStream(&minidump,
180                MD_LINUX_ENVIRON,
181                "MD_LINUX_ENVIRON",
182                &errors);
183  DumpRawStream(&minidump,
184                MD_LINUX_LSB_RELEASE,
185                "MD_LINUX_LSB_RELEASE",
186                &errors);
187  DumpRawStream(&minidump,
188                MD_LINUX_PROC_STATUS,
189                "MD_LINUX_PROC_STATUS",
190                &errors);
191  DumpRawStream(&minidump,
192                MD_LINUX_CPU_INFO,
193                "MD_LINUX_CPU_INFO",
194                &errors);
195  DumpRawStream(&minidump,
196                MD_LINUX_MAPS,
197                "MD_LINUX_MAPS",
198                &errors);
199
200  return errors == 0;
201}
202
203}  // namespace
204
205int main(int argc, char **argv) {
206  BPLOG_INIT(&argc, &argv);
207
208  if (argc != 2) {
209    fprintf(stderr, "usage: %s <file>\n", argv[0]);
210    return 1;
211  }
212
213  return PrintMinidumpDump(argv[1]) ? 0 : 1;
214}