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

Unified Diff: components/browser_watcher/postmortem_minidump_writer.h

Issue 2128683002: Collect unclean shutdown debug information (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tracker
Patch Set: Merge Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: components/browser_watcher/postmortem_minidump_writer.h
diff --git a/components/browser_watcher/postmortem_minidump_writer.h b/components/browser_watcher/postmortem_minidump_writer.h
new file mode 100644
index 0000000000000000000000000000000000000000..4570e703270db1b875ae3e646ab4d957a9c23adf
--- /dev/null
+++ b/components/browser_watcher/postmortem_minidump_writer.h
@@ -0,0 +1,116 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_BROWSER_WATCHER_POSTMORTEM_MINIDUMP_WRITER_H_
+#define COMPONENTS_BROWSER_WATCHER_POSTMORTEM_MINIDUMP_WRITER_H_
+
+#include <stdint.h>
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/files/scoped_file.h"
Sigurður Ásgeirsson 2016/08/11 17:44:14 doesn't look like you need this include?
manzagop (departed) 2016/08/12 21:23:22 Done.
+#include "base/macros.h"
+#include "base/strings/string_piece.h"
+#include "components/browser_watcher/stability_report.pb.h"
+#include "third_party/crashpad/crashpad/minidump/minidump_extensions.h"
+#include "third_party/crashpad/crashpad/util/misc/uuid.h"
+
+namespace browser_watcher {
+
+// A class with functionality for writing minimal minidump containers to wrap
+// postmortem stability reports.
+// TODO(manzagop): remove this class once CrashPad takes over writing postmortem
+// minidumps.
+class PostmortemMinidumpWriter {
+ public:
+ using Position = uint32_t;
Sigurður Ásgeirsson 2016/08/11 17:44:14 I assume there's a constraint on this type due to
manzagop (departed) 2016/08/12 21:23:21 Right, it's used to assign to an RVA. I added a co
+
+ // Note: the caller owns |minidump_file| and is responsible to keep it valid
+ // for the lifetime of this object.
+ explicit PostmortemMinidumpWriter(FILE* minidump_file);
Sigurður Ásgeirsson 2016/08/11 17:44:14 are there other constraints on minidump_file - I t
manzagop (departed) 2016/08/12 21:23:21 Hm, I'm not sure how to check this from a FILE* to
+ ~PostmortemMinidumpWriter() = default;
+
+ // Write to |minidump_file| a minimal minidump that wraps |report|. Returns
+ // true on success, false otherwise.
+ bool WriteDump(const StabilityReport& report,
+ const crashpad::UUID& client_id,
+ const crashpad::UUID& report_id);
+
+ private:
+ // The minidump header is always located at the head.
+ static const Position kHeaderPos = 0U;
+
+ bool AppendCrashpadInfo(const crashpad::UUID& client_id,
+ const crashpad::UUID& report_id,
+ const std::map<std::string, std::string>& crash_keys);
+
+ bool AppendCrashpadDictionaryEntry(
+ const std::string& key,
+ const std::string& value,
+ std::vector<crashpad::MinidumpSimpleStringDictionaryEntry>* entries);
+
+ // Allocate |size_bytes| within the minidump. On success, |pos| contains the
+ // location of the allocation. Returns true on success, false otherwise.
+ bool Allocate(size_t size_bytes, Position* pos);
+
+ // Write to pre-allocated space.
+ template <class DataType>
+ bool Write(Position pos, const DataType& data);
Sigurður Ásgeirsson 2016/08/11 17:44:14 looks to me this function is used once - maybe bet
manzagop (departed) 2016/08/12 21:23:21 It's also used in the (templated) Append.
+ bool WriteBytes(Position pos, size_t size_bytes, const void* data);
+
+ // Allocate space for and write the contents of |data|. On success, |pos|
+ // contains the location of the write. Returns true on success, false
+ // otherwise.
+ template <class DataType>
+ bool Append(const DataType& data, Position* pos);
+ template <class DataType>
+ bool AppendVec(const std::vector<DataType>& data, Position* pos);
+ bool AppendUtf8String(const std::string data, Position* pos);
Sigurður Ásgeirsson 2016/08/11 17:44:14 string& or StringPiece?
manzagop (departed) 2016/08/12 21:23:21 Went with StringPiece. Done.
+ bool AppendBytes(base::StringPiece data, Position* pos);
+
+ // Safely increment |cursor_| by |size_bytes|.
+ bool IncrementCursor(size_t size_bytes);
+
+ // The next allocatable position.
+ Position cursor_;
Sigurður Ásgeirsson 2016/08/11 17:44:14 good comment, but cursor_ has connotations to a wr
manzagop (departed) 2016/08/12 21:23:21 Done.
+
+ // Structure for the directory.
Sigurður Ásgeirsson 2016/08/11 17:44:14 storage for the directory during writes?
manzagop (departed) 2016/08/12 21:23:21 Done.
+ std::vector<MINIDUMP_DIRECTORY> directory_;
+
+ // The file to write to.
+ FILE* minidump_file_; // Not owned.
+
+ DISALLOW_COPY_AND_ASSIGN(PostmortemMinidumpWriter);
+};
+
+template <class DataType>
+bool PostmortemMinidumpWriter::Write(Position pos, const DataType& data) {
+ return WriteBytes(pos, sizeof(data), &data);
+}
+
+template <class DataType>
+bool PostmortemMinidumpWriter::Append(const DataType& data, Position* pos) {
+ DCHECK(pos);
+ if (!Allocate(sizeof(data), pos))
+ return false;
+ return Write(*pos, data);
+}
+
+template <class DataType>
+bool PostmortemMinidumpWriter::AppendVec(const std::vector<DataType>& data,
+ Position* pos) {
+ DCHECK(!data.empty());
+ DCHECK(pos);
+
+ size_t size_bytes = sizeof(DataType) * data.size();
+ if (!Allocate(size_bytes, pos))
+ return false;
+ return WriteBytes(*pos, size_bytes, &data.at(0));
+}
+
+} // namespace browser_watcher
+
+#endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_MINIDUMP_WRITER_H_

Powered by Google App Engine
This is Rietveld 408576698