minidump_dump.cc revision 3261e8b6eac44a41341f112821482bee6c940c98
1// Copyright (C) 2006 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// minidump_dump.cc: Print the contents of a minidump file in somewhat
16// readable text.
17//
18// Author: Mark Mentovai
19
20#include <errno.h>
21#include <fcntl.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <string.h>
25#ifndef _WIN32
26#include <unistd.h>
27#define O_BINARY 0
28#else // !_WIN32
29#include <io.h>
30#define open _open
31#endif // !_WIN32
32
33#include "processor/minidump.h"
34
35
36using namespace google_airbag;
37
38
39int main(int argc, char** argv) {
40  if (argc != 2) {
41    fprintf(stderr, "usage: %s <file>\n", argv[0]);
42    exit(1);
43  }
44
45  int fd = open(argv[1], O_RDONLY | O_BINARY);
46  if (fd == -1) {
47    printf("open failed\n");
48    exit(1);
49  }
50
51  Minidump minidump(fd);
52  if (!minidump.Read()) {
53    printf("minidump.Read() failed\n");
54    exit(1);
55  }
56  minidump.Print();
57
58  int error = 0;
59
60  MinidumpThreadList* threadList = minidump.GetThreadList();
61  if (!threadList) {
62    error |= 1 << 2;
63    printf("minidump.GetThreadList() failed\n");
64  } else {
65    threadList->Print();
66  }
67
68  MinidumpModuleList* moduleList = minidump.GetModuleList();
69  if (!moduleList) {
70    error |= 1 << 3;
71    printf("minidump.GetModuleList() failed\n");
72  } else {
73    moduleList->Print();
74  }
75
76  MinidumpMemoryList* memoryList = minidump.GetMemoryList();
77  if (!memoryList) {
78    error |= 1 << 4;
79    printf("minidump.GetMemoryList() failed\n");
80  } else {
81    memoryList->Print();
82  }
83
84  MinidumpException* exception = minidump.GetException();
85  if (!exception) {
86    error |= 1 << 5;
87    printf("minidump.GetException() failed\n");
88  } else {
89    exception->Print();
90  }
91
92  MinidumpSystemInfo* systemInfo = minidump.GetSystemInfo();
93  if (!systemInfo) {
94    error |= 1 << 6;
95    printf("minidump.GetSystemInfo() failed\n");
96  } else {
97    systemInfo->Print();
98  }
99
100  MinidumpMiscInfo* miscInfo = minidump.GetMiscInfo();
101  if (!miscInfo) {
102    error |= 1 << 7;
103    printf("minidump.GetMiscInfo() failed\n");
104  } else {
105    miscInfo->Print();
106  }
107
108  // Use return instead of exit to allow destructors to run.
109  return(error);
110}
111