PageRenderTime 30ms CodeModel.GetById 20ms 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
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  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. // minidump_dump.cc: Print the contents of a minidump file in somewhat
  30. // readable text.
  31. //
  32. // Author: Mark Mentovai
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include "client/linux/minidump_writer/minidump_extension_linux.h"
  36. #include "google_breakpad/processor/minidump.h"
  37. #include "processor/logging.h"
  38. #include "processor/scoped_ptr.h"
  39. namespace {
  40. using google_breakpad::Minidump;
  41. using google_breakpad::MinidumpThreadList;
  42. using google_breakpad::MinidumpModuleList;
  43. using google_breakpad::MinidumpMemoryInfoList;
  44. using google_breakpad::MinidumpMemoryList;
  45. using google_breakpad::MinidumpException;
  46. using google_breakpad::MinidumpAssertion;
  47. using google_breakpad::MinidumpSystemInfo;
  48. using google_breakpad::MinidumpMiscInfo;
  49. using google_breakpad::MinidumpBreakpadInfo;
  50. static void DumpRawStream(Minidump *minidump,
  51. u_int32_t stream_type,
  52. const char *stream_name,
  53. int *errors) {
  54. u_int32_t length = 0;
  55. if (!minidump->SeekToStreamType(stream_type, &length)) {
  56. return;
  57. }
  58. printf("Stream %s:\n", stream_name);
  59. if (length == 0) {
  60. printf("\n");
  61. return;
  62. }
  63. std::vector<char> contents(length);
  64. if (!minidump->ReadBytes(&contents[0], length)) {
  65. ++*errors;
  66. BPLOG(ERROR) << "minidump.ReadBytes failed";
  67. return;
  68. }
  69. size_t current_offset = 0;
  70. while (current_offset < length) {
  71. size_t remaining = length - current_offset;
  72. // Printf requires an int and direct casting from size_t results
  73. // in compatibility warnings.
  74. u_int32_t int_remaining = remaining;
  75. printf("%.*s", int_remaining, &contents[current_offset]);
  76. char *next_null = reinterpret_cast<char *>(
  77. memchr(&contents[current_offset], 0, remaining));
  78. if (next_null == NULL)
  79. break;
  80. printf("\\0\n");
  81. size_t null_offset = next_null - &contents[0];
  82. current_offset = null_offset + 1;
  83. }
  84. printf("\n\n");
  85. }
  86. static bool PrintMinidumpDump(const char *minidump_file) {
  87. Minidump minidump(minidump_file);
  88. if (!minidump.Read()) {
  89. BPLOG(ERROR) << "minidump.Read() failed";
  90. return false;
  91. }
  92. minidump.Print();
  93. int errors = 0;
  94. MinidumpThreadList *thread_list = minidump.GetThreadList();
  95. if (!thread_list) {
  96. ++errors;
  97. BPLOG(ERROR) << "minidump.GetThreadList() failed";
  98. } else {
  99. thread_list->Print();
  100. }
  101. MinidumpModuleList *module_list = minidump.GetModuleList();
  102. if (!module_list) {
  103. ++errors;
  104. BPLOG(ERROR) << "minidump.GetModuleList() failed";
  105. } else {
  106. module_list->Print();
  107. }
  108. MinidumpMemoryList *memory_list = minidump.GetMemoryList();
  109. if (!memory_list) {
  110. ++errors;
  111. BPLOG(ERROR) << "minidump.GetMemoryList() failed";
  112. } else {
  113. memory_list->Print();
  114. }
  115. MinidumpException *exception = minidump.GetException();
  116. if (!exception) {
  117. BPLOG(INFO) << "minidump.GetException() failed";
  118. } else {
  119. exception->Print();
  120. }
  121. MinidumpAssertion *assertion = minidump.GetAssertion();
  122. if (!assertion) {
  123. BPLOG(INFO) << "minidump.GetAssertion() failed";
  124. } else {
  125. assertion->Print();
  126. }
  127. MinidumpSystemInfo *system_info = minidump.GetSystemInfo();
  128. if (!system_info) {
  129. ++errors;
  130. BPLOG(ERROR) << "minidump.GetSystemInfo() failed";
  131. } else {
  132. system_info->Print();
  133. }
  134. MinidumpMiscInfo *misc_info = minidump.GetMiscInfo();
  135. if (!misc_info) {
  136. ++errors;
  137. BPLOG(ERROR) << "minidump.GetMiscInfo() failed";
  138. } else {
  139. misc_info->Print();
  140. }
  141. MinidumpBreakpadInfo *breakpad_info = minidump.GetBreakpadInfo();
  142. if (!breakpad_info) {
  143. // Breakpad info is optional, so don't treat this as an error.
  144. BPLOG(INFO) << "minidump.GetBreakpadInfo() failed";
  145. } else {
  146. breakpad_info->Print();
  147. }
  148. MinidumpMemoryInfoList *memory_info_list = minidump.GetMemoryInfoList();
  149. if (!memory_info_list) {
  150. ++errors;
  151. BPLOG(ERROR) << "minidump.GetMemoryInfoList() failed";
  152. } else {
  153. memory_info_list->Print();
  154. }
  155. DumpRawStream(&minidump,
  156. MD_LINUX_CMD_LINE,
  157. "MD_LINUX_CMD_LINE",
  158. &errors);
  159. DumpRawStream(&minidump,
  160. MD_LINUX_ENVIRON,
  161. "MD_LINUX_ENVIRON",
  162. &errors);
  163. DumpRawStream(&minidump,
  164. MD_LINUX_LSB_RELEASE,
  165. "MD_LINUX_LSB_RELEASE",
  166. &errors);
  167. DumpRawStream(&minidump,
  168. MD_LINUX_PROC_STATUS,
  169. "MD_LINUX_PROC_STATUS",
  170. &errors);
  171. DumpRawStream(&minidump,
  172. MD_LINUX_CPU_INFO,
  173. "MD_LINUX_CPU_INFO",
  174. &errors);
  175. DumpRawStream(&minidump,
  176. MD_LINUX_MAPS,
  177. "MD_LINUX_MAPS",
  178. &errors);
  179. return errors == 0;
  180. }
  181. } // namespace
  182. int main(int argc, char **argv) {
  183. BPLOG_INIT(&argc, &argv);
  184. if (argc != 2) {
  185. fprintf(stderr, "usage: %s <file>\n", argv[0]);
  186. return 1;
  187. }
  188. return PrintMinidumpDump(argv[1]) ? 0 : 1;
  189. }