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

Side by Side Diff: minidump/minidump_file_writer.cc

Issue 703223003: Add MinidumpFileWriter::InitializeFromSnapshot() and its tests (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@minidump_crashpad_info_init_from_snapshot
Patch Set: Address review feedback Created 6 years, 1 month 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
« no previous file with comments | « minidump/minidump_file_writer.h ('k') | minidump/minidump_file_writer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "minidump/minidump_file_writer.h" 15 #include "minidump/minidump_file_writer.h"
16 16
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "minidump/minidump_crashpad_info_writer.h"
19 #include "minidump/minidump_exception_writer.h"
20 #include "minidump/minidump_memory_writer.h"
21 #include "minidump/minidump_misc_info_writer.h"
22 #include "minidump/minidump_module_writer.h"
23 #include "minidump/minidump_system_info_writer.h"
24 #include "minidump/minidump_thread_id_map.h"
25 #include "minidump/minidump_thread_writer.h"
18 #include "minidump/minidump_writer_util.h" 26 #include "minidump/minidump_writer_util.h"
27 #include "snapshot/process_snapshot.h"
19 #include "util/file/file_writer.h" 28 #include "util/file/file_writer.h"
20 #include "util/numeric/safe_assignment.h" 29 #include "util/numeric/safe_assignment.h"
21 30
22 namespace crashpad { 31 namespace crashpad {
23 32
24 MinidumpFileWriter::MinidumpFileWriter() 33 MinidumpFileWriter::MinidumpFileWriter()
25 : MinidumpWritable(), header_(), streams_(), stream_types_() { 34 : MinidumpWritable(), header_(), streams_(), stream_types_() {
26 // Don’t set the signature field right away. Leave it set to 0, so that a 35 // Don’t set the signature field right away. Leave it set to 0, so that a
27 // partially-written minidump file isn’t confused for a complete and valid 36 // partially-written minidump file isn’t confused for a complete and valid
28 // one. The header will be rewritten in WriteToFile(). 37 // one. The header will be rewritten in WriteToFile().
29 header_.Signature = 0; 38 header_.Signature = 0;
30 39
31 header_.Version = MINIDUMP_VERSION; 40 header_.Version = MINIDUMP_VERSION;
32 header_.CheckSum = 0; 41 header_.CheckSum = 0;
33 header_.Flags = MiniDumpNormal; 42 header_.Flags = MiniDumpNormal;
34 } 43 }
35 44
36 MinidumpFileWriter::~MinidumpFileWriter() { 45 MinidumpFileWriter::~MinidumpFileWriter() {
37 } 46 }
38 47
48 void MinidumpFileWriter::InitializeFromSnapshot(
49 const ProcessSnapshot* process_snapshot) {
50 DCHECK_EQ(state(), kStateMutable);
51 DCHECK_EQ(header_.Signature, 0u);
52 DCHECK_EQ(header_.TimeDateStamp, 0u);
53 DCHECK_EQ(header_.Flags, MiniDumpNormal);
54 DCHECK(streams_.empty());
55
56 // This time is truncated to an integer number of seconds, not rounded, for
57 // compatibility with the truncation of process_snapshot->ProcessStartTime()
58 // done by MinidumpMiscInfoWriter::InitializeFromSnapshot(). Handling both
59 // timestamps in the same way allows the highest-fidelity computation of
60 // process uptime as the difference between the two values.
61 timeval snapshot_time;
62 process_snapshot->SnapshotTime(&snapshot_time);
63 SetTimestamp(snapshot_time.tv_sec);
64
65 const SystemSnapshot* system_snapshot = process_snapshot->System();
66 auto system_info = make_scoped_ptr(new MinidumpSystemInfoWriter());
67 system_info->InitializeFromSnapshot(system_snapshot);
68 AddStream(system_info.Pass());
69
70 auto misc_info = make_scoped_ptr(new MinidumpMiscInfoWriter());
71 misc_info->InitializeFromSnapshot(process_snapshot);
72 AddStream(misc_info.Pass());
73
74 auto memory_list = make_scoped_ptr(new MinidumpMemoryListWriter());
75 auto thread_list = make_scoped_ptr(new MinidumpThreadListWriter());
76 thread_list->SetMemoryListWriter(memory_list.get());
77 MinidumpThreadIDMap thread_id_map;
78 thread_list->InitializeFromSnapshot(process_snapshot->Threads(),
79 &thread_id_map);
80 AddStream(thread_list.Pass());
81
82 const ExceptionSnapshot* exception_snapshot = process_snapshot->Exception();
83 if (exception_snapshot) {
84 auto exception = make_scoped_ptr(new MinidumpExceptionWriter());
85 exception->InitializeFromSnapshot(exception_snapshot, thread_id_map);
86 AddStream(exception.Pass());
87 }
88
89 auto module_list = make_scoped_ptr(new MinidumpModuleListWriter());
90 module_list->InitializeFromSnapshot(process_snapshot->Modules());
91 AddStream(module_list.Pass());
92
93 auto crashpad_info = make_scoped_ptr(new MinidumpCrashpadInfoWriter());
94 crashpad_info->InitializeFromSnapshot(process_snapshot);
95
96 // Since the MinidumpCrashpadInfo stream is an extension, it’s safe to not add
97 // it to the minidump file if it wouldn’t carry any useful information.
98 if (crashpad_info->IsUseful()) {
99 AddStream(crashpad_info.Pass());
100 }
101
102 AddStream(memory_list.Pass());
103 }
104
39 void MinidumpFileWriter::SetTimestamp(time_t timestamp) { 105 void MinidumpFileWriter::SetTimestamp(time_t timestamp) {
40 DCHECK_EQ(state(), kStateMutable); 106 DCHECK_EQ(state(), kStateMutable);
41 107
42 internal::MinidumpWriterUtil::AssignTimeT(&header_.TimeDateStamp, timestamp); 108 internal::MinidumpWriterUtil::AssignTimeT(&header_.TimeDateStamp, timestamp);
43 } 109 }
44 110
45 void MinidumpFileWriter::AddStream( 111 void MinidumpFileWriter::AddStream(
46 scoped_ptr<internal::MinidumpStreamWriter> stream) { 112 scoped_ptr<internal::MinidumpStreamWriter> stream) {
47 DCHECK_EQ(state(), kStateMutable); 113 DCHECK_EQ(state(), kStateMutable);
48 114
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 for (internal::MinidumpStreamWriter* stream : streams_) { 220 for (internal::MinidumpStreamWriter* stream : streams_) {
155 iov.iov_base = stream->DirectoryListEntry(); 221 iov.iov_base = stream->DirectoryListEntry();
156 iov.iov_len = sizeof(MINIDUMP_DIRECTORY); 222 iov.iov_len = sizeof(MINIDUMP_DIRECTORY);
157 iovecs.push_back(iov); 223 iovecs.push_back(iov);
158 } 224 }
159 225
160 return file_writer->WriteIoVec(&iovecs); 226 return file_writer->WriteIoVec(&iovecs);
161 } 227 }
162 228
163 } // namespace crashpad 229 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_file_writer.h ('k') | minidump/minidump_file_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698