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

Side by Side 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: Add CrashpadInfo to minidump 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_BROWSER_WATCHER_POSTMORTEM_MINIDUMP_WRITER_H_
6 #define COMPONENTS_BROWSER_WATCHER_POSTMORTEM_MINIDUMP_WRITER_H_
7
8 #include <stdint.h>
9
10 #include <map>
11 #include <string>
12 #include <vector>
13
14 #include "base/files/scoped_file.h"
15 #include "base/macros.h"
16 #include "base/strings/string_piece.h"
17 #include "components/browser_watcher/stability_report.pb.h"
18 #include "third_party/crashpad/crashpad/minidump/minidump_extensions.h"
19 #include "third_party/crashpad/crashpad/util/misc/uuid.h"
20
21 namespace browser_watcher {
22
23 // A class with functionality for writing minimal minidump containers to wrap
24 // postmortem stability reports.
25 // TODO(manzagop): remove this class once CrashPad takes over writing postmortem
26 // minidumps.
27 class PostmortemMinidumpWriter {
28 public:
29 using Position = uint32_t;
30
31 PostmortemMinidumpWriter();
32 ~PostmortemMinidumpWriter() = default;
33
34 // Write to |minidump_file| a minimal minidump that wraps |report|. Returns
35 // true on success, false otherwise.
36 bool WriteDump(const StabilityReport& report,
37 const crashpad::UUID& client_id,
38 const crashpad::UUID& report_id,
39 FILE* minidump_file);
40
41 private:
42 // The minidump header is always located at the head.
43 static const Position kHeaderPos = 0U;
44
45 bool AppendCrashpadInfo(const crashpad::UUID& client_id,
46 const crashpad::UUID& report_id,
47 const std::map<std::string, std::string>& crash_keys);
48
49 bool AppendCrashpadDictionaryEntry(
50 const std::string& key,
51 const std::string& value,
52 std::vector<crashpad::MinidumpSimpleStringDictionaryEntry>* entries);
53
54 // Allocate |size_bytes| within the minidump. On success, |pos| contains the
55 // location of the allocation. Returns true on success, false otherwise.
56 bool Allocate(size_t size_bytes, Position* pos);
57
58 // Write to pre-allocated space.
59 template <class DataType>
60 bool Write(Position pos, const DataType& data);
61 bool WriteBytes(Position pos, size_t size_bytes, const void* data);
62
63 // Allocate space for and write the contents of |data|. On success, |pos|
64 // contains the location of the write. Returns true on success, false
65 // otherwise.
66 template <class DataType>
67 bool Append(const DataType& data, Position* pos);
68 template <class DataType>
69 bool AppendVec(const std::vector<DataType>& data, Position* pos);
70 bool AppendUtf8String(const std::string data, Position* pos);
71 bool AppendBytes(base::StringPiece data, Position* pos);
72
73 // Safely increment |cursor_| by |size_bytes|.
74 bool IncrementCursor(size_t size_bytes);
75
76 // The next allocatable position.
77 Position cursor_;
78
79 // Structure for the directory.
80 std::vector<MINIDUMP_DIRECTORY> directory_;
81
82 // The file to write to.
83 FILE* minidump_file_;
84
85 DISALLOW_COPY_AND_ASSIGN(PostmortemMinidumpWriter);
86 };
87
88 template <class DataType>
89 bool PostmortemMinidumpWriter::Write(Position pos, const DataType& data) {
90 return WriteBytes(pos, sizeof(data), &data);
91 }
92
93 template <class DataType>
94 bool PostmortemMinidumpWriter::Append(const DataType& data, Position* pos) {
95 DCHECK(pos);
96 if (!Allocate(sizeof(data), pos))
97 return false;
98 return Write(*pos, data);
99 }
100
101 template <class DataType>
102 bool PostmortemMinidumpWriter::AppendVec(const std::vector<DataType>& data,
103 Position* pos) {
104 DCHECK(!data.empty());
105 DCHECK(pos);
106
107 size_t size_bytes = sizeof(DataType) * data.size();
108 if (!Allocate(size_bytes, pos))
109 return false;
110 return WriteBytes(*pos, size_bytes, &data.at(0));
111 }
112
113 } // namespace browser_watcher
114
115 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_MINIDUMP_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698