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

Side by Side Diff: minidump/minidump_thread_writer.cc

Issue 637503006: Add MinidumpThreadWriter, MinidumpThreadListWriter, and their test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@minidump_memory_writer_test_util
Patch Set: Address review feedback Created 6 years, 2 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
« no previous file with comments | « minidump/minidump_thread_writer.h ('k') | minidump/minidump_thread_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
(Empty)
1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "minidump/minidump_thread_writer.h"
16
17 #include "base/logging.h"
18 #include "minidump/minidump_context_writer.h"
19 #include "minidump/minidump_memory_writer.h"
20 #include "util/numeric/safe_assignment.h"
21
22 namespace crashpad {
23
24 MinidumpThreadWriter::MinidumpThreadWriter()
25 : MinidumpWritable(), thread_(), stack_(NULL), context_(NULL) {
26 }
27
28 const MINIDUMP_THREAD* MinidumpThreadWriter::MinidumpThread() const {
29 DCHECK_EQ(state(), kStateWritable);
30
31 return &thread_;
32 }
33
34 void MinidumpThreadWriter::SetStack(MinidumpMemoryWriter* stack) {
35 DCHECK_EQ(state(), kStateMutable);
36
37 stack_ = stack;
38 }
39
40 void MinidumpThreadWriter::SetContext(MinidumpContextWriter* context) {
41 DCHECK_EQ(state(), kStateMutable);
42
43 context_ = context;
44 }
45
46 bool MinidumpThreadWriter::Freeze() {
47 DCHECK_EQ(state(), kStateMutable);
48 CHECK(context_);
49
50 if (!MinidumpWritable::Freeze()) {
51 return false;
52 }
53
54 if (stack_) {
55 stack_->RegisterMemoryDescriptor(&thread_.Stack);
56 }
57
58 context_->RegisterLocationDescriptor(&thread_.ThreadContext);
59
60 return true;
61 }
62
63 size_t MinidumpThreadWriter::SizeOfObject() {
64 DCHECK_GE(state(), kStateFrozen);
65
66 // This object doesn’t directly write anything itself. Its MINIDUMP_THREAD is
67 // written by its parent as part of a MINIDUMP_THREAD_LIST, and its children
68 // are responsible for writing themselves.
69 return 0;
70 }
71
72 std::vector<internal::MinidumpWritable*> MinidumpThreadWriter::Children() {
73 DCHECK_GE(state(), kStateFrozen);
74 DCHECK(context_);
75
76 std::vector<MinidumpWritable*> children;
77 if (stack_) {
78 children.push_back(stack_);
79 }
80 children.push_back(context_);
81
82 return children;
83 }
84
85 bool MinidumpThreadWriter::WriteObject(FileWriterInterface* file_writer) {
86 DCHECK_EQ(state(), kStateWritable);
87
88 // This object doesn’t directly write anything itself. Its MINIDUMP_THREAD is
89 // written by its parent as part of a MINIDUMP_THREAD_LIST, and its children
90 // are responsible for writing themselves.
91 return true;
92 }
93
94 MinidumpThreadListWriter::MinidumpThreadListWriter()
95 : MinidumpStreamWriter(),
96 thread_list_base_(),
97 threads_(),
98 memory_list_writer_(NULL) {
99 }
100
101 MinidumpThreadListWriter::~MinidumpThreadListWriter() {
102 }
103
104 void MinidumpThreadListWriter::SetMemoryListWriter(
105 MinidumpMemoryListWriter* memory_list_writer) {
106 DCHECK_EQ(state(), kStateMutable);
107 DCHECK(threads_.empty());
108
109 memory_list_writer_ = memory_list_writer;
110 }
111
112 void MinidumpThreadListWriter::AddThread(MinidumpThreadWriter* thread) {
113 DCHECK_EQ(state(), kStateMutable);
114
115 threads_.push_back(thread);
116
117 if (memory_list_writer_) {
118 MinidumpMemoryWriter* stack = thread->Stack();
119 if (stack) {
120 memory_list_writer_->AddExtraMemory(stack);
121 }
122 }
123 }
124
125 bool MinidumpThreadListWriter::Freeze() {
126 DCHECK_EQ(state(), kStateMutable);
127
128 if (!MinidumpStreamWriter::Freeze()) {
129 return false;
130 }
131
132 size_t thread_count = threads_.size();
133 if (!AssignIfInRange(&thread_list_base_.NumberOfThreads, thread_count)) {
134 LOG(ERROR) << "thread_count " << thread_count << " out of range";
135 return false;
136 }
137
138 return true;
139 }
140
141 size_t MinidumpThreadListWriter::SizeOfObject() {
142 DCHECK_GE(state(), kStateFrozen);
143
144 return sizeof(thread_list_base_) + threads_.size() * sizeof(MINIDUMP_THREAD);
145 }
146
147 std::vector<internal::MinidumpWritable*> MinidumpThreadListWriter::Children() {
148 DCHECK_GE(state(), kStateFrozen);
149
150 std::vector<MinidumpWritable*> children;
151 for (MinidumpThreadWriter* thread : threads_) {
152 children.push_back(thread);
153 }
154
155 return children;
156 }
157
158 bool MinidumpThreadListWriter::WriteObject(FileWriterInterface* file_writer) {
159 DCHECK_EQ(state(), kStateWritable);
160
161 WritableIoVec iov;
162 iov.iov_base = &thread_list_base_;
163 iov.iov_len = sizeof(thread_list_base_);
164 std::vector<WritableIoVec> iovecs(1, iov);
165
166 for (const MinidumpThreadWriter* thread : threads_) {
167 iov.iov_len = sizeof(MINIDUMP_THREAD);
168 iov.iov_base = thread->MinidumpThread();
169 iovecs.push_back(iov);
170 }
171
172 return file_writer->WriteIoVec(&iovecs);
173 }
174
175 MinidumpStreamType MinidumpThreadListWriter::StreamType() const {
176 return kMinidumpStreamTypeThreadList;
177 }
178
179 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_thread_writer.h ('k') | minidump/minidump_thread_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698