OLD | NEW |
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_thread_writer.h" | 15 #include "minidump/minidump_thread_writer.h" |
16 | 16 |
17 #include <sys/types.h> | 17 #include <sys/types.h> |
18 | 18 |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "minidump/minidump_context_writer.h" | 20 #include "minidump/minidump_context_writer.h" |
21 #include "minidump/minidump_memory_writer.h" | 21 #include "minidump/minidump_memory_writer.h" |
| 22 #include "snapshot/memory_snapshot.h" |
| 23 #include "snapshot/thread_snapshot.h" |
22 #include "util/file/file_writer.h" | 24 #include "util/file/file_writer.h" |
23 #include "util/numeric/safe_assignment.h" | 25 #include "util/numeric/safe_assignment.h" |
24 | 26 |
25 namespace crashpad { | 27 namespace crashpad { |
26 | 28 |
27 MinidumpThreadWriter::MinidumpThreadWriter() | 29 MinidumpThreadWriter::MinidumpThreadWriter() |
28 : MinidumpWritable(), thread_(), stack_(nullptr), context_(nullptr) { | 30 : MinidumpWritable(), thread_(), stack_(nullptr), context_(nullptr) { |
29 } | 31 } |
30 | 32 |
31 MinidumpThreadWriter::~MinidumpThreadWriter() { | 33 MinidumpThreadWriter::~MinidumpThreadWriter() { |
32 } | 34 } |
33 | 35 |
| 36 void MinidumpThreadWriter::InitializeFromSnapshot( |
| 37 const ThreadSnapshot* thread_snapshot, |
| 38 const MinidumpThreadIDMap* thread_id_map) { |
| 39 DCHECK_EQ(state(), kStateMutable); |
| 40 DCHECK(!stack_); |
| 41 DCHECK(!context_); |
| 42 |
| 43 auto thread_id_it = thread_id_map->find(thread_snapshot->ThreadID()); |
| 44 DCHECK(thread_id_it != thread_id_map->end()); |
| 45 SetThreadID(thread_id_it->second); |
| 46 |
| 47 SetSuspendCount(thread_snapshot->SuspendCount()); |
| 48 SetPriority(thread_snapshot->Priority()); |
| 49 SetTEB(thread_snapshot->ThreadSpecificDataAddress()); |
| 50 |
| 51 const MemorySnapshot* stack_snapshot = thread_snapshot->Stack(); |
| 52 if (stack_snapshot && stack_snapshot->Size() > 0) { |
| 53 scoped_ptr<MinidumpMemoryWriter> stack = |
| 54 MinidumpMemoryWriter::CreateFromSnapshot(stack_snapshot); |
| 55 SetStack(stack.Pass()); |
| 56 } |
| 57 |
| 58 scoped_ptr<MinidumpContextWriter> context = |
| 59 MinidumpContextWriter::CreateFromSnapshot(thread_snapshot->Context()); |
| 60 SetContext(context.Pass()); |
| 61 } |
| 62 |
34 const MINIDUMP_THREAD* MinidumpThreadWriter::MinidumpThread() const { | 63 const MINIDUMP_THREAD* MinidumpThreadWriter::MinidumpThread() const { |
35 DCHECK_EQ(state(), kStateWritable); | 64 DCHECK_EQ(state(), kStateWritable); |
36 | 65 |
37 return &thread_; | 66 return &thread_; |
38 } | 67 } |
39 | 68 |
40 void MinidumpThreadWriter::SetStack(scoped_ptr<MinidumpMemoryWriter> stack) { | 69 void MinidumpThreadWriter::SetStack(scoped_ptr<MinidumpMemoryWriter> stack) { |
41 DCHECK_EQ(state(), kStateMutable); | 70 DCHECK_EQ(state(), kStateMutable); |
42 | 71 |
43 stack_ = stack.Pass(); | 72 stack_ = stack.Pass(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 MinidumpThreadListWriter::MinidumpThreadListWriter() | 130 MinidumpThreadListWriter::MinidumpThreadListWriter() |
102 : MinidumpStreamWriter(), | 131 : MinidumpStreamWriter(), |
103 thread_list_base_(), | 132 thread_list_base_(), |
104 threads_(), | 133 threads_(), |
105 memory_list_writer_(nullptr) { | 134 memory_list_writer_(nullptr) { |
106 } | 135 } |
107 | 136 |
108 MinidumpThreadListWriter::~MinidumpThreadListWriter() { | 137 MinidumpThreadListWriter::~MinidumpThreadListWriter() { |
109 } | 138 } |
110 | 139 |
| 140 void MinidumpThreadListWriter::InitializeFromSnapshot( |
| 141 const std::vector<const ThreadSnapshot*>& thread_snapshots, |
| 142 MinidumpThreadIDMap* thread_id_map) { |
| 143 DCHECK_EQ(state(), kStateMutable); |
| 144 DCHECK(threads_.empty()); |
| 145 |
| 146 BuildMinidumpThreadIDMap(thread_snapshots, thread_id_map); |
| 147 |
| 148 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) { |
| 149 auto thread = make_scoped_ptr(new MinidumpThreadWriter()); |
| 150 thread->InitializeFromSnapshot(thread_snapshot, thread_id_map); |
| 151 AddThread(thread.Pass()); |
| 152 } |
| 153 } |
| 154 |
111 void MinidumpThreadListWriter::SetMemoryListWriter( | 155 void MinidumpThreadListWriter::SetMemoryListWriter( |
112 MinidumpMemoryListWriter* memory_list_writer) { | 156 MinidumpMemoryListWriter* memory_list_writer) { |
113 DCHECK_EQ(state(), kStateMutable); | 157 DCHECK_EQ(state(), kStateMutable); |
114 DCHECK(threads_.empty()); | 158 DCHECK(threads_.empty()); |
115 | 159 |
116 memory_list_writer_ = memory_list_writer; | 160 memory_list_writer_ = memory_list_writer; |
117 } | 161 } |
118 | 162 |
119 void MinidumpThreadListWriter::AddThread( | 163 void MinidumpThreadListWriter::AddThread( |
120 scoped_ptr<MinidumpThreadWriter> thread) { | 164 scoped_ptr<MinidumpThreadWriter> thread) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 222 } |
179 | 223 |
180 return file_writer->WriteIoVec(&iovecs); | 224 return file_writer->WriteIoVec(&iovecs); |
181 } | 225 } |
182 | 226 |
183 MinidumpStreamType MinidumpThreadListWriter::StreamType() const { | 227 MinidumpStreamType MinidumpThreadListWriter::StreamType() const { |
184 return kMinidumpStreamTypeThreadList; | 228 return kMinidumpStreamTypeThreadList; |
185 } | 229 } |
186 | 230 |
187 } // namespace crashpad | 231 } // namespace crashpad |
OLD | NEW |