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

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: 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 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"
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.
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;
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
30
31 // Note: the caller owns |minidump_file| and is responsible to keep it valid
32 // for the lifetime of this object.
33 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
34 ~PostmortemMinidumpWriter() = default;
35
36 // Write to |minidump_file| a minimal minidump that wraps |report|. Returns
37 // true on success, false otherwise.
38 bool WriteDump(const StabilityReport& report,
39 const crashpad::UUID& client_id,
40 const crashpad::UUID& report_id);
41
42 private:
43 // The minidump header is always located at the head.
44 static const Position kHeaderPos = 0U;
45
46 bool AppendCrashpadInfo(const crashpad::UUID& client_id,
47 const crashpad::UUID& report_id,
48 const std::map<std::string, std::string>& crash_keys);
49
50 bool AppendCrashpadDictionaryEntry(
51 const std::string& key,
52 const std::string& value,
53 std::vector<crashpad::MinidumpSimpleStringDictionaryEntry>* entries);
54
55 // Allocate |size_bytes| within the minidump. On success, |pos| contains the
56 // location of the allocation. Returns true on success, false otherwise.
57 bool Allocate(size_t size_bytes, Position* pos);
58
59 // Write to pre-allocated space.
60 template <class DataType>
61 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.
62 bool WriteBytes(Position pos, size_t size_bytes, const void* data);
63
64 // Allocate space for and write the contents of |data|. On success, |pos|
65 // contains the location of the write. Returns true on success, false
66 // otherwise.
67 template <class DataType>
68 bool Append(const DataType& data, Position* pos);
69 template <class DataType>
70 bool AppendVec(const std::vector<DataType>& data, Position* pos);
71 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.
72 bool AppendBytes(base::StringPiece data, Position* pos);
73
74 // Safely increment |cursor_| by |size_bytes|.
75 bool IncrementCursor(size_t size_bytes);
76
77 // The next allocatable position.
78 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.
79
80 // 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.
81 std::vector<MINIDUMP_DIRECTORY> directory_;
82
83 // The file to write to.
84 FILE* minidump_file_; // Not owned.
85
86 DISALLOW_COPY_AND_ASSIGN(PostmortemMinidumpWriter);
87 };
88
89 template <class DataType>
90 bool PostmortemMinidumpWriter::Write(Position pos, const DataType& data) {
91 return WriteBytes(pos, sizeof(data), &data);
92 }
93
94 template <class DataType>
95 bool PostmortemMinidumpWriter::Append(const DataType& data, Position* pos) {
96 DCHECK(pos);
97 if (!Allocate(sizeof(data), pos))
98 return false;
99 return Write(*pos, data);
100 }
101
102 template <class DataType>
103 bool PostmortemMinidumpWriter::AppendVec(const std::vector<DataType>& data,
104 Position* pos) {
105 DCHECK(!data.empty());
106 DCHECK(pos);
107
108 size_t size_bytes = sizeof(DataType) * data.size();
109 if (!Allocate(size_bytes, pos))
110 return false;
111 return WriteBytes(*pos, size_bytes, &data.at(0));
112 }
113
114 } // namespace browser_watcher
115
116 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_MINIDUMP_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698