| 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..5dce8949a5215f2a8f631ea026c427584d81dd3a
|
| --- /dev/null
|
| +++ b/components/browser_watcher/postmortem_minidump_writer.h
|
| @@ -0,0 +1,115 @@
|
| +// 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"
|
| +#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;
|
| +
|
| + PostmortemMinidumpWriter();
|
| + ~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,
|
| + FILE* minidump_file);
|
| +
|
| + 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);
|
| + 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);
|
| + 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_;
|
| +
|
| + // Structure for the directory.
|
| + std::vector<MINIDUMP_DIRECTORY> directory_;
|
| +
|
| + // The file to write to.
|
| + FILE* minidump_file_;
|
| +
|
| + 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_
|
|
|