Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: components/browser_watcher/dump_stability_report_main_win.cc

Issue 2866163002: Update stability report dumper so it handles non-postmortem minidumps (Closed)
Patch Set: presubmit changes Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // A utility for printing the contents of a postmortem stability minidump. 5 // A utility for printing the contents of a postmortem stability minidump.
6 6
7 #include <windows.h> // NOLINT 7 #include <windows.h> // NOLINT
8
8 #include <dbghelp.h> 9 #include <dbghelp.h>
9 10
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
13 #include "base/files/scoped_file.h" 14 #include "base/files/scoped_file.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "components/browser_watcher/stability_report.pb.h" 17 #include "components/browser_watcher/stability_report.pb.h"
17 18
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 152
152 // TODO(manzagop): flesh out as StabilityReport gets fleshed out. 153 // TODO(manzagop): flesh out as StabilityReport gets fleshed out.
153 void PrintReport(FILE* out, const browser_watcher::StabilityReport& report) { 154 void PrintReport(FILE* out, const browser_watcher::StabilityReport& report) {
154 PrintUserData(out, 0, report.global_data()); 155 PrintUserData(out, 0, report.global_data());
155 for (int i = 0; i < report.process_states_size(); ++i) { 156 for (int i = 0; i < report.process_states_size(); ++i) {
156 const browser_watcher::ProcessState process = report.process_states(i); 157 const browser_watcher::ProcessState process = report.process_states(i);
157 PrintProcessState(out, process); 158 PrintProcessState(out, process);
158 } 159 }
159 } 160 }
160 161
162 bool GetStabilityStreamRvaAndSize(RVA directory_rva,
163 ULONG32 stream_count,
164 FILE* file,
165 RVA* report_rva,
166 ULONG32* report_size_bytes) {
167 std::vector<MINIDUMP_DIRECTORY> directory;
168 directory.resize(stream_count);
169
170 CHECK_EQ(0, fseek(file, directory_rva, SEEK_SET));
171 CHECK_EQ(stream_count, fread(directory.data(), sizeof(MINIDUMP_DIRECTORY),
172 stream_count, file));
173
174 for (const MINIDUMP_DIRECTORY& entry : directory) {
175 constexpr ULONG32 kStabilityStream = static_cast<ULONG32>(0x4B6B0002);
176 if (entry.StreamType == kStabilityStream) {
177 *report_rva = entry.Location.Rva;
178 *report_size_bytes = entry.Location.DataSize;
179 return true;
180 }
181 }
182
183 return false;
184 }
185
161 int Main(int argc, char** argv) { 186 int Main(int argc, char** argv) {
162 base::CommandLine::Init(argc, argv); 187 base::CommandLine::Init(argc, argv);
163 188
164 // Get the dump. 189 // Get the dump.
165 base::FilePath minidump_path; 190 base::FilePath minidump_path;
166 if (!ParseCommandLine(base::CommandLine::ForCurrentProcess(), &minidump_path)) 191 if (!ParseCommandLine(base::CommandLine::ForCurrentProcess(), &minidump_path))
167 return 1; 192 return 1;
168 193
169 // Read the minidump to extract the proto. 194 // Read the minidump to extract the proto.
170 base::ScopedFILE minidump_file; 195 base::ScopedFILE minidump_file;
171 minidump_file.reset(base::OpenFile(minidump_path, "rb")); 196 minidump_file.reset(base::OpenFile(minidump_path, "rb"));
172 CHECK(minidump_file.get()); 197 CHECK(minidump_file.get());
173 198
174 // Read the header. 199 // Read the header.
175 // TODO(manzagop): leverage Crashpad to do this. 200 // TODO(manzagop): leverage Crashpad to do this.
176 MINIDUMP_HEADER header = {}; 201 MINIDUMP_HEADER header = {};
177 CHECK_EQ(1U, fread(&header, sizeof(header), 1U, minidump_file.get())); 202 CHECK_EQ(1U, fread(&header, sizeof(header), 1U, minidump_file.get()));
178 CHECK_EQ(static_cast<ULONG32>(MINIDUMP_SIGNATURE), header.Signature); 203 CHECK_EQ(static_cast<ULONG32>(MINIDUMP_SIGNATURE), header.Signature);
179 CHECK_EQ(2U, header.NumberOfStreams); 204 fprintf(stdout, "Number of streams: %u\n", header.NumberOfStreams);
180 RVA directory_rva = header.StreamDirectoryRva; 205 RVA directory_rva = header.StreamDirectoryRva;
181 206
182 // Read the directory entry for the stability report's stream. 207 RVA report_rva;
183 // Note: this hardcodes an expectation that the stability report is the first 208 ULONG32 report_size_bytes;
184 // encountered stream. This is acceptable for a debug tool. 209 CHECK(GetStabilityStreamRvaAndSize(directory_rva, header.NumberOfStreams,
185 MINIDUMP_DIRECTORY directory = {}; 210 minidump_file.get(), &report_rva,
186 CHECK_EQ(0, fseek(minidump_file.get(), directory_rva, SEEK_SET)); 211 &report_size_bytes));
187 CHECK_EQ(1U, fread(&directory, sizeof(directory), 1U, minidump_file.get()));
188 CHECK_EQ(static_cast<ULONG32>(0x4B6B0002), directory.StreamType);
189 RVA report_rva = directory.Location.Rva;
190 ULONG32 report_size_bytes = directory.Location.DataSize;
191 212
192 // Read the serialized stability report. 213 // Read the serialized stability report.
193 std::string serialized_report; 214 std::string serialized_report;
194 serialized_report.resize(report_size_bytes); 215 serialized_report.resize(report_size_bytes);
195 CHECK_EQ(0, fseek(minidump_file.get(), report_rva, SEEK_SET)); 216 CHECK_EQ(0, fseek(minidump_file.get(), report_rva, SEEK_SET));
196 CHECK_EQ(report_size_bytes, fread(&serialized_report.at(0), 1, 217 CHECK_EQ(report_size_bytes, fread(&serialized_report.at(0), 1,
197 report_size_bytes, minidump_file.get())); 218 report_size_bytes, minidump_file.get()));
198 219
199 browser_watcher::StabilityReport report; 220 browser_watcher::StabilityReport report;
200 CHECK(report.ParseFromString(serialized_report)); 221 CHECK(report.ParseFromString(serialized_report));
201 222
202 // Note: we can't use the usual protocol buffer human readable API due to 223 // Note: we can't use the usual protocol buffer human readable API due to
203 // the use of optimize_for = LITE_RUNTIME. 224 // the use of optimize_for = LITE_RUNTIME.
204 PrintReport(stdout, report); 225 PrintReport(stdout, report);
205 226
206 return 0; 227 return 0;
207 } 228 }
208 229
209 } // namespace 230 } // namespace
210 231
211 int main(int argc, char** argv) { 232 int main(int argc, char** argv) {
212 return Main(argc, argv); 233 return Main(argc, argv);
213 } 234 }
OLDNEW
« PRESUBMIT_test.py ('K') | « components/browser_watcher/dump_postmortem_minidump_main_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698